:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #e0dfd8;
  --border-strong: #c9c8bf;
  --text: #171716;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #1d5f8a;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef6;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --good: #1a7f4b;
  --warn: #9a6200;
  --focus: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-w: 216px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --border-strong: #42423e;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #5aa7de; --accent-ink: #0b1620; --accent-soft: #1b2d3b;
    --danger: #f2877d; --danger-soft: #3a1e1b; --good: #4cc38a; --warn: #e0a83a; --focus: #5aa7de;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2b; --border-strong: #42423e;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #5aa7de; --accent-ink: #0b1620; --accent-soft: #1b2d3b;
  --danger: #f2877d; --danger-soft: #3a1e1b; --good: #4cc38a; --warn: #e0a83a; --focus: #5aa7de;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* boot + sign-in */
.boot { position: fixed; inset: 0; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: 100%; max-width: 360px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 36px 28px; box-shadow: var(--shadow); }
.signin-logo { border-radius: 16px; margin-bottom: 16px; }
.signin-card p { margin: 8px 0 24px; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-google { width: 100%; min-height: 46px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; min-height: 42px;
}
textarea { min-height: 76px; resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); font-weight: 550; min-width: 0; }
label.field .req { color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--text); font-weight: 500; }

/* segmented chips */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; left: 0; top: 0; }
.seg label {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500; user-select: none;
}
.seg input:checked + label { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }

/* layout */
.app { min-height: 100dvh; }
.nav {
  position: fixed; z-index: 20; display: flex; background: var(--surface); border-color: var(--border);
}
.nav-link {
  display: flex; align-items: center; gap: 10px; color: var(--text-2); text-decoration: none; font-weight: 550; font-size: 14px; border-radius: 10px;
}
.nav-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link.active { color: var(--accent); background: var(--accent-soft); }
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.nav-brand img { border-radius: 7px; }
.sync { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.sync.off::before { background: var(--warn); }

.view { padding: 20px 16px calc(96px + var(--safe-b)); max-width: 1200px; margin: 0 auto; outline: none; }

@media (min-width: 860px) {
  .nav { inset: 0 auto 0 0; width: var(--nav-w); flex-direction: column; gap: 4px; padding: 20px 12px; border-right: 1px solid var(--border); }
  .nav-brand { padding: 4px 10px 20px; }
  .nav-link { padding: 10px; }
  .nav-add { order: -1; margin-bottom: 10px; background: var(--accent); color: var(--accent-ink); justify-content: center; }
  .nav-add.active { background: var(--accent); color: var(--accent-ink); }
  .nav-foot { margin-top: auto; padding: 10px; }
  .view { margin-left: var(--nav-w); padding: 28px 32px 48px; }
}
@media (max-width: 859.98px) {
  .nav { inset: auto 0 0 0; border-top: 1px solid var(--border); padding: 6px 8px calc(6px + var(--safe-b)); justify-content: space-around; }
  .nav-brand, .nav-foot { display: none; }
  .nav-link { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; min-width: 56px; background: none !important; }
  .nav-add svg { background: var(--accent); color: var(--accent-ink); border-radius: 50%; width: 34px; height: 34px; padding: 6px; margin-top: -2px; }
  .nav-add.active { color: var(--accent); }
}

/* page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.offline-banner { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; font-size: 13px; margin-bottom: 12px; color: var(--text-2); }

/* filter bar */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.filters input[type="search"] { flex: 1 1 220px; min-width: 0; }
.filters .seg label { min-height: 34px; font-size: 13px; }

/* cards & tiles */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--muted); font-weight: 550; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12px; color: var(--text-2); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1000px) { .grid-2 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); } }
.grid-2 .card + .card { margin-top: 0; }

/* chart */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--border); }
.chart .baseline { stroke: var(--border-strong); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--text); fill-opacity: .04; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .role-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); min-width: 140px; }
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }

/* bars-in-table */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; font-size: 13px; }
.bar-row .track { grid-column: 1 / -1; height: 8px; border-radius: 4px; background: var(--surface-2); display: flex; gap: 2px; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; }
.bar-row .track i:first-child { border-radius: 4px 0 0 4px; }
.bar-row .track i:last-child { border-radius: 0 4px 4px 0; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data td.wrap { white-space: normal; min-width: 180px; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; }
table.data th.sorted::after { content: " ↓"; }
table.data th.sorted.asc::after { content: " ↑"; }
table.data td.n, table.data th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 650; border-top: 2px solid var(--border-strong); }
.zero { color: var(--border-strong); }

/* log list */
.log-list { display: flex; flex-direction: column; }
.log-row {
  display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 2px 14px; align-items: center;
  padding: 11px 4px; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit;
}
.log-row:hover { background: var(--surface-2); }
.log-date { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.log-main { min-width: 0; }
.log-op { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-meta { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; font-weight: 550; }
.chip.comp { background: var(--danger-soft); color: var(--danger); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 600px) {
  .log-row { grid-template-columns: minmax(0, 1fr) auto; }
  .log-date { grid-column: 1 / -1; font-size: 12px; }
}
.more { display: flex; justify-content: center; padding: 16px; }

/* form */
.form { display: flex; flex-direction: column; gap: 16px; max-width: 860px; }
.form fieldset { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 14px 16px 16px; margin: 0; min-width: 0; }
.form legend { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: 0 6px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.form-grid .span-all { grid-column: 1 / -1; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 699.98px) { .form-grid .span-2 { grid-column: 1 / -1; } }
.form-actions {
  position: sticky; bottom: calc(64px + var(--safe-b)); z-index: 5; display: flex; gap: 8px; flex-wrap: wrap;
  background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border);
}
@media (min-width: 860px) { .form-actions { bottom: 0; } }
.form-actions .spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
details.more-fields summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px 0; list-style: none; }
details.more-fields summary::-webkit-details-marker { display: none; }
details.more-fields[open] summary { margin-bottom: 12px; }

/* data page */
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.notice { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; color: var(--text); }
.notice.warn { background: var(--danger-soft); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* toast & modal */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b)); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }
@media (min-width: 860px) { .toast { bottom: 24px; left: calc(50% + var(--nav-w) / 2); } }
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-bottom: 8px; }
dialog .row { justify-content: flex-end; margin-top: 16px; }
.table-wrap.scroll { max-height: 520px; overflow-y: auto; }
table.data tfoot td { position: sticky; bottom: 0; background: var(--surface); }

/* settings */
.items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.item { display: inline-flex; align-items: center; gap: 2px; min-height: 34px; padding: 0 3px 0 12px; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--surface); font-size: 14px; }
.item button { width: 28px; height: 28px; border: 0; border-radius: 50%; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.item button:hover { background: var(--danger-soft); color: var(--danger); }
details.from-log { margin-top: 12px; }
details.from-log summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pick-item { font: inherit; font-size: 13px; padding: 5px 10px; border: 1px dashed var(--border-strong); border-radius: 999px; background: transparent; color: var(--text-2); cursor: pointer; }
.pick-item:hover { background: var(--accent-soft); color: var(--text); }
.user-list { list-style: none; margin: 12px 0 0; padding: 0; }
.user-list li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--border); }
.user-list .user-email { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 550; }
