/* Homer.
   The page is built on one idea: speech is messy, state is exact.
   Left column is set in a humanist sans and behaves like talk. Right column is
   set in mono with tabular figures and behaves like a ledger. The whole product
   is the arrow between them, so the typography carries it. */

:root {
  --paper: #edefea;
  --paper-2: #f6f7f3;
  --ink: #17232b;
  --ink-soft: #55645f;
  --rule: #d2d8cd;
  --homer: #136f63;
  --homer-wash: #e2eee9;
  --new: #c98016;
  --review: #a64b2a;

  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, "Roboto Mono", monospace;

  --gap: 20px;
  --radius: 3px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

.micro {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* --- bar ---------------------------------------------------------------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 14px 22px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
  flex-wrap: wrap;
}

.bar__id {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--homer);
  color: var(--paper-2);
  font-family: var(--mono);
  font-weight: 700;
  border-radius: 50%;
}

.bar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.bar__sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.bar__chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 9px;
  border: 1px solid var(--rule);
  border-radius: 100px;
  color: var(--ink-soft);
  background: var(--paper);
  white-space: nowrap;
}

.chip--live {
  border-color: var(--homer);
  color: var(--homer);
}

.chip--flag {
  border-color: var(--review);
  color: var(--review);
}

/* --- layout ------------------------------------------------------------- */

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
}

.thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--rule);
}

.thread__list {
  flex: 1;
  overflow-y: auto;
  margin: 0;
  padding: 22px 22px 8px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* --- messages ----------------------------------------------------------- */

.msg {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg__meta {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.msg__body {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--own {
  align-self: flex-end;
  align-items: flex-end;
}

.msg--own .msg__body {
  background: #fff;
}

/* Homer doesn't chat, it posts. Full width, flat, ruled — the same visual
   register as the ledger on the right, because that's what it speaks for. */
.msg--homer {
  max-width: 100%;
}

.msg--homer .msg__body {
  background: var(--homer-wash);
  border: none;
  border-left: 2px solid var(--homer);
  border-radius: 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
}

.msg__voice {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-soft);
}

.msg__voice::before {
  content: "";
  width: 3px;
  height: 11px;
  background: currentColor;
  box-shadow:
    5px 0 0 currentColor,
    10px 0 0 currentColor;
  margin-right: 10px;
}

/* --- composer ----------------------------------------------------------- */

.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 22px 4px;
  border-top: 1px solid var(--rule);
  background: var(--paper-2);
}

.composer__who {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

select,
input[type="text"] {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 8px 10px;
}

select {
  font-size: 13px;
  padding: 5px 8px;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
}

.send {
  background: var(--ink);
  color: var(--paper-2);
  border: 1px solid var(--ink);
  padding: 8px 16px;
}

.mic {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 7px 12px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  touch-action: none;
}

.mic__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--review);
  transform: scale(0.8);
}

.mic[data-recording="true"] {
  border-color: var(--review);
  color: var(--review);
}

.mic[data-recording="true"] .mic__dot {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(1.35);
    opacity: 0.55;
  }
}

.composer__hint {
  margin: 0;
  padding: 0 22px 14px;
  background: var(--paper-2);
  font-size: 12px;
  color: var(--ink-soft);
}

/* --- ledger ------------------------------------------------------------- */

.ledger {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 20px 20px;
  background: var(--paper);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  overflow-y: auto;
}

.ledger__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 7px;
}

.ledger h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* The delivery minimum, made visible. Homer acts on this number by itself, so
   it can't be something only the server knows. */
.gauge {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.gauge--ready {
  color: var(--homer);
  font-weight: 600;
}

/* An open question sits above the ledger, not in it. Nothing here has been
   decided yet, so it must not read like a line item — it's inset, in Homer's
   own colour, and it stays until it's answered. */
.asks {
  display: grid;
  gap: 10px;
}

.asks:not(:empty) {
  margin-bottom: 14px;
}

.ask {
  border: 1px solid var(--homer);
  background: var(--homer-wash);
  border-radius: var(--radius);
  padding: 10px 11px 11px;
}

.ask__head {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--homer);
}

.ask__sub {
  margin: 1px 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ask__choices {
  display: grid;
  gap: 6px;
}

.ask__choice {
  display: grid;
  gap: 1px;
  text-align: left;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}

.ask__choice:hover:not(:disabled) {
  border-color: var(--homer);
}

.ask__choice span {
  /* The counts are the argument: this is what you already buy. */
  font-size: 10.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.ask__skip {
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
}

.row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 13px;
}

.row__flag {
  color: var(--new);
  font-size: 11px;
}

.row__name {
  overflow-wrap: anywhere;
}

.row__sub {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-top: 2px;
}

.row__qty {
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.row--review .row__name {
  color: var(--review);
}

.row--review .row__flag {
  color: var(--review);
}

/* Signature: a new line is *drawn* into the ledger — the rule sweeps across
   and the text settles onto it. Speech became state, and you can see it. */
.row--new {
  animation: draw-in 620ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes draw-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
    background: linear-gradient(90deg, var(--new) 0%, transparent 0%);
    box-shadow: inset 0 -1px 0 var(--new);
  }
  35% {
    opacity: 1;
    box-shadow: inset 0 -1px 0 var(--new);
  }
  to {
    opacity: 1;
    transform: none;
    box-shadow: inset 0 -1px 0 transparent;
  }
}

.empty {
  color: var(--ink-soft);
  font-size: 12.5px;
  padding: 16px 0;
}

.ledger__foot {
  margin-top: auto;
  padding-top: 18px;
}

.counters {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.counter {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px dotted var(--rule);
  font-size: 12px;
  color: var(--ink-soft);
}

.counter b {
  color: var(--ink);
  font-weight: 600;
}

.note {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.note--cart {
  margin-top: 8px;
}

.cart {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  background: var(--homer);
  color: var(--paper-2);
  border: none;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

input[disabled],
.send[disabled],
.mic[disabled] {
  opacity: 0.5;
  cursor: progress;
}

.cart[disabled] {
  background: var(--rule);
  color: var(--ink-soft);
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--homer);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }

  .thread {
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }

  .thread__list {
    max-height: 52vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
