:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1c2430; --muted: #66707d; --border: #dde1e7;
  --primary: #1f5f8b; --primary-ink: #ffffff; --primary-soft: #e3eef6;
  --ok: #1e7a46; --ok-soft: #e2f3e8; --warn: #9a5b00; --warn-soft: #fdf1dc; --danger: #b3261e; --danger-soft: #fbe5e3; --info: #22609a; --info-soft: #e3eef8;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161c; --surface: #1a2028; --surface-2: #222a34; --text: #e6e9ee; --muted: #9aa4b2; --border: #2f3946;
    --primary: #5aa3d6; --primary-ink: #0d1520; --primary-soft: #1d3346; --ok: #5cc98a; --ok-soft: #173325; --warn: #f0b252; --warn-soft: #3a2b12;
    --danger: #f28b82; --danger-soft: #3d1c1a; --info: #7bb6e8; --info-soft: #1b2e42; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: .2rem 0 .8rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
.small { font-size: .85rem; } .muted { color: var(--muted); } .strong { font-weight: 600; }
.err-text { color: var(--danger); } .warn-text { color: var(--warn); }
.pre { white-space: pre-wrap; }
pre { white-space: pre-wrap; font-size: .8rem; background: var(--surface-2); padding: .5rem; border-radius: 6px; max-width: 100%; overflow-x: auto; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; justify-content: flex-end; }
.who { font-size: .9rem; }
.bell { text-decoration: none; font-size: .9rem; }
.nav-toggle { display: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: .3rem .6rem; font-size: 1.1rem; }
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 50px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: .8rem .5rem; display: flex; flex-direction: column; gap: 1px; }
.sidebar a { display: flex; justify-content: space-between; align-items: center; padding: .42rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .93rem; }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-h { margin: .9rem .7rem .2rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.main { padding: 1.2rem 1.5rem 3rem; max-width: 1100px; width: 100%; }
.main.wide { max-width: none; }
.public-main { max-width: 440px; margin: 8vh auto; padding: 0 16px; }
.crumbs { font-size: .85rem; margin-bottom: .3rem; }
.page-h { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .6rem; }
.page-h h1 { margin: 0; }

/* Cards & stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .7rem; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .7rem; margin: 0 0 1rem; }
.stat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; text-decoration: none; color: var(--text); }
a.stat:hover { border-color: var(--primary); }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .82rem; color: var(--muted); }
.stat.warn { border-color: var(--warn); background: var(--warn-soft); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.loc-card { display: flex; flex-direction: column; gap: .25rem; padding: .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.loc-card:hover { border-color: var(--primary); }
.quick { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.quick .btn { flex: 1 1 160px; justify-content: center; padding: .75rem 1rem; }
.tasks { list-style: none; padding: 0; margin: 0; }
.tasks li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.tasks li:last-child { border-bottom: 0; }
.row-mini { padding: .3rem 0; }
.empty { text-align: center; color: var(--muted); padding: 1.2rem .5rem; }
.empty p { margin: 0 0 .6rem; }

/* Badges & pills */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.t-ok { background: var(--ok-soft); color: var(--ok); } .t-warn { background: var(--warn-soft); color: var(--warn); }
.t-danger { background: var(--danger-soft); color: var(--danger); } .t-info { background: var(--info-soft); color: var(--info); }
.t-sample { background: #ede4fb; color: #5b3a9a; }
.pill { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--primary); color: var(--primary-ink); font-size: .75rem; text-align: center; font-weight: 700; }
.pill.danger { background: var(--danger); color: #fff; }

/* Flash */
.flash { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.flash.info { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.sample-banner { background: #ede4fb; color: #4a2f80; padding: .45rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .88rem; }

/* Forms */
.field { display: flex; flex-direction: column; gap: .25rem; margin: 0 0 .7rem; min-width: 0; }
fieldset.field { border: 0; padding: 0; }
.lbl { font-size: .85rem; font-weight: 600; }
.hint { font-size: .8rem; color: var(--muted); margin: .25rem 0 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; width: 100%; min-height: 40px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=file] { padding: .35rem; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input.num { text-align: right; max-width: 9rem; }
.small-input { margin-top: .25rem; font-size: .85rem; min-height: 32px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1rem; align-items: end; }
.narrow { max-width: 460px; }
.check { display: flex; gap: .45rem; align-items: center; font-size: .9rem; margin: .2rem 0; }
.inline-checks { display: flex; flex-wrap: wrap; gap: .2rem 1rem; align-items: center; }
.inline, form.inline { display: inline; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .4rem 0; }
.inline-form input { width: auto; flex: 1 1 200px; }
.form-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .8rem; }
.form-actions .field { margin: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 .8rem; align-items: end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem .1rem; margin-bottom: 1rem; }
.filter-actions { display: flex; gap: .4rem; margin-bottom: .7rem; }
.dims { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0 .6rem; }
.copyrow { display: flex; gap: .5rem; align-items: flex-start; margin: .4rem 0; }
.copyrow textarea, .copyrow input { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: .3rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { padding: .3rem .65rem; font-size: .85rem; min-height: 32px; }
.btn.block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; }
.linkbtn.danger { color: var(--danger); }
details.mini { margin: .4rem 0; }
details.mini > summary { cursor: pointer; color: var(--primary); font-size: .9rem; }
details.inline { display: inline-block; }

/* Tables */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.rtable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.rtable th, .rtable td { padding: .45rem .55rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.rtable th { font-size: .78rem; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--surface); }
.rtable .num, .rtable th.num { text-align: right; font-variant-numeric: tabular-nums; }
.rtable tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
.rtable tr.muted td { color: var(--muted); }
.rtable tr.row-error td { background: var(--danger-soft); }
.rtable tr.alert-row td { background: var(--warn-soft); }
.rtable.compact td, .rtable.compact th { padding: .3rem .45rem; }
.rtable.lines td { vertical-align: middle; }
.sheet { max-height: 75vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.sheet thead th { position: sticky; top: 0; z-index: 1; }
.analysis td a.drill { font-weight: 600; text-decoration: none; border-bottom: 1px dashed currentColor; }
a.sort { color: inherit; text-decoration: none; }
a.sort.on.asc::after { content: " ▲"; } a.sort.on.desc::after { content: " ▼"; }
.thumb { max-width: 48px; max-height: 48px; border-radius: 4px; vertical-align: middle; }

/* Misc components */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; }
.next-action { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; background: var(--primary-soft); border: 1px solid var(--primary); border-radius: var(--radius); padding: .65rem .9rem; margin-bottom: 1rem; }
.steps { display: flex; flex-wrap: wrap; gap: .3rem; list-style: none; padding: 0; margin: 0 0 1rem; }
.steps li { font-size: .78rem; padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.steps li.on { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .7rem; margin-bottom: .8rem; }
.box { border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem; display: flex; flex-direction: column; gap: .35rem; background: var(--surface); }
.box.flagged { border-color: var(--danger); background: var(--danger-soft); }
.box-h { display: flex; justify-content: space-between; gap: .4rem; flex-wrap: wrap; }
.files { list-style: none; padding: 0; margin: 0 0 .5rem; }
.files li { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.files li.old { opacity: .65; }
.upload { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.upload input[type=file] { width: auto; flex: 1 1 200px; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.history li.void { opacity: .6; text-decoration: line-through; }
.history li.void details, .history li.void .badge { text-decoration: none; }
.notifs { list-style: none; padding: 0; margin: 0; }
.notifs li { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .45rem; }
.notifs li.unread { border-left: 4px solid var(--primary); }
.aliases { padding-left: 1rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: .7rem; flex-wrap: wrap; }
.tabs a { padding: .3rem .8rem; border-radius: 999px; text-decoration: none; background: var(--surface-2); color: var(--text); font-size: .88rem; }
.tabs a.active { background: var(--primary); color: var(--primary-ink); }
.drill-panel { position: fixed; right: 16px; bottom: 16px; width: min(640px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: 1rem; z-index: 30; }
.drill-panel .close { float: right; }
.notes { background: var(--surface-2); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.error-page { max-width: 560px; }

/* Paste grid */
.paste-grid { min-height: 180px; max-height: 60vh; overflow: auto; border: 2px dashed var(--border); border-radius: var(--radius); padding: .5rem; background: var(--surface); }
.paste-grid:focus { border-color: var(--primary); outline: none; }
.sheet-grid { border-collapse: collapse; font-size: .82rem; }
.sheet-grid th, .sheet-grid td { border: 1px solid var(--border); padding: .2rem .4rem; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.sheet-grid th { background: var(--surface-2); color: var(--muted); font-weight: 600; position: sticky; top: 0; }
.sheet-grid td:focus { outline: 2px solid var(--primary); background: var(--primary-soft); white-space: normal; }

/* Mobile */
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; inset: 50px 0 0 0; z-index: 25; overflow-y: auto; border-right: 0; }
  body.nav-open .sidebar { display: flex; }
  .main { padding: 1rem 16px 3rem; }
  .who { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; } .kv dt { margin-top: .4rem; }
}
@media (max-width: 700px) {
  /* Tables become stacked cards; each cell shows its column label. */
  table.rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable thead { display: none; }
  .rtable tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .55rem; padding: .3rem .5rem; background: var(--surface); }
  .rtable td { border: 0; padding: .2rem 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .2rem .8rem; text-align: right; }
  .rtable td.num { text-align: right; }
  .rtable td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .8rem; text-align: left; flex: 0 0 42%; }
  .rtable td > input, .rtable td > select { max-width: 58%; }
  .rtable tr.total { background: var(--surface-2); }
  .sheet { max-height: none; border: 0; background: transparent; }
  .filters { grid-template-columns: 1fr 1fr; }
  .top-right { gap: .6rem; }
}
