/* Valheim Companion dashboard.
   Colour roles come from the dataviz reference palette (validated light + dark steps); dark is the
   default because that is when people play. Data marks carry colour; text always wears ink tokens. */

:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;        /* sequential blue: meters, bars */
  --track: #104281;         /* same ramp, the step nearest the dark surface */
  --s1: #3987e5;            /* categorical: storage */
  --s2: #d95926;            /* categorical: workstations */
  --s3: #199e70;            /* categorical: everything else */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:where(:not([data-theme="dark"])) {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --surface-2: #f2f1ed;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --ring: rgba(11, 11, 11, 0.10);
    --accent: #2a78d6;
    --track: #cde2fb;
    --s1: #2a78d6;
    --s2: #eb6834;
    --s3: #1baf7a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; letter-spacing: 0.01em; }
h2 { font-size: 14px; color: var(--ink); }
h3 { font-size: 16px; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 12.5px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.app { max-width: 1280px; margin: 0 auto; padding: 14px 16px 40px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 4px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--ring); color: var(--ink-2); }
.more-bases { background: var(--surface-2); border: 0; box-shadow: inset 0 0 0 1px var(--ring); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; color: var(--ink-2); max-width: 200px; }
.more-bases.on { background: var(--ink); color: var(--page); box-shadow: none; }
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clock { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.players { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--ring); color: var(--ink-2); }
.live { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--ink-2); }
.live.on::before { background: var(--good); }

/* KPI row */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--surface); border-radius: 10px; box-shadow: inset 0 0 0 1px var(--ring); padding: 12px 14px; min-width: 0; }
.kpi .label { color: var(--ink-2); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 600; line-height: 1.15; margin-top: 2px; }
.kpi .note { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .meter { margin-top: 8px; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; align-items: start; }
.main-col, .side-col { display: grid; gap: 12px; min-width: 0; }

.card { background: var(--surface); border-radius: 10px; box-shadow: inset 0 0 0 1px var(--ring); padding: 14px; min-width: 0; }
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }

/* pills / segmented */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 0; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--ring); color: var(--ink-2); padding: 3px 10px; border-radius: 999px; font-size: 12.5px; cursor: pointer; }
.pill[aria-selected="true"] { background: var(--ink); color: var(--page); box-shadow: none; }
.seg { display: inline-flex; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--ring); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; color: var(--ink-2); font-size: 13px; }
.seg button.on { background: var(--surface-2); color: var(--ink); }

/* meters: fill carries the value, track is the same ramp */
.meter { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter.warning > i { background: var(--warning); }
.meter.critical > i { background: var(--critical); }
.meter.good > i { background: var(--good); }

/* status: never colour alone */
.st { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.st::before { content: ""; width: 14px; height: 14px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 700; color: #0b0b0b; line-height: 14px; text-align: center; }
.st.good::before { content: "✓"; background: var(--good); color: #fff; }
.st.warning::before { content: "!"; background: var(--warning); }
.st.serious::before { content: "!"; background: var(--serious); }
.st.critical::before { content: "✕"; background: var(--critical); color: #fff; }
.st.idle::before { content: "–"; background: var(--baseline); color: var(--ink-2); }
.st.paused::before { content: "II"; background: var(--baseline); color: var(--ink-2); font-size: 8px; letter-spacing: -1px; }

/* attention list */
.attn { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.attn li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 7px 4px; border-bottom: 1px solid var(--grid); }
.attn li:last-child { border-bottom: 0; }
.attn .what { min-width: 0; }
.attn .what b { font-weight: 600; }
.attn .where { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* workshop */
.ws-group { margin-top: 12px; }
.ws-group:first-child { margin-top: 0; }
.ws-group > h4 { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.ws-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.st-card { background: var(--surface-2); border-radius: 8px; padding: 10px 11px; box-shadow: inset 0 0 0 1px var(--ring); min-width: 0; }
.st-card .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.st-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-card .line { display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-top: 7px; font-size: 12.5px; color: var(--ink-2); }
.st-card .line .v { font-variant-numeric: tabular-nums; color: var(--ink); }
.st-card .note { margin-top: 7px; font-size: 12.5px; color: var(--ink-2); }
.st-card .note.muted { color: var(--muted); }
.slots { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 7px; }
.slot { font-size: 11.5px; padding: 1px 6px; border-radius: 4px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--ring); color: var(--ink-2); }
.fires-line { display: flex; gap: 14px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; margin-top: 4px; }

/* storage */
.storage-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
#search { flex: 1 1 220px; min-width: 0; background: var(--surface-2); border: 0; box-shadow: inset 0 0 0 1px var(--ring); border-radius: 8px; padding: 7px 10px; }
.stock { width: 100%; border-collapse: collapse; }
.stock th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--baseline); }
.stock td { padding: 5px 6px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.stock td.bar { width: 38%; }
.stock .hbar { height: 8px; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 2px; }
.stock .where { color: var(--muted); font-size: 12.5px; }
.more { margin-top: 8px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; padding: 4px 0; text-decoration: underline; text-underline-offset: 3px; }
.chests { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.chest { text-align: left; border: 0; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--ring); border-radius: 8px; padding: 9px 10px; cursor: pointer; min-width: 0; }
.chest:hover, .chest:focus-visible { box-shadow: inset 0 0 0 1px var(--ink-2); outline: none; }
.chest .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chest .k { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 6px; margin: 2px 0 6px; }
.chest ul { list-style: none; padding: 0; margin: 6px 0 0; font-size: 12.5px; color: var(--ink-2); }
.chest li { display: flex; justify-content: space-between; gap: 6px; }
.chest li span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chest li span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.map-wrap { position: relative; }
.map { width: 100%; height: auto; display: block; background: var(--surface-2); border-radius: 8px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* side: to-dos, watches, events */
.todo-form, .row-form { display: flex; gap: 6px; }
.todo-form input, .row-form input, .row-form select, .who input { flex: 1; min-width: 0; background: var(--surface-2); border: 0; box-shadow: inset 0 0 0 1px var(--ring); border-radius: 8px; padding: 7px 10px; }
.todo-form button, .row-form button { border: 0; border-radius: 8px; padding: 7px 12px; background: var(--ink); color: var(--page); font-weight: 600; cursor: pointer; }
.who { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.who input { padding: 4px 8px; }
.todos, .watches, .events { list-style: none; margin: 10px 0 0; padding: 0; }
.todos li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 7px 0; border-bottom: 1px solid var(--grid); }
.todos li:last-child { border-bottom: 0; }
.todos input[type=checkbox] { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--good); }
.todos .meta { color: var(--muted); font-size: 12px; }
.todos .done .txt { text-decoration: line-through; color: var(--muted); }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }
.done-box { margin-top: 8px; }
.done-box summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
.watches li { padding: 8px 0; border-bottom: 1px solid var(--grid); }
.watches li:last-child { border-bottom: 0; }
.watches .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.watches .where { color: var(--muted); font-size: 12px; }
.watches .meter { margin-top: 6px; }
.events li { padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 13px; color: var(--ink-2); display: flex; justify-content: space-between; gap: 10px; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.health { font-size: 12.5px; color: var(--ink-2); }
.health b { color: var(--ink); font-weight: 600; }

/* drawer */
.drawer { border: 0; padding: 0; border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 24px 60px rgba(0,0,0,0.5); width: min(520px, 94vw); max-height: 88vh; }
.drawer::backdrop { background: rgba(0,0,0,0.55); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 14px 14px 8px; margin: 0; }
.drawer-body { padding: 0 14px 16px; overflow: auto; max-height: calc(88vh - 70px); }
.items-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.items-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--baseline); padding: 4px 6px; }
.items-table th.num { text-align: right; }
.items-table td { padding: 5px 6px; border-bottom: 1px solid var(--grid); }

.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 8px 24px rgba(0,0,0,0.4); border-radius: 8px; padding: 6px 9px; font-size: 12.5px; max-width: 260px; }
.tip b { font-weight: 600; }

@media (max-width: 1000px) {
  /* one column; the to-do list moves up to right after "Needs attention" */
  .cols { display: flex; flex-direction: column; }
  .main-col, .side-col { display: contents; }
  .o-attn { order: 1; } .o-todo { order: 2; } .o-ws { order: 3; } .o-st { order: 4; }
  .o-watch { order: 5; } .o-act { order: 6; } .o-health { order: 7; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .app { padding: 10px 10px 30px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: span 2; }
  .kpi .value { font-size: 22px; }
  .stock td.bar { width: 28%; }
  .ws-grid { grid-template-columns: minmax(0, 1fr); }
}

/* login: one password field, no username */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); display: grid; gap: 12px; padding: 22px; }
.login .brand { margin-bottom: 4px; }
.login input { background: var(--surface-2); border: 0; box-shadow: inset 0 0 0 1px var(--ring); border-radius: 8px; padding: 10px 12px; font-size: 16px; }
.login button { border: 0; border-radius: 8px; padding: 10px 12px; background: var(--ink); color: var(--page); font-weight: 600; font-size: 15px; cursor: pointer; }
.login button:disabled { opacity: 0.6; cursor: default; }
.login-msg { margin: 0; color: var(--ink-2); font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
