/* ComNote — shared tokens and components.
   A civic operations look: paper surfaces, hairline rules, one restrained
   accent, colour reserved for status and urgency so it always means something. */

:root {
  --bg: #f5f5f1;
  --panel: #ffffff;
  --panel-2: #fafaf7;
  --line: #e2e1da;
  --line-strong: #cfcdc4;
  --ink: #18201d;
  --ink-2: #4f5753;
  --ink-3: #858b87;
  --brand: #0b6b47;
  --brand-ink: #ffffff;
  --brand-soft: #e5f1eb;
  --focus: #0b6b47;

  --s-received: #2f5da8;   --s-received-bg: #e8eef8;
  --s-progress: #a35f00;   --s-progress-bg: #fbf0dd;
  --s-resolved: #1d7a4c;   --s-resolved-bg: #e3f2ea;
  --s-rejected: #6a6f6c;   --s-rejected-bg: #eeeeeb;

  --u-critical: #b42318;
  --u-high: #d0620f;
  --u-medium: #b08900;
  --u-low: #7c8a84;

  --radius: 6px;
  --radius-sm: 4px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --shadow-pop: 0 10px 30px rgba(24, 32, 29, .12), 0 1px 3px rgba(24, 32, 29, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513; --panel: #171c1a; --panel-2: #1b211e; --line: #2a312e; --line-strong: #39423e;
    --ink: #e8ece9; --ink-2: #a9b2ad; --ink-3: #78817c;
    --brand: #3fb27f; --brand-ink: #08130e; --brand-soft: #173126; --focus: #3fb27f;
    --s-received: #7ea4e6; --s-received-bg: #1a2638;
    --s-progress: #e5a443; --s-progress-bg: #33270f;
    --s-resolved: #5cc792; --s-resolved-bg: #15301f;
    --s-rejected: #9aa19d; --s-rejected-bg: #252a28;
    --u-critical: #f0695c; --u-high: #f0924a; --u-medium: #d8b443; --u-low: #93a19a;
    --shadow-pop: 0 10px 30px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111513; --panel: #171c1a; --panel-2: #1b211e; --line: #2a312e; --line-strong: #39423e;
  --ink: #e8ece9; --ink-2: #a9b2ad; --ink-3: #78817c;
  --brand: #3fb27f; --brand-ink: #08130e; --brand-soft: #173126; --focus: #3fb27f;
  --s-received: #7ea4e6; --s-received-bg: #1a2638;
  --s-progress: #e5a443; --s-progress-bg: #33270f;
  --s-resolved: #5cc792; --s-resolved-bg: #15301f;
  --s-rejected: #9aa19d; --s-rejected-bg: #252a28;
  --u-critical: #f0695c; --u-high: #f0924a; --u-medium: #d8b443; --u-low: #93a19a;
  --shadow-pop: 0 10px 30px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.5 var(--font); font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: .92em; letter-spacing: -.01em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ── Wordmark ─────────────────────────────────────────────── */
.wordmark { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 600; letter-spacing: -.01em; }
.wordmark svg { flex: none; }
.wordmark small { font-weight: 500; color: var(--ink-3); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }

/* ── Controls ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--ink);
  font-weight: 500; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--ink-3); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn svg { width: 15px; height: 15px; }

.input, .select, .textarea {
  height: 32px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--panel); min-width: 0;
}
.select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23858b87' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.textarea { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; width: 100%; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
label.check { display: inline-flex; gap: 7px; align-items: center; font-size: 13px; color: var(--ink-2); cursor: pointer; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--panel); }
.segmented button { border: 0; background: transparent; height: 30px; padding: 0 11px; font-size: 13px; color: var(--ink-2); cursor: pointer; border-right: 1px solid var(--line); display: inline-flex; gap: 6px; align-items: center; }
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
.segmented button .count { font-family: var(--mono); font-size: 11px; opacity: .7; }

/* ── Status + urgency ─────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.received { color: var(--s-received); background: var(--s-received-bg); }
.pill.in_progress { color: var(--s-progress); background: var(--s-progress-bg); }
.pill.resolved { color: var(--s-resolved); background: var(--s-resolved-bg); }
.pill.rejected { color: var(--s-rejected); background: var(--s-rejected-bg); }

.urg { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; white-space: nowrap; }
.urg i { display: inline-flex; gap: 2px; }
.urg i b { width: 4px; height: 11px; border-radius: 1px; background: var(--line-strong); }
.urg.low i b:nth-child(-n+1),
.urg.medium i b:nth-child(-n+2),
.urg.high i b:nth-child(-n+3),
.urg.critical i b { background: currentColor; }
.urg.low { color: var(--u-low); } .urg.medium { color: var(--u-medium); }
.urg.high { color: var(--u-high); } .urg.critical { color: var(--u-critical); font-weight: 600; }

.tag { display: inline-block; padding: 1px 6px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--line); font-size: 11.5px; color: var(--ink-2); white-space: nowrap; }

/* ── Panels + tables ──────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .01em; }
.panel-head .sub { font-size: 12px; color: var(--ink-3); font-weight: 400; margin-left: 6px; }
.panel-body { padding: 16px; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; font-weight: 500; font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover td { background: var(--panel-2); }
table.grid tbody tr.selected td { background: var(--brand-soft); }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid td.num { font-family: var(--mono); font-size: 12.5px; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--ink); }
table.grid th[aria-sort="ascending"]::after { content: " ↑"; }
table.grid th[aria-sort="descending"]::after { content: " ↓"; }
.cell-title { font-weight: 500; color: var(--ink); }
.cell-sub { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ── Trust score ──────────────────────────────────────────── */
.score { display: inline-flex; align-items: center; gap: 8px; min-width: 120px; }
.score .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; min-width: 60px; }
.score .bar span { display: block; height: 100%; border-radius: 3px; }
.score b { font-family: var(--mono); font-size: 13px; font-weight: 600; width: 26px; text-align: right; }
.score.good .bar span { background: var(--s-resolved); }
.score.fair .bar span { background: var(--u-medium); }
.score.poor .bar span { background: var(--u-critical); }
.score.none b { color: var(--ink-3); font-weight: 400; }

/* ── Markdown (coaching reports) ──────────────────────────── */
.prose { font-size: 14px; line-height: 1.6; max-width: 72ch; }
.prose h2 { font-size: 14px; margin: 20px 0 6px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.prose h2:first-child { margin-top: 0; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin: 3px 0; }

/* ── Toast ────────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--ink); color: var(--panel); padding: 10px 16px; border-radius: var(--radius); font-size: 13px; transition: .2s ease; z-index: 1000; pointer-events: none; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Map ──────────────────────────────────────────────────── */
.leaflet-container { font: inherit; background: var(--panel-2); }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-popup-content-wrapper { border-radius: var(--radius); box-shadow: var(--shadow-pop); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.45; }
.map-pop .mono { font-size: 12px; color: var(--ink-3); }
.map-pop strong { display: block; margin: 2px 0 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.skeleton { background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }

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