:root {
  --bg: #f6f4ef; --surface: #ffffff; --surface-2: #faf8f3; --border: #e6e1d6;
  --text: #1f1c17; --muted: #756e60; --gold: #b8860b; --gold-soft: #f3e7c4;
  --pos: #1a7f4b; --neg: #c0392b; --focus: #d4a017;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f; --surface: #1d1b16; --surface-2: #23211b; --border: #34302672;
    --text: #ece7db; --muted: #a39b88; --gold: #e0b44c; --gold-soft: #3a3020;
    --pos: #4cc489; --neg: #ef7466; --focus: #e0b44c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.15rem; display: flex; align-items: center; gap: .55rem; }
h2 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
.coin { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe9a6, #d4a017 55%, #8a6408); box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.12); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; }
.login-card h1 { margin-bottom: 6px; }

/* Layout */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; display: grid; gap: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile.live { background: linear-gradient(135deg, var(--gold-soft), var(--surface) 70%); }
.tile-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.tile-value { font-size: 1.55rem; font-weight: 650; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.tile-sub.pos, .tile-sub.neg { font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 0 var(--pos); animation: pulse 2s infinite; }
.dot.stale { background: var(--muted); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--pos) 60%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* Tables */
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 3px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 650; border-bottom: none; padding-top: 10px; }
.n { text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }

input, select, button { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.cell { border-color: transparent; background: transparent; padding: 5px 6px; border-radius: 6px; }
.cell:hover { border-color: var(--border); }
.cell:focus { background: var(--surface); border-color: var(--focus); }
td.n .cell { text-align: right; width: 7.5em; }
td .cell[type=date] { width: 10.5em; }
.cell.notes { min-width: 12em; }
select.cell { min-width: 12em; }

input.readonly { background: var(--surface-2); color: var(--muted); cursor: default; }
input.readonly:focus-visible { outline: none; }
td.readonly { color: var(--muted); }

button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button:hover { border-color: var(--gold); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 600; }
button.ghost { background: transparent; }
button.icon { padding: 4px 9px; background: transparent; border-color: transparent; color: var(--muted); }
button.icon.danger:hover:not(:disabled) { color: var(--neg); border-color: var(--neg); }

/* Forms */
label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
.add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.add-grid .wide { grid-column: span 2; }
.new-type { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; border: 1px dashed var(--gold); border-radius: 10px; padding: 10px 12px 12px; margin: 0; }
.new-type legend { font-size: .8rem; color: var(--gold); padding: 0 6px; }
.actions { display: flex; justify-content: flex-end; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1 1 140px; }
.error { color: var(--neg); margin: 0; min-height: 1.2em; font-size: .88rem; grid-column: 1 / -1; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; font-size: .9rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--neg); color: #fff; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; } .wrap { padding: 16px 16px 48px; }
  .add-grid .wide { grid-column: 1 / -1; }
  .tile-value { font-size: 1.3rem; }
}
