/* Goldmine — slate and assay-gold. Light and dark share one set of tokens. */
:root {
  --bg: #edf0f3; --surface: #ffffff; --surface-2: #f6f8fa; --ink: #17212b; --muted: #5d6a77; --line: #dce1e7;
  --side: #101a26; --side-ink: #c4cfdb; --side-mute: #7f8d9c; --side-line: #1d2a39;
  --gold: #e0a526; --gold-ink: #1c1400; --gold-text: #8f6200; --gold-soft: #fbf1d6;
  --ok: #1d7a58; --warn: #a15c00; --bad: #b3362b; --info: #2a6a9e;
  --shadow: 0 1px 2px rgba(16,26,38,.06), 0 4px 14px rgba(16,26,38,.05);
  --r: 10px; --side-w: 244px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0b121a; --surface: #121b26; --surface-2: #0f1721; --ink: #e6ebf0; --muted: #94a1ae; --line: #233140;
  --side: #090f16; --side-ink: #b9c5d1; --side-line: #172230;
  --gold: #e8b23c; --gold-text: #f0c35c; --gold-soft: #2a2310;
  --ok: #4cc79b; --warn: #f0b04a; --bad: #f08074; --info: #6fb1e6;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.tab, .num { font-variant-numeric: tabular-nums; }
.num { text-align: right; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.ic { width: 1.15em; height: 1.15em; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; flex: none; }
[data-theme="dark"] .if-light, :root:not([data-theme="dark"]) .if-dark { display: none; }

/* ---- Shell ---- */
.shell { min-height: 100vh; }
.side { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; z-index: 40; transition: transform .2s ease; }
.brand { display: flex; align-items: center; gap: .7rem; height: 60px; padding: 0 1.25rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; border-bottom: 1px solid var(--side-line); }
.brand img { border-radius: 7px; }
.nav { flex: 1; overflow-y: auto; padding: .75rem .75rem 1rem; }
.nav-label { padding: 1rem .65rem .35rem; font-size: .78rem; color: var(--side-mute); font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: .7rem; padding: .55rem .65rem; border-radius: 8px; color: var(--side-ink); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.is-active { background: rgba(224,165,38,.14); color: #f3c75a; box-shadow: inset 3px 0 0 var(--gold); }
.side-foot { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-top: 1px solid var(--side-line); }
.who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who strong { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.who span { font-size: .8rem; color: var(--side-mute); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: rgba(127,141,156,.18); }
.main { margin-left: var(--side-w); min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; height: 60px; padding: 0 1.5rem; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top-title { flex: 1; font-weight: 600; color: var(--muted); }
.page { padding: 1.5rem; max-width: 1280px; }
.only-mobile { display: none; }
.scrim { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.65rem; line-height: 1.2; letter-spacing: -.01em; }
.sub { color: var(--muted); margin-top: .2rem; max-width: 62ch; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---- Cards ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 1rem; font-weight: 650; }
.card-b { padding: 1.1rem; }
.stack { display: grid; gap: 1.25rem; }
.cols { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); align-items: start; }

/* ---- Buttons & forms ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 38px; padding: 0 .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--gold); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost-danger { color: var(--bad); }
.btn-sm { min-height: 32px; padding: 0 .65rem; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
.in, select.in, textarea.in { min-height: 38px; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); font: inherit; max-width: 100%; }
textarea.in { width: 100%; resize: vertical; }
.in:focus { border-color: var(--gold); outline: 2px solid color-mix(in srgb, var(--gold) 35%, transparent); }
.grow { flex: 1 1 220px; }
.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > label, .lbl { font-weight: 600; font-size: .92rem; }
.hint { color: var(--muted); font-size: .86rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }

.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 4px); min-width: 150px; padding: .3rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 30; }
.menu-pop a { display: block; padding: .5rem .65rem; border-radius: 6px; text-decoration: none; }
.menu-pop a:hover { background: var(--surface-2); }

.switch { position: relative; display: inline-flex; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i { width: 38px; height: 22px; border-radius: 22px; background: var(--line); transition: background .15s; position: relative; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--gold); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---- Badges / chips ---- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.b-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.b-enr { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.b-bl { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.b-un { color: var(--muted); background: color-mix(in srgb, var(--muted) 15%, transparent); }
.chip { display: inline-block; padding: .1rem .55rem; border-radius: 6px; background: var(--gold-soft); color: var(--gold-text); font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums; }
.chip:hover { filter: brightness(.96); }

/* ---- Flash ---- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid var(--line); border-left-width: 4px; background: var(--surface); }
.flash-success { border-left-color: var(--ok); }
.flash-warning { border-left-color: var(--warn); }
.flash-danger { border-left-color: var(--bad); }
.flash-info { border-left-color: var(--info); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: .82rem; font-weight: 650; color: var(--muted); padding: .6rem .85rem; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.tbl th.num { text-align: right; }
.tbl td { padding: .6rem .85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }
.card-f { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: .75rem 1.1rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.pager { display: flex; flex-wrap: wrap; gap: .25rem; }
.pg { min-width: 34px; height: 34px; padding: 0 .6rem; display: inline-flex; align-items: center; justify-content: center; border-radius: 7px; border: 1px solid var(--line); text-decoration: none; background: var(--surface); color: var(--ink); font-size: .9rem; }
a.pg:hover { border-color: var(--muted); }
.pg.is-on { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 700; }
.pg.is-off { color: var(--muted); border-color: transparent; background: transparent; }

/* ---- Dashboard ---- */
.stamp { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem 2rem; padding: 1.15rem 1.4rem; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--gold); border-radius: var(--r); box-shadow: var(--shadow); }
.stamp-k { color: var(--muted); font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: .45rem; }
.stamp-d { font-size: 2.35rem; line-height: 1.15; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stamp-m { color: var(--muted); font-size: .9rem; text-align: right; }
.stamp.is-empty { border-left-color: var(--line); }
.stamp.is-empty .stamp-d { font-size: 1.35rem; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { padding: 1rem 1.1rem; }
.stat-k { color: var(--muted); font-weight: 600; font-size: .9rem; }
.stat-v { font-size: 1.9rem; line-height: 1.2; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin: .15rem 0; }
.stat-s { color: var(--muted); font-size: .86rem; }
.stat.is-key { border-color: color-mix(in srgb, var(--gold) 55%, var(--line)); }
.bar { display: flex; height: 8px; border-radius: 8px; overflow: hidden; background: var(--line); min-width: 120px; }
.bar > i { display: block; height: 100%; }
.bar .s-ok { background: var(--ok); }
.bar .s-enr { background: var(--warn); }
.bar .s-used { background: var(--muted); opacity: .55; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; color: var(--muted); font-size: .84rem; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: .4rem; background: var(--muted); }
.legend .l-ok::before { background: var(--ok); } .legend .l-enr::before { background: var(--warn); } .legend .l-used::before { background: var(--muted); opacity: .55; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1.1rem; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .meta { color: var(--muted); font-size: .86rem; }

/* ---- Create a file ---- */
.create-grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 0; }
.row + .row { border-top: 1px solid var(--line); }
.row-t strong { display: block; }
.size-in { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.size-in .in { width: 130px; font-size: 1.1rem; font-weight: 650; }
.srch-list { max-height: 460px; overflow-y: auto; border-top: 1px solid var(--line); }
.srch-row { display: flex; align-items: center; gap: .85rem; padding: .6rem 1.1rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.srch-row:last-child { border-bottom: 0; }
.srch-row .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.srch-row .ct { font-variant-numeric: tabular-nums; font-weight: 650; }
.srch-row.is-off .nm, .srch-row.is-off .ct { color: var(--muted); text-decoration: line-through; }
.srch-row.is-empty { opacity: .55; }
.srch-bar { display: flex; flex-wrap: wrap; gap: .5rem; padding: .85rem 1.1rem; align-items: center; }
.summary { position: sticky; top: 76px; }
.sum-n { font-size: 2.4rem; font-weight: 750; line-height: 1.1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sum-l { color: var(--muted); font-size: .9rem; }
.sum-row { display: flex; justify-content: space-between; padding: .5rem 0; border-top: 1px solid var(--line); }
.sum-row b { font-variant-numeric: tabular-nums; }
.note { padding: .6rem .8rem; border-radius: 8px; background: color-mix(in srgb, var(--warn) 13%, transparent); color: var(--ink); font-size: .9rem; margin-bottom: .9rem; }

/* ---- Import ---- */
.drop { display: block; padding: 2.2rem 1rem; text-align: center; border: 2px dashed var(--line); border-radius: var(--r); background: var(--surface-2); cursor: pointer; }
.drop:hover, .drop.is-over { border-color: var(--gold); background: var(--gold-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop strong { display: block; font-size: 1.05rem; }
.drop-list { margin: .9rem 0 0; padding: 0; list-style: none; color: var(--muted); font-size: .9rem; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .75rem; padding: 1rem 1.1rem; }
.res-grid div b { display: block; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.res-grid div span { color: var(--muted); font-size: .85rem; }

/* ---- Dialog ---- */
.dlg { border: 1px solid var(--line); border-radius: 12px; padding: 1.4rem; max-width: 440px; width: calc(100% - 2rem); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.dlg::backdrop { background: rgba(8,14,22,.55); }
.dlg h2 { font-size: 1.15rem; margin-bottom: .5rem; }
.dlg p { color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ---- Login / setup ---- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: .75rem; font-weight: 750; font-size: 1.4rem; margin-bottom: 1.5rem; }
.auth-brand img { border-radius: 9px; }
.auth-card .in { width: 100%; }
.auth-card h1 { font-size: 1.2rem; margin-bottom: .25rem; }
.auth-card .btn { width: 100%; }

/* ---- Responsive ---- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols, .create-grid { grid-template-columns: 1fr; } .summary { position: static; } }
@media (max-width: 900px) {
  .side { transform: translateX(-100%); }
  .side.is-open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .scrim.is-open { display: block; position: fixed; inset: 0; background: rgba(8,14,22,.5); z-index: 35; }
  .main { margin-left: 0; }
  .only-mobile { display: inline-flex; }
  .top { padding: 0 .75rem; }
  .page { padding: 1rem; }
  .stamp-m { text-align: left; }
}
@media (max-width: 520px) { .stats { grid-template-columns: 1fr; } .stamp-d { font-size: 1.9rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Menus inside tables open in place instead of floating, so the table's scroll area never clips them */
.tbl .menu-pop { position: static; box-shadow: none; margin-top: .4rem; }
