:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --border: #d9dfe5;
  --text: #17212b;
  --muted: #5f6d7a;
  --accent: #2f6f9f;
  --accent-ink: #ffffff;
  --accent-soft: #e2edf6;
  --good: #1f7a4d;
  --bad: #b3392f;
  --bar: #8fb3cf;
  --bar-neg: #e0a19b;
  --shadow: 0 1px 2px rgba(20, 30, 40, .06), 0 2px 8px rgba(20, 30, 40, .05);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161b; --surface: #182028; --surface-2: #1f2932; --border: #2c3843;
    --text: #e3e9ee; --muted: #93a2af; --accent: #6aa8d8; --accent-ink: #0d1822; --accent-soft: #1d3346;
    --good: #5cc28f; --bad: #ec7d72; --bar: #3d6788; --bar-neg: #7a3d38;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161b; --surface: #182028; --surface-2: #1f2932; --border: #2c3843;
  --text: #e3e9ee; --muted: #93a2af; --accent: #6aa8d8; --accent-ink: #0d1822; --accent-soft: #1d3346;
  --good: #5cc28f; --bad: #ec7d72; --bar: #3d6788; --bar-neg: #7a3d38;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.err { color: var(--bad); min-height: 1.2em; margin: .3em 0; font-size: .9rem; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; fill: #8199ad; }
.brand svg .dk { fill: #50657a; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 16px 12px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 500;
}
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.top-right { display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
@media (max-width: 720px) {
  .top-inner { gap: 4px 12px; padding-top: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs a { padding: 10px 10px; }
  .top-right { margin-left: auto; }
}

main { padding: 20px 16px 8px; }
.foot { color: var(--muted); font-size: .8rem; padding-bottom: 24px; }

/* controls */
.btn {
  font: inherit; font-weight: 550; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); padding: 7px 14px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 6px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type="number"] { font-family: var(--mono); text-align: right; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: .82rem; color: var(--muted); font-weight: 500; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head p { margin: 0; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; }

/* price list */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { max-width: 260px; }
.toolbar select { width: auto; }
.list { display: flex; flex-direction: column; gap: 8px; }
.ingot > summary {
  list-style: none; cursor: pointer; display: grid; align-items: center; gap: 12px;
  grid-template-columns: 18px minmax(140px, 1.2fr) 2fr auto auto; padding: 12px 16px;
}
.ingot > summary::-webkit-details-marker { display: none; }
.chev { width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
.ingot[open] .chev { transform: rotate(45deg); }
.ingot .nm { font-weight: 650; }
.ingot .std { font-size: .8rem; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: .75rem; background: var(--surface-2); border-radius: 5px; padding: 1px 6px; font-family: var(--mono); }
.price { text-align: right; }
.price b { font-size: 1.1rem; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.price small { display: block; color: var(--muted); font-size: .75rem; }
.ingot .body { border-top: 1px solid var(--border); padding: 12px 16px 16px; }
@media (max-width: 720px) {
  .ingot > summary { grid-template-columns: 14px 1fr auto; }
  .ingot .chips, .ingot .price.t { display: none; }
}

/* tables */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }
tfoot td { font-weight: 650; border-bottom: none; }
tr.bal td { color: var(--muted); }
.bar { position: relative; height: 8px; min-width: 80px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar i { position: absolute; top: 0; bottom: 0; left: 0; background: var(--bar); border-radius: 4px; }
.bar i.neg { background: var(--bar-neg); }
.ov { color: var(--accent); font-weight: 650; }
.up { color: var(--good); } .dn { color: var(--bad); }
.edit-tbl td { padding: 4px 6px; }
.edit-tbl input[type="number"] { width: 110px; }
.edit-tbl input.w-sym { width: 64px; }
.edit-tbl input.w-name { width: 140px; }

/* calculator */
.calc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; align-items: start; }
@media (max-width: 820px) { .calc { grid-template-columns: 1fr; } }
.grid-inputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.big { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.big div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.big small { color: var(--muted); font-size: .75rem; display: block; }
.big b { font-family: var(--mono); font-size: 1.15rem; font-variant-numeric: tabular-nums; word-break: break-all; }
@media (max-width: 480px) { .big { grid-template-columns: 1fr; } }

/* types editor */
.type-ed > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.type-ed > summary::-webkit-details-marker { display: none; }
.type-ed .body { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.meta-grid { display: grid; grid-template-columns: 1fr 1fr 140px; gap: 10px; }
@media (max-width: 620px) { .meta-grid { grid-template-columns: 1fr; } }
.sub { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; width: min(360px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog input { margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(80px);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: .9rem;
  transition: transform .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
