/* Keys panel components. Class contract for page templates:
 * Shell:    .layout .sidebar .brand .nav-link(.active) .nav-gap .divider .main .page-head .title .actions
 *           .panel (aside, 360px; put a <div class="divider"></div> before it) .center-wrap .center-form body.inset
 * Content:  .section > .section-head (h2 + .actions) ; .table (table; th = caption row, tr.selectable, tr.selected, .num right-aligned)
 *           .kv (dl: dt/dd) ; .seed-grid > .seed-word (.n + word) ; progress.share (value/max)
 * Controls: .btn .btn-primary .btn-danger (a or button; .block full width) ; label.field > span + .input (input/select/textarea)
 *           .seg > label > input[radio] + span ; label.toggle > input[checkbox] + .track
 * Messages: .flash .flash.error .flash.ok
 * Helpers:  .row .stack .grow .center .ok .warn .danger .muted .dim .mono .small .big .setting (row: name left, control right)
 * Dark:     automatic (prefers-color-scheme) or <html data-theme="dark|light">. No inline styles/scripts (CSP). */
:root {
  --bg: #FFFFFF; --side: #F6F6F4; --sel: #F1F1EE; --nav: #E9E9E5; --line: #E5E5E2;
  --text: #1A1A1A; --muted: #6B6B6B; --dim: #9B9B98; --off: #CFCFCB;
  --ok: #1F7A3D; --warn: #B25E00; --danger: #C0362C;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171717; --side: #101010; --sel: #232323; --nav: #242424; --line: #2C2C2C;
    --text: #EDEDED; --muted: #A3A3A3; --dim: #707070; --off: #4A4A4A;
    --ok: #5FBF80; --warn: #E2A345; --danger: #F07467; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171717; --side: #101010; --sel: #232323; --nav: #242424; --line: #2C2C2C;
  --text: #EDEDED; --muted: #A3A3A3; --dim: #707070; --off: #4A4A4A;
  --ok: #5FBF80; --warn: #E2A345; --danger: #F07467; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
body.inset { background: var(--side); }
a { color: inherit; text-decoration: none; }
h1, h2, p, dl, dd { margin: 0; }

/* shell */
.layout { display: flex; min-height: 100%; }
.sidebar { width: 220px; flex: none; background: var(--side); padding: 28px 12px 20px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 16px; font-weight: 600; padding: 0 10px 22px; }
.nav-link { padding: 8px 10px; border-radius: 6px; color: var(--muted); }
.nav-link:hover { background: var(--sel); }
.nav-link.active { background: var(--nav); color: var(--text); font-weight: 600; }
.nav-gap { height: 16px; }
.divider { width: 1px; flex: none; background: var(--line); }
.main { flex: 1; min-width: 0; padding: 28px 20px; display: flex; flex-direction: column; gap: 28px; }
.page-head { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; }
.title { font-size: 22px; font-weight: 600; margin-right: auto; }
.actions { display: flex; align-items: center; gap: 8px; }
.panel { width: 360px; flex: none; padding: 28px 24px; display: flex; flex-direction: column; gap: 28px; }
.center-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; }
.center-form { width: 320px; display: flex; flex-direction: column; gap: 24px; }

/* sections, tables, key-value */
.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: center; gap: 12px; padding: 0 12px; }
.section-head h2 { font-size: 14px; font-weight: 600; margin-right: auto; }
.panel .section-head { padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th { font-size: 11px; font-weight: 400; color: var(--dim); text-align: left; padding: 0 12px 8px; }
.table td { padding: 12px; border-top: 1px solid var(--line); color: var(--muted); }
.table td:first-child { color: var(--text); }
.table tbody:last-child tr:last-child td, .table tr:last-child td { border-bottom: 1px solid var(--line); }
.table th.num { text-align: right; }
.table td.num { text-align: right; color: var(--text); }
.table tr.selectable { cursor: pointer; }
.table tr.selectable:hover td, .table tr.selected td { background: var(--sel); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px 0; }
.kv dt { color: var(--muted); }
.big { font-size: 36px; font-weight: 600; }
.small { font-size: 12px; }
.mono { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .danger { color: var(--danger); } .muted { color: var(--muted); } .dim { color: var(--dim); }
.setting { display: flex; align-items: center; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.center { text-align: center; }

/* controls */
.btn { font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; display: inline-flex; justify-content: center; align-items: center; }
.btn:hover { background: var(--sel); }
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary:hover { background: var(--text); opacity: .88; }
.btn-danger { color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); }
.input { font: inherit; width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.input:focus { outline: none; border-color: var(--text); }
.seg { display: flex; gap: 2px; padding: 2px; background: var(--side); border-radius: 6px; }
.seg label { flex: 1; }
.seg input, .toggle input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 10px; border-radius: 4px; font-size: 12px; color: var(--muted); border: 1px solid transparent; cursor: pointer; }
.seg input:checked + span { background: var(--bg); border-color: var(--line); color: var(--text); font-weight: 600; }
.toggle { position: relative; display: inline-block; width: 32px; height: 18px; flex: none; }
.toggle .track { position: absolute; inset: 0; border-radius: 9px; background: var(--off); cursor: pointer; transition: background .15s; }
.toggle .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); transition: transform .15s; }
.toggle input:checked + .track { background: var(--text); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--muted); outline-offset: 2px; }

/* seed words, share bar, messages */
.seed-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seed-word { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px; background: var(--side); font-size: 12px; color: var(--muted); min-width: 0; }
.seed-word .n { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 10px; color: var(--dim); }
progress.share { appearance: none; width: 100%; height: 4px; border: 0; border-radius: 2px; background: var(--line); }
progress.share::-webkit-progress-bar { background: var(--line); border-radius: 2px; }
progress.share::-webkit-progress-value { background: var(--text); border-radius: 2px; }
progress.share::-moz-progress-bar { background: var(--text); border-radius: 2px; }
.flash { padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--side); }
.flash.error { color: var(--danger); border-color: var(--danger); }
.flash.ok { color: var(--ok); border-color: var(--ok); }

/* items */
.nav-link { display: flex; align-items: center; gap: 10px; }
.nav-link svg { flex: none; }
.center-form .title { margin: 0; text-align: center; }
.panel-title { font-size: 16px; font-weight: 600; }
.table a.cell { display: block; margin: -12px; padding: 12px; color: inherit; min-height: 1em; }
.table a.cell.warn { color: var(--warn); } .table a.cell.muted { color: var(--muted); }
.search { width: 260px; }
.seg a { flex: 1; }
.seg a.on span { background: var(--bg); border-color: var(--line); color: var(--text); font-weight: 600; }
.secret-val { white-space: pre-wrap; word-break: break-all; padding: 8px; border-radius: 4px; background: var(--side); }
textarea.input { resize: vertical; }
.seg a span { white-space: nowrap; padding: 6px 4px; }

/* balances */
.nav-link .count { margin-left: auto; color: var(--dim); font-size: 12px; font-weight: 400; }
.tight { gap: 4px; padding: 0 12px; }
.total .big { line-height: 1.1; }
.asset { display: grid; grid-template-columns: 56px 1fr auto; gap: 6px 0; align-items: center; }
.asset b { font-weight: 600; }
.asset .usd { text-align: right; }
.asset progress { grid-column: 1 / -1; }
.bal-total { font-size: 22px; font-weight: 600; }
.interval { width: auto; padding: 4px 8px; }
.seg { flex-wrap: wrap; }
.seg a { flex: 1 1 auto; }

/* security, nowrap cells */
.table td.nw { white-space: nowrap; }
.table td.name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.log { display: flex; gap: 12px; align-items: flex-start; }
.log .t { width: 56px; flex: none; color: var(--dim); font-size: 12px; }
.prow { display: flex; align-items: center; gap: 16px; padding: 12px; border-top: 1px solid var(--line); }
.prow .n { width: 250px; flex: none; }
.prow.last { border-bottom: 1px solid var(--line); }
