/* Sonoma Mesh tokens (from sonomamesh.com css/style.css) */
:root {
  --font-display: 'Cabinet Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Satoshi', 'Segoe UI', sans-serif;
  --font-mono: 'SFMono-Regular', ui-monospace, Consolas, monospace;
  --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem; --text-lg: 1.125rem;
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.1rem);
  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.25rem;
  --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --radius-sm: .375rem; --radius-md: .625rem; --radius-lg: 1rem; --radius-full: 9999px;
  --t: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --color-bg: #f7f5f0; --color-surface: #fbf9f4; --color-surface-2: #ffffff;
  --color-surface-offset: #efebe2; --color-surface-offset-2: #e7e1d3;
  --color-divider: #e6e0d4; --color-border: #ddd6c8;
  --color-text: #211d16; --color-text-muted: #6b6559; --color-text-faint: #8f877a;
  --color-primary: #c1622a; --color-primary-hover: #9c4d1f; --color-primary-highlight: #f0ddcb;
  --color-secondary: #2f4a3c; --color-secondary-highlight: #dde6de;
  --color-success: #43703a; --color-success-highlight: #dbe6d4;
  --color-warning: #8a5a12; --color-warning-highlight: #f1e4c4;
  --color-error: #99342f; --color-error-highlight: #eeddd8;
  --shadow-sm: 0 1px 2px oklch(0.25 0.03 55 / 0.08);
  --shadow-md: 0 6px 20px oklch(0.25 0.03 55 / 0.1);
  --shadow-lg: 0 16px 40px oklch(0.25 0.03 55 / 0.16);
  color-scheme: light;
}
[data-theme='dark'] {
  --color-bg: #14120f; --color-surface: #1b1815; --color-surface-2: #201c18;
  --color-surface-offset: #211d18; --color-surface-offset-2: #292420;
  --color-divider: #2c2823; --color-border: #34302a;
  --color-text: #ede8de; --color-text-muted: #a39b8c; --color-text-faint: #857d70;
  --color-primary: #e08a47; --color-primary-hover: #eda468; --color-primary-highlight: #3a2d20;
  --color-secondary: #6a9280; --color-secondary-highlight: #22302a;
  --color-success: #7fae70; --color-success-highlight: #263124;
  --color-warning: #d9a85a; --color-warning-highlight: #3a3020;
  --color-error: #cf8580; --color-error-highlight: #3a2624;
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 6px 20px oklch(0 0 0 / 0.35);
  --shadow-lg: 0 16px 40px oklch(0 0 0 / 0.5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--color-bg); color: var(--color-text);
  font-family: var(--font-body); font-size: var(--text-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--color-primary); text-underline-offset: 2px; }
a:hover { color: var(--color-primary-hover); }
button { font: inherit; color: inherit; }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--color-surface-2); padding: var(--space-2) var(--space-4); z-index: 100; }
.skip:focus { left: var(--space-4); }
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 var(--space-6); }
.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: .8em; letter-spacing: .02em; }

/* header */
.site-header { position: sticky; top: 0; z-index: 20; background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--color-divider); }
.header-row { display: flex; align-items: center; gap: var(--space-3); height: 60px; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--color-text); text-decoration: none; }
.brand svg { width: 30px; height: 30px; color: var(--color-primary); }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; letter-spacing: -0.01em; }
.brand-name span { color: var(--color-primary); }
.brand:hover { color: var(--color-text); }
.crumb { color: var(--color-text-faint); font-size: 1.2rem; }
.page-name { font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: .5rem .9rem; border-radius: var(--radius-full);
  border: 1px solid var(--color-border); background: var(--color-surface-2); color: var(--color-text);
  font-weight: 500; font-size: var(--text-sm); text-decoration: none; cursor: pointer; transition: background var(--t), border-color var(--t); }
.btn:hover { background: var(--color-surface-offset); color: var(--color-text); }
.btn svg { width: 16px; height: 16px; }
.btn.sm { padding: .35rem .7rem; font-size: var(--text-xs); }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: var(--radius-full);
  border: 1px solid var(--color-border); background: var(--color-surface-2); cursor: pointer; }
.icon-btn:hover { background: var(--color-surface-offset); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .sun { display: none; }
[data-theme='dark'] .icon-btn .sun { display: block; }
[data-theme='dark'] .icon-btn .moon { display: none; }

.live-chip { display: inline-flex; align-items: center; gap: .45rem; padding: .3rem .7rem; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 500; background: var(--color-surface-offset); color: var(--color-text-muted); white-space: nowrap; }
.live-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-text-faint); }
.live-chip[data-state='connected'] { background: var(--color-success-highlight); color: var(--color-success); }
.live-chip[data-state='connected'] .dot { background: var(--color-success); animation: pulse 2s infinite; }
.live-chip[data-state='degraded'] { background: var(--color-warning-highlight); color: var(--color-warning); }
.live-chip[data-state='degraded'] .dot { background: var(--color-warning); }
.live-chip[data-state='down'] { background: var(--color-error-highlight); color: var(--color-error); }
.live-chip[data-state='down'] .dot { background: var(--color-error); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-success) 55%, transparent); }
  70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* intro + kpis */
.intro { padding: var(--space-8) 0 var(--space-5); max-width: 760px; }
.intro h1 { font-family: var(--font-display); font-weight: 800; font-size: var(--text-xl); line-height: 1.1; margin: 0 0 var(--space-2); letter-spacing: -0.015em; }
.intro p { margin: 0; color: var(--color-text-muted); }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.kpi { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--color-surface-2); border: 1px solid var(--color-border); cursor: pointer; transition: border-color var(--t), box-shadow var(--t); min-width: 0; }
.kpi:hover { border-color: var(--color-text-faint); }
.kpi[aria-pressed='true'] { border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary) inset; }
.kpi-label { display: flex; align-items: center; gap: .4rem; font-size: var(--text-xs); color: var(--color-text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value { font-family: var(--font-display); font-weight: 700; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: var(--text-xs); color: var(--color-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sdot.active { background: var(--color-success); }
.sdot.quiet { background: var(--color-warning); }
.sdot.silent { background: var(--color-text-faint); }
.sdot.unmapped { background: transparent; box-shadow: inset 0 0 0 1.5px var(--color-text-faint); }

/* layout */
.tabs { display: none; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-4); align-items: start; }
.card { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-4); border-bottom: 1px solid var(--color-divider); }
.search { flex: 1 1 220px; display: flex; align-items: center; gap: var(--space-2); padding: 0 .75rem; height: 38px;
  border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-surface); }
.search:focus-within { border-color: var(--color-primary); }
.search svg { width: 16px; height: 16px; color: var(--color-text-faint); flex: none; }
.search input { border: 0; outline: 0; background: transparent; width: 100%; font: inherit; font-size: var(--text-sm); color: var(--color-text); }
.seg { display: inline-flex; padding: 3px; background: var(--color-surface-offset); border-radius: var(--radius-full); }
.seg button { border: 0; background: transparent; padding: .3rem .7rem; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 500;
  color: var(--color-text-muted); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed='true'] { background: var(--color-surface-2); color: var(--color-text); box-shadow: var(--shadow-sm); }
.export { display: flex; gap: var(--space-2); }

/* table */
.table-wrap { overflow-x: auto; }
.rtable { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.rtable th { position: sticky; top: 0; background: var(--color-surface-2); text-align: left; font-weight: 500; color: var(--color-text-muted);
  font-size: var(--text-xs); border-bottom: 1px solid var(--color-divider); padding: 0; }
.rtable th button { width: 100%; text-align: left; border: 0; background: transparent; padding: .7rem var(--space-4); cursor: pointer; color: inherit; white-space: nowrap; }
.rtable th button[aria-sort]::after { content: ' ↓'; color: var(--color-primary); }
.rtable th button[aria-sort='ascending']::after { content: ' ↑'; }
.rtable td { padding: .65rem var(--space-4); border-bottom: 1px solid var(--color-divider); vertical-align: middle; }
.rtable tbody tr { cursor: pointer; transition: background var(--t); }
.rtable tbody tr:hover { background: var(--color-surface-offset); }
.rtable tbody tr:last-child td { border-bottom: 0; }
.rtable tr.skeleton td { color: var(--color-text-muted); text-align: center; padding: var(--space-10); cursor: default; }
.rtable tr.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0% { background: var(--color-primary-highlight); } 100% { background: transparent; } }
.r-name { font-weight: 600; color: var(--color-text); display: block; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-sub { display: flex; align-items: center; gap: .4rem; color: var(--color-text-faint); font-size: var(--text-xs); margin-top: 1px; }
.tag { display: inline-block; padding: 0 .4rem; border-radius: var(--radius-sm); font-size: .68rem; font-weight: 600; letter-spacing: .02em;
  background: var(--color-surface-offset); color: var(--color-text-muted); white-space: nowrap; }
.tag.new { background: var(--color-primary-highlight); color: var(--color-primary-hover); }
[data-theme='dark'] .tag.new { color: var(--color-primary); }
.tag.off { background: var(--color-surface-offset-2); }
.tag.obs { background: color-mix(in oklab, var(--color-secondary) 16%, transparent); color: var(--color-secondary); }
.seg-n { font-variant-numeric: tabular-nums; opacity: .7; margin-left: 2px; }
.when .uplink { display: block; color: var(--color-text-faint); }
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .15rem .55rem; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; }
.pill.active { background: var(--color-success-highlight); color: var(--color-success); }
.pill.quiet { background: var(--color-warning-highlight); color: var(--color-warning); }
.pill.silent { background: var(--color-surface-offset); color: var(--color-text-muted); }
.pill.unmapped { background: transparent; color: var(--color-text-muted); box-shadow: inset 0 0 0 1px var(--color-border); }
.muted { color: var(--color-text-muted); }
.lbl-short { display: none; }
.m-heard { display: none; font-size: var(--text-xs); color: var(--color-text-faint); margin-top: 2px; white-space: nowrap; }
[data-theme='dark'] .seg button[aria-pressed='true'] { background: #3a332c; }
.faint { color: var(--color-text-faint); }
.when { white-space: nowrap; }
.when small { display: block; color: var(--color-text-faint); font-size: var(--text-xs); }
.table-foot { margin: 0; padding: var(--space-3) var(--space-4); font-size: var(--text-xs); color: var(--color-text-faint); border-top: 1px solid var(--color-divider); }
.empty { padding: var(--space-10) var(--space-4); text-align: center; color: var(--color-text-muted); }

/* feed */
.feed-panel { position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; }
.feed-head { padding: var(--space-4); border-bottom: 1px solid var(--color-divider); }
.feed-head h2 { margin: 0 0 var(--space-3); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.chips button { border: 1px solid var(--color-border); background: transparent; border-radius: var(--radius-full); padding: .2rem .6rem;
  font-size: var(--text-xs); color: var(--color-text-muted); cursor: pointer; }
.chips button[aria-pressed='true'] { background: var(--color-text); color: var(--color-bg); border-color: var(--color-text); }
.feed { list-style: none; margin: 0; padding: var(--space-2) 0; overflow-y: auto; flex: 1; min-height: 120px; }
.feed li { display: grid; grid-template-columns: 12px 1fr; gap: var(--space-3); padding: .6rem var(--space-4); border-radius: 0; }
.feed li.clickable { cursor: pointer; }
.feed li.clickable:hover { background: var(--color-surface-offset); }
.feed li.fresh { animation: flash 2.4s ease-out; }
.feed .mark { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--color-text-faint); }
.feed .mark.discovered, .feed .mark.observer_discovered { background: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-highlight); }
.feed .mark.heard_again, .feed .mark.back_on_map, .feed .mark.feed_restored { background: var(--color-success); }
.feed .mark.went_quiet { background: var(--color-warning); }
.feed .mark.left_map, .feed .mark.feed_down { background: var(--color-error); }
.feed .mark.renamed, .feed .mark.moved, .feed .mark.role_changed, .feed .mark.key_confirmed,
.feed .mark.observer_tagged, .feed .mark.observer_untagged { background: var(--color-secondary); }
.feed .ev-top { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }
.feed .ev-label { font-weight: 600; color: var(--color-text); }
.feed .ev-sum { font-size: var(--text-sm); color: var(--color-text-muted); margin-top: 1px; overflow-wrap: anywhere; }
.feed .ev-sum b { color: var(--color-text); font-weight: 600; }
.feed-empty { padding: var(--space-8) var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); text-align: center; }
.more { margin: var(--space-2) var(--space-4) var(--space-4); align-self: flex-start; }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--color-primary); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; }

/* system bar */
.sysbar { margin: var(--space-5) 0 0; }
.sysbar dl { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.sysbar dl div { display: flex; gap: .35rem; }
.sysbar dt { color: var(--color-text-faint); }
.sysbar dd { margin: 0; font-variant-numeric: tabular-nums; }
.sysbar .bad { color: var(--color-error); }
.sysbar .warn { color: var(--color-warning); }
.site-footer { padding: var(--space-6) var(--space-6) var(--space-10); font-size: var(--text-xs); color: var(--color-text-faint); }
.site-footer p { margin: 0; max-width: 760px; }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: oklch(0.2 0.02 55 / 0.35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--color-surface-2); z-index: 50;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; border-left: 1px solid var(--color-border); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--color-divider); }
.drawer-head h2 { margin: 2px 0 0; font-family: var(--font-display); font-size: 1.45rem; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.eyebrow { margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.drawer-body { overflow-y: auto; padding: var(--space-4) var(--space-5) var(--space-8); }
.links { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .5rem var(--space-4); margin: 0 0 var(--space-5); font-size: var(--text-sm); }
.facts dt { color: var(--color-text-muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.keybox { display: flex; gap: var(--space-2); align-items: flex-start; }
.keybox code { font-family: var(--font-mono); font-size: .74rem; word-break: break-all; line-height: 1.45; }
.copy { flex: none; border: 1px solid var(--color-border); background: var(--color-surface); border-radius: var(--radius-sm); font-size: var(--text-xs); padding: .1rem .45rem; cursor: pointer; }
.drawer-body h3 { font-family: var(--font-display); font-size: var(--text-base); font-weight: 700; margin: var(--space-5) 0 var(--space-2); }
.note { background: var(--color-surface-offset); border-radius: var(--radius-md); padding: var(--space-3); font-size: var(--text-sm); }
.history { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--color-divider); }
.history li { position: relative; padding: 0 0 var(--space-3) var(--space-4); font-size: var(--text-sm); }
.history li::before { content: ''; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--color-surface-2); border: 2px solid var(--color-text-faint); }
.history li.discovered::before { border-color: var(--color-primary); background: var(--color-primary); }
.history time { display: block; font-size: var(--text-xs); color: var(--color-text-faint); }

/* toasts */
.toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 60; display: flex; flex-direction: column; gap: var(--space-2); }
.toast { background: var(--color-text); color: var(--color-bg); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg); max-width: 340px; font-size: var(--text-sm); cursor: pointer; animation: slidein .3s ease-out; }
.toast b { display: block; font-family: var(--font-display); font-size: var(--text-base); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 1100px) {
  .grid { grid-template-columns: minmax(0, 1fr) 310px; }
  .c-first { display: none; }
}
@media (max-width: 860px) {
  .wrap { padding: 0 var(--space-4); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tabs { display: flex; gap: var(--space-1); padding: 3px; background: var(--color-surface-offset); border-radius: var(--radius-full); margin-bottom: var(--space-3); }
  .tabs button { flex: 1; border: 0; background: transparent; border-radius: var(--radius-full); padding: .45rem; font-weight: 600; font-size: var(--text-sm); color: var(--color-text-muted); cursor: pointer; }
  .tabs button[aria-selected='true'] { background: var(--color-surface-2); color: var(--color-text); box-shadow: var(--shadow-sm); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .panel[hidden] { display: none; }
  .feed-panel { position: static; max-height: none; }
  .c-place { display: none; }
}
@media (max-width: 560px) {
  .header-row { gap: var(--space-2); }
  .crumb, #mapLink span { display: none; }
  #mapLink { padding: .5rem; }
  .brand-name { font-size: 1.05rem; }
  .intro { padding-top: var(--space-5); }
  .intro p { font-size: var(--text-sm); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
  .kpi { padding: var(--space-3); }
  .kpi-value { font-size: 1.6rem; }
  .toolbar { padding: var(--space-3); }
  .seg { width: 100%; overflow-x: auto; }
  .seg button { flex: 1; padding: .3rem .5rem; }
  .export { margin-left: auto; }
  .rtable td, .rtable th button { padding-left: var(--space-3); padding-right: var(--space-3); }
  .r-name { max-width: 170px; }
  .c-heard { display: none; }
  .m-heard { display: block; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .r-name { max-width: 190px; }
  .live-chip { padding: .3rem .5rem; }
  .live-chip .txt { display: none; }
  .header-actions { gap: var(--space-1); }
}
/* Phones: keep the header on one line down to 320 px. */
@media (max-width: 420px) {
  .site-header .wrap { padding: 0 var(--space-3); }
  .header-row { gap: var(--space-2); height: 54px; white-space: nowrap; }
  .brand { gap: 6px; min-width: 0; }
  .brand svg { width: 24px; height: 24px; flex: none; }
  .brand-name, .page-name { font-size: .95rem; }
  .header-actions { flex: none; }
  .icon-btn, #mapLink { width: 34px; height: 34px; padding: 0; justify-content: center; }
  .live-chip { padding: .25rem .4rem; }
}
@media (max-width: 360px) {
  .brand-name { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
