/* SpaceBot dashboard. Colors are roles (CSS custom properties); the chart
   palette is the validated default from the dataviz reference palette. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f3f2ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --good: #006300;
  --critical: #d03b3b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --seq-100: #cde2fb; --seq-200: #9ec5f4; --seq-300: #6da7ec; --seq-400: #3987e5;
  --seq-500: #256abf; --seq-600: #184f95; --seq-700: #0d366b;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #232321;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --good: #0ca30c; --critical: #d03b3b;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #232321;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --good: #0ca30c; --critical: #d03b3b;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; color: var(--text-secondary); }
p.lead { margin: 0 0 16px; color: var(--text-secondary); }
.muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--text-primary); text-decoration: none; }
.spacer { flex: 1; }
.layout { display: flex; min-height: calc(100vh - 50px); }
nav#sidebar { width: 210px; flex: none; padding: 12px 8px; border-right: 1px solid var(--border); background: var(--surface-1); }
nav#sidebar .group { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 14px 8px 4px; }
nav#sidebar a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--text-secondary); text-decoration: none; }
nav#sidebar a:hover { background: var(--surface-2); }
nav#sidebar a.active { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
main#main { flex: 1; min-width: 0; padding: 16px 20px 40px; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  nav#sidebar { width: auto; border-right: 0; border-bottom: 1px solid var(--border); display: flex; overflow-x: auto; gap: 2px; padding: 6px; }
  nav#sidebar .group { display: none; }
  nav#sidebar a { white-space: nowrap; }
  main#main { padding: 12px; }
}

button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
button.danger { background: var(--critical); }
button:disabled { opacity: .5; cursor: default; }
select, input[type=text], input[type=number], input[type=date], input[type=search], textarea {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; }
textarea { width: 100%; min-height: 80px; font-family: ui-monospace, monospace; font-size: 12px; }
label { display: inline-flex; align-items: center; gap: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--text-secondary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters .chips { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.filters .chips button { background: var(--surface-1); color: var(--text-secondary); border-radius: 0; padding: 5px 10px; }
.filters .chips button.on { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid { margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-muted); }

.chart { width: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.legend .key { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 1px; }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.uplot { font-family: inherit; }
.u-legend { display: none; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-weight: 600; color: var(--text-secondary); border-bottom: 1px solid var(--grid); padding: 6px 8px; cursor: pointer; user-select: none; white-space: nowrap; }
table.data td { border-bottom: 1px solid var(--grid); padding: 6px 8px; }
table.data td.num, table.data th.num { font-variant-numeric: tabular-nums; text-align: right; }
table.data tr:hover td { background: var(--surface-2); }
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }

.barlist { display: flex; flex-direction: column; gap: 6px; }
.barlist .item { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.barlist .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist .track { height: 12px; }
.barlist .bar { height: 12px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.barlist .val { font-variant-numeric: tabular-nums; color: var(--text-secondary); }

.heatmap { max-width: 860px; display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 2px; font-size: 10px; color: var(--text-muted); }
.heatmap .cell { aspect-ratio: 1.4; border-radius: 2px; min-width: 0; }
.heatmap > span { overflow: visible; white-space: nowrap; }
.heatmap .rowlabel { align-self: center; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 120px; }
.tooltip .t { color: var(--text-muted); margin-bottom: 2px; }
.tooltip .r { display: flex; align-items: center; gap: 6px; }
.tooltip .r b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .r .key { width: 12px; height: 2px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1); padding: 8px 14px; border-radius: 6px; z-index: 60; }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); }
.empty { color: var(--text-muted); padding: 24px 0; text-align: center; }
.loading { opacity: .55; transition: opacity .15s; }
.error { color: var(--critical); }
.picker { position: relative; display: inline-block; }
.picker .menu { position: absolute; top: 100%; left: 0; z-index: 20; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; max-height: 260px; overflow: auto; min-width: 220px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.picker .menu div { padding: 6px 10px; cursor: pointer; }
.picker .menu div:hover { background: var(--surface-2); }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 2px 8px; font-size: 12px; }
.chip button { background: none; color: var(--text-muted); padding: 0 2px; }
.login { max-width: 420px; margin: 80px auto; text-align: center; }

/* ---- page structure (stats + settings pages) ---- */
.page-head { margin-bottom: 12px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head .sub, .sub.hint { font-size: 12px; color: var(--text-muted); }
.card-head .row { gap: 8px; }
.hint { font-size: 12px; color: var(--text-muted); margin: -4px 0 12px; }
.note { color: var(--text-secondary); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { background: var(--surface-1); color: var(--text-secondary); border-radius: 0; padding: 3px 10px; font-size: 12px; }
.seg button.on { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.options { margin-bottom: 12px; font-size: 13px; color: var(--text-secondary); }
.card-head .options { margin: 0; }
.more { font-size: 12px; margin-top: 8px; }
.small-link { font-size: 12px; }
.kv { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 13px; flex-wrap: wrap; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-secondary); min-width: 150px; }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 8px; }
.section-head h3 { margin: 0; }
button.small { padding: 3px 10px; font-size: 12px; }
.panels { margin-bottom: 16px; }
.panel-row { padding: 6px 0; border-bottom: 1px solid var(--grid); }
.row .spacer { flex: 1; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-tools input[type=search] { min-width: 0; flex: 0 1 220px; }
.filters .presets { display: inline-flex; gap: 6px; align-items: center; }

/* ---- settings ---- */
.settings .field { max-width: 720px; }
.settings .field > small { font-size: 12px; }
.toggle { font-size: 14px; }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 10px 0; background: var(--page); border-top: 1px solid var(--border); z-index: 4; }
table.matrix th.perm { font-size: 11px; font-weight: 600; white-space: normal; min-width: 72px; vertical-align: bottom; cursor: default; }
table.matrix td.center { text-align: center; }
table.matrix td.role { white-space: nowrap; font-weight: 600; }
.labels .row { margin-bottom: 6px; }
.labels code { min-width: 100px; font-size: 12px; }

@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  #guild-picker { min-width: 0; max-width: 48vw; }
  #account .muted { display: none; }
  #account { white-space: nowrap; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .value { font-size: 20px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 12px; }
  .kv .k { min-width: 0; width: 100%; }
  .heatmap { grid-template-columns: 28px repeat(24, minmax(0, 1fr)); gap: 1px; font-size: 9px; }
  .filters { gap: 6px; }
  .filters .chips { max-width: 100%; overflow-x: auto; }
  .filters .chips button { padding: 5px 8px; }
  .picker input[type=search] { width: 120px !important; }
  table.data td { white-space: nowrap; }
  .table-tools button { white-space: nowrap; }
}
