:root {
  --bg: #101418; --panel: #1a2027; --text: #e6e9ec; --muted: #8a94a0;
  --accent: #e3b341; --line: #2a323c; --good: #4ec27b; --stale: #c0863a;
  --navheight: 3.5rem;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }

/* Mobile-first: brand bar on top, thumb-reachable tab bar fixed to the bottom. */
header { display: flex; align-items: baseline; gap: 1.5rem; padding: .8rem 1.2rem; border-bottom: 1px solid var(--line); }
header h1 { font-size: 1.1rem; margin: 0; }
header a { color: var(--text); text-decoration: none; }
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav a {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: var(--navheight); color: var(--muted); text-decoration: none; font-weight: 600;
}
nav a[aria-current] { color: var(--accent); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem calc(var(--navheight) + env(safe-area-inset-bottom) + 1rem); }

@media (min-width: 720px) {
  nav { position: static; background: none; border: 0; padding: 0; }
  nav a { flex: none; min-height: 0; margin-right: 1rem; font-weight: 400; }
  nav a:hover { color: var(--accent); }
  main { padding: 1.2rem; }
}

.muted { color: var(--muted); }
.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.panel h3 { margin: 0 0 .4rem; }
a.panel { display: block; color: var(--text); text-decoration: none; }
a.panel:hover { border-color: var(--accent); }

/* Tables span the full width and scroll sideways inside their own wrapper —
   the page itself never scrolls horizontally on a phone. */
.tablewrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--bg); }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--panel); }
@media (min-width: 720px) {
  .tablewrap { margin: 0; padding: 0; }
  th, td { padding: .35rem .5rem; }
}

.chip { display: inline-block; font-size: .72rem; padding: 0 .4rem; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); margin-left: .35rem; }
.price { white-space: nowrap; }
.price .src { color: var(--muted); font-size: .75rem; }
.stale { color: var(--stale); }
.placeholder { border: 1px dashed var(--line); border-radius: 8px; padding: .8rem 1rem; color: var(--muted); }
form.auth { max-width: 380px; margin: 3rem auto; display: flex; flex-direction: column; gap: .7rem; }
input, button, select, textarea { font: inherit; padding: .5rem .7rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
button { background: var(--accent); color: #14181c; border: 0; cursor: pointer; font-weight: 600; min-height: 2.75rem; }
button.secondary { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.notice { padding: .6rem .9rem; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); }
.error { border-color: #b3494e; color: #e8a0a3; }
.kpis { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.kpis .panel { min-width: 160px; flex: 1 1 40%; }
@media (min-width: 720px) { .kpis .panel { flex: none; } }
.kpis .big { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; }
.searchbar { margin: .6rem 0 1rem; width: 100%; min-height: 2.75rem; }

/* Per-row quick actions (add from browse, remove from holdings): 44px touch
   targets that never hijack the row's own tap-to-detail. */
td.actioncell { width: 1%; padding: .25rem .35rem; }
button.rowaction {
  min-height: 2.75rem; min-width: 2.75rem; padding: 0;
  background: var(--panel); color: var(--accent); border: 1px solid var(--line);
  border-radius: 8px; font-size: 1.2rem; line-height: 1;
}
button.rowaction:hover { border-color: var(--accent); }

/* Bottom sheet: the one-thumb add/remove form. */
#sheet .sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }
#sheet .sheet-panel {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0; padding: 1rem 1rem calc(env(safe-area-inset-bottom) + 1rem);
  max-height: 85vh; overflow-y: auto;
}
#sheet form { display: flex; flex-direction: column; gap: .7rem; margin-top: .7rem; }
#sheet h3 { margin: 0; }
@media (min-width: 720px) {
  #sheet .sheet-panel { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 50%);
    width: 420px; border: 1px solid var(--line); border-radius: 12px; }
}
.formrow { display: flex; gap: .7rem; }
.formrow label { flex: 1; }
label { display: flex; flex-direction: column; gap: .25rem; color: var(--muted); font-size: .85rem; }
label input, label select { width: 100%; }
label.inline { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); font-size: 1rem; }
label.inline input { width: auto; }

/* Toast + view-header row (title, picker, actions). */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 40;
  bottom: calc(var(--navheight) + env(safe-area-inset-bottom) + 1rem);
  background: var(--accent); color: #14181c; font-weight: 600;
  padding: .55rem 1rem; border-radius: 8px;
}
.viewhead { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin: .4rem 0 .8rem; }
.viewhead h2 { margin: 0; flex: 1 1 auto; }
.viewhead select { min-height: 2.75rem; }
button.small { min-height: 2.25rem; padding: .25rem .7rem; font-size: .85rem; }
.wtp textarea { width: 100%; min-height: 4rem; resize: vertical; }
