/* Roots and Peaks enquiry desk.
   Palette: stone ink on a cool paper ground, sal-leaf green for actions,
   marigold reserved for the one thing that must not wait (P0). */
:root {
  --paper: #F5F7F6;
  --surface: #FFFFFF;
  --ink: #24322F;
  --muted: #5E6E69;
  --line: #D9E0DD;
  --sal: #2F5D50;
  --sal-soft: #E3EEEA;
  --marigold: #E5A100;
  --marigold-soft: #FFF3D6;
  --river: #2D7389;
  --river-soft: #E1EFF3;
  --danger: #A33A2C;
  --p2: #7C8C87;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto,
          "Nirmala UI", "Noto Sans Devanagari", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121C19;
    --surface: #1A2622;
    --ink: #E3ECE8;
    --muted: #9AABA5;
    --line: #2C3A35;
    --sal: #7FB8A4;
    --sal-soft: #213530;
    --marigold: #F2B83A;
    --marigold-soft: #3A3018;
    --river: #6FB3C8;
    --river-soft: #1D3038;
    --danger: #E08A7E;
    --p2: #8A9A95;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--sal); }
:focus-visible { outline: 2px solid var(--river); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 7px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--sal); border-color: var(--sal); color: var(--paper); }
.btn:disabled { opacity: .55; cursor: default; }
.field {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  min-width: 0;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }

/* ---- sign in ---------------------------------------------------------- */
.signin {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.signin form {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
}
.signin h1 { font-size: 24px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.signin label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* ---- shell ------------------------------------------------------------ */
.shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.topbar .brand { font-weight: 600; margin-right: auto; }
.panes {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
}

/* ---- queue ------------------------------------------------------------ */
.queue {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid var(--line);
}
.filters {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.filters .row { display: flex; gap: 8px; flex-wrap: wrap; }
.filters .row > .field { flex: 1 1 120px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 10px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--sal-soft); color: var(--sal); font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }

.list { overflow-y: auto; min-height: 0; }
.item {
  display: grid;
  grid-template-columns: 4px 1fr auto;
  gap: 0 12px;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 10px 16px 10px 0;
  cursor: pointer;
}
.item:hover { background: var(--surface); }
.item[aria-current="true"] { background: var(--sal-soft); }
.item .bar { grid-row: 1 / span 2; border-radius: 0 2px 2px 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .when { font-size: 13px; color: var(--muted); white-space: nowrap; }
.item .meta { grid-column: 2 / span 2; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; color: var(--muted); }
.more { padding: 16px; text-align: center; }
.empty { padding: 32px 16px; color: var(--muted); }

.bar.P0 { background: var(--marigold); }
.bar.P1 { background: var(--river); }
.bar.P2 { background: var(--p2); }
.bar.P3, .bar.P4, .bar.none { background: transparent; }

.chip {
  display: inline-block;
  font-size: 12px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius-s);
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
  white-space: nowrap;
}
.chip.P0 { background: var(--marigold-soft); border-color: var(--marigold); }
.chip.P1 { background: var(--river-soft); border-color: var(--river); }
.chip.wa { border-color: var(--sal); color: var(--sal); }

/* ---- lead ------------------------------------------------------------- */
.lead { overflow-y: auto; min-height: 0; padding: 20px 28px 48px; }
.lead .back { display: none; margin-bottom: 12px; }
.lead header h2 { font-size: 24px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.contact { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }

/* The one loud element: what to do next. */
.next {
  margin: 20px 0;
  padding: 16px 18px;
  border-left: 6px solid var(--p2);
  background: var(--surface);
  border-radius: 0 var(--radius-m) var(--radius-m) 0;
}
.next.P0 { border-left-color: var(--marigold); background: var(--marigold-soft); }
.next.P1 { border-left-color: var(--river); }
.next .action { font-size: 21px; font-weight: 600; line-height: 1.25; }
.next p { margin: 6px 0 0; max-width: 70ch; }

.section { margin-top: 24px; max-width: 760px; }
.section h3 { font-size: 15px; font-weight: 600; margin: 0 0 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.controls .field { flex: 0 1 220px; }

.thread { display: grid; gap: 8px; }
.msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: var(--radius-m);
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.out { justify-self: end; background: var(--sal-soft); border-color: transparent; }
.msg.system { justify-self: center; background: transparent; border-style: dashed; font-size: 13px; color: var(--muted); }
.msg time { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: var(--radius-m);
  font-size: 14px;
}

/* ---- phones: one pane at a time --------------------------------------- */
@media (max-width: 820px) {
  .panes { grid-template-columns: 1fr; }
  .queue { border-right: 0; }
  .shell.has-lead .queue { display: none; }
  .shell:not(.has-lead) .lead { display: none; }
  .lead { padding: 16px 16px 40px; }
  .lead .back { display: inline-block; }
  .msg { max-width: 92%; }
}
