/* AutoArb PWA — same palette as the local dashboard (slate surfaces, emerald
   accent), written by hand so the site needs no CSS framework or CDN. */

:root {
  --bg: #020617;
  --surface: #0f172a;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --dim: #64748b;
  --accent: #34d399;
  --accent-strong: #059669;
  --warn: #fbbf24;
  --bad: #f87171;
  --row-hover: #0a1022;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, p { margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
h4 { font-size: .8rem; color: #cbd5e1; margin-top: .75rem; }
small { font-size: .8em; color: var(--dim); font-weight: 400; }

a { color: var(--accent); }
a:hover { color: #6ee7b7; }

.muted { color: var(--dim); font-size: .78rem; }
.muted .strong { color: #e2e8f0; }
.dim { color: var(--dim); }
.soft { color: var(--muted); }
.strong { font-weight: 600; }
.good { color: var(--accent); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.bad-soft { color: #fca5a5; }
.profit { color: var(--accent); font-weight: 600; }
.price { color: #6ee7b7; font-weight: 600; white-space: nowrap; }
.mono, .key { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; color: #cbd5e1; }
.key, .wrap { overflow-wrap: anywhere; }
.caps { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.k { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); }
.small { font-size: .8rem; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.c { text-align: center; }
.spacer { flex: 1; }
.bolt { color: var(--accent); }

.boot { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.boot.error, .error { color: var(--bad); }
.empty { padding: 1.5rem; text-align: center; color: var(--dim); font-size: .85rem; }

/* ---- shell ------------------------------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.bar {
  max-width: 80rem; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: .5rem .75rem; flex-wrap: wrap;
}
.bar h1 { font-size: 1.15rem; white-space: nowrap; }
.bar nav { display: flex; gap: .25rem; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.bar nav a {
  padding: .35rem .7rem; border-radius: .375rem;
  color: var(--muted); text-decoration: none; font-size: .9rem; white-space: nowrap;
}
.bar nav a:hover { color: var(--text); }
.bar nav a.on { background: var(--accent-strong); color: #fff; font-weight: 500; }
.fresh { font-size: .75rem; white-space: nowrap; }

.page { max-width: 80rem; margin: 0 auto; padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom)); }
.stack > * + * { margin-top: 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .5rem; padding: .9rem 1rem;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }

/* ---- controls ---------------------------------------------------------- */

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

button.primary {
  background: var(--accent-strong); color: #fff; border: 0;
  border-radius: .375rem; padding: .6rem 1rem; font-weight: 600;
}
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost {
  background: transparent; border: 1px solid var(--border-strong);
  border-radius: .375rem; padding: .35rem .7rem; color: var(--muted);
}
button.ghost:hover { color: var(--text); }
button.link { background: none; border: 0; padding: .25rem; color: var(--dim); font-size: .8rem; }
button.link:hover { color: var(--text); }
button.more { display: block; margin: 1rem auto 0; }

button.ghost:disabled { opacity: .35; cursor: default; }
button.ghost:disabled:hover { color: var(--muted); }

select, input[type="number"], input[type="password"], input[type="search"] {
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: .375rem; padding: .4rem .5rem; min-width: 0; width: 100%;
}
:is(button, select, input, a, summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: .2rem; font-size: .72rem; color: var(--dim); }
.field.inline { flex-direction: row; align-items: center; gap: .4rem; }
.field.inline select { width: auto; }
.check { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }

.filters {
  display: grid; gap: .6rem .75rem; align-items: end;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: .5rem; padding: .9rem 1rem;
}

.segmented { display: flex; flex-wrap: wrap; gap: .15rem; }
.segmented button {
  background: transparent; border: 0; border-radius: .375rem;
  padding: .25rem .6rem; font-size: .78rem; color: var(--muted);
}
.segmented button:hover { color: var(--text); }
.segmented button.on { background: rgba(16, 185, 129, .15); color: var(--accent); }

/* ---- unlock ------------------------------------------------------------ */

.unlock { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.unlock form { width: 100%; max-width: 22rem; display: grid; gap: .7rem; }
.unlock h1 { font-size: 1.4rem; }
.unlock label { font-size: .8rem; color: var(--muted); }
.unlock input { font-size: 1rem; padding: .6rem .7rem; letter-spacing: .04em; }

/* ---- prilike ----------------------------------------------------------- */

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: .5rem;
  padding: .7rem .9rem; display: flex; flex-direction: column; gap: .15rem; min-width: 0;
}
.tile .v { font-size: 1.35rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
/* The sortable data tables of Prilike, Depreciation and Prodato. */
table.data { font-size: .875rem; }
table.data th {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 600;
  color: var(--dim); padding: .5rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data th:not(.r) { text-align: left; }
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--text); }
table.data th[aria-sort]:not([aria-sort="none"]) { color: var(--accent); }
table.data td { padding: .5rem; border-bottom: 1px solid var(--surface); vertical-align: middle; }
table.data tbody tr:hover, table.data tbody tr:hover .sticky { background: var(--row-hover); }
table.opps tbody tr { cursor: pointer; }
table.dense { font-size: .78rem; }
table.dense :is(th, td) { padding: .4rem .45rem; }
/* The first column stays put while a wide table scrolls sideways. */
table.data .sticky { position: sticky; left: 0; z-index: 1; background: var(--bg); }
td.wide { max-width: 20rem; }
td.keyed { max-width: 15rem; white-space: nowrap; }   /* a model with its FullKey underneath */

.title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: .68rem; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tier { font-size: .7rem; font-weight: 600; padding: .1rem .35rem; border-radius: .25rem; }
.t1 { background: #059669; color: #fff; }
.t2 { background: #65a30d; color: #fff; }
.t3 { background: #f59e0b; color: #0f172a; }
.t4 { background: #ea580c; color: #fff; }
.t5 { background: #b91c1c; color: #fff; }

.tag.damaged { font-size: .6rem; font-weight: 600; padding: .1rem .25rem; border-radius: .2rem; background: #dc2626; color: #fff; }

.status { font-size: .72rem; padding: .1rem .4rem; border-radius: .25rem; white-space: nowrap; }
.s-new { background: rgba(59, 130, 246, .2); color: #93c5fd; }
.s-reviewed { background: rgba(245, 158, 11, .2); color: #fcd34d; }
.s-watching { background: rgba(168, 85, 247, .2); color: #d8b4fe; }
.s-bought { background: rgba(16, 185, 129, .2); color: #6ee7b7; }
.s-ignored { background: var(--border-strong); color: var(--muted); }

.cards { list-style: none; margin-bottom: 0; padding: 0; display: grid; gap: .6rem; }
.opp {
  background: var(--surface); border: 1px solid var(--border); border-radius: .5rem;
  padding: .7rem .8rem; display: grid; gap: .3rem; cursor: pointer; min-width: 0;
}
.opp .title { white-space: normal; }
.opp-head { display: flex; align-items: center; gap: .5rem; }
.opp-head .profit { font-size: 1.05rem; }
.opp-nums { display: flex; flex-wrap: wrap; gap: .15rem .8rem; font-size: .8rem; }
.opp .sub { white-space: normal; overflow-wrap: anywhere; }
.cards.flat .opp { cursor: default; }   /* nothing to open behind these */

.outlink {
  display: inline-block; padding: .15rem .45rem; border-radius: .25rem;
  color: var(--muted); text-decoration: none;
}
.outlink:hover { color: var(--accent); background: var(--border); }

/* ---- drawer (opportunity detail, model breakdown) ------------------------ */

body.no-scroll { overflow: hidden; }
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(2, 6, 23, .7); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(34rem, 100vw); display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border-strong);
  box-shadow: -1rem 0 2rem rgba(0, 0, 0, .45);
}
.drawer.wide { width: min(80rem, 100vw); }
.drawer-head {
  display: flex; align-items: flex-start; gap: .75rem;
  padding: calc(.8rem + env(safe-area-inset-top)) 1rem .8rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 1.05rem; overflow-wrap: anywhere; }
.drawer-head .opp-head + h2 { margin-top: .4rem; }
.grow { flex: 1; min-width: 0; }
.close {
  flex: none; width: 2.25rem; height: 2.25rem; font-size: 1rem;
  background: none; border: 1px solid var(--border-strong); border-radius: .375rem; color: var(--muted);
}
.close:hover { color: var(--text); }
.drawer-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
}

.big { font-size: 1.5rem; line-height: 1.1; }
table.ledger { margin-top: .5rem; font-size: .875rem; }
table.ledger td { padding: .3rem 0; }
table.ledger td.r { white-space: nowrap; padding-left: .75rem; }
table.ledger tr.sum td { border-top: 1px solid var(--border-strong); font-weight: 600; }
table.ledger tr:last-child td { border-bottom: 0; }

.note {
  background: var(--surface); border: 1px solid var(--border); border-radius: .5rem;
  padding: .6rem .8rem; font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.specs {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem .75rem;
  margin-top: .5rem; font-size: .875rem;
}
.specs > div { min-width: 0; overflow-wrap: anywhere; }
.keys { margin-top: .7rem; display: grid; gap: .15rem; font-size: .75rem; color: var(--dim); }
.hint { margin-top: .5rem; }

.comps {
  max-height: 24rem; overflow: auto; margin-top: .5rem;
  border: 1px solid var(--border); border-radius: .5rem;
}
.comps th { position: sticky; top: 0; background: var(--surface); }
.comps td { color: #cbd5e1; white-space: nowrap; }
.comps td.amount { color: #e2e8f0; }
.comps tr.trimmed td { color: var(--dim); }   /* outside the IQR fence: not in the median */
.comps tr.trimmed td.amount { text-decoration: line-through; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; font-size: .875rem; }
a.button {
  background: var(--accent-strong); color: #fff; border-radius: .375rem;
  padding: .55rem .9rem; font-weight: 600; text-decoration: none;
}
a.button:hover { background: #10b981; color: #fff; }

/* ---- depreciation, prodato ---------------------------------------------- */

a.model { color: var(--text); font-weight: 600; text-decoration: underline dotted var(--border-strong); text-underline-offset: 3px; }
a.model:hover { color: var(--accent); }

.signal { font-size: .7rem; font-weight: 700; padding: .1rem .4rem; border-radius: .25rem; background: var(--border-strong); color: #e2e8f0; }
.sig-buy { background: #059669; color: #fff; }
.sig-hold { background: #f59e0b; color: #0f172a; }
.sig-sell { background: #f87171; color: #0f172a; }
.sig-avoid { background: #b91c1c; color: #fff; }

.trim { font-size: .65rem; font-weight: 600; padding: .1rem .35rem; border-radius: .25rem; background: #4f46e5; color: #fff; }
.share { vertical-align: middle; margin-left: .3rem; }
.share rect { fill: #059669; }

.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; font-size: .8rem; color: var(--dim); }

/* ---- statistika -------------------------------------------------------- */

.chart { display: block; width: 100%; height: auto; user-select: none; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); stroke-width: 1; }
.chart .axis { fill: var(--dim); font-size: 11px; }
.chart .bar { fill: #10b981; fill-opacity: .85; transition: fill-opacity 100ms; }
.chart .bar:hover { fill-opacity: 1; }

.panels { display: grid; gap: .75rem; margin-top: .6rem; }

details { margin-top: .6rem; font-size: .8rem; }
summary { cursor: pointer; color: var(--muted); width: fit-content; }
summary:hover { color: var(--text); }
.scroll { max-height: 16rem; overflow-y: auto; margin-top: .5rem; }

table.plain { font-size: .8rem; }
table.plain th { text-align: left; font-weight: 400; color: var(--dim); padding: .25rem .4rem; border-bottom: 1px solid var(--border); }
table.plain th.r { text-align: right; }
table.plain td { padding: .25rem .4rem; border-bottom: 1px solid rgba(30, 41, 59, .5); }

.health { table-layout: fixed; }
.health td:nth-child(1) { width: 34%; }
.health td:nth-child(2) { width: 16%; }
.health td:nth-child(4) { width: 5.5rem; }

.pill { font-size: .7rem; font-weight: 600; padding: .1rem .4rem; border-radius: .25rem; color: #fff; }
.pill.good { background: #059669; }
.pill.warn { background: #b45309; }
.pill.bad { background: #dc2626; }

.alert {
  border: 1px solid #b91c1c; background: rgba(69, 10, 10, .4);
  border-radius: .5rem; padding: .7rem .9rem; font-size: .85rem; color: #fecaca;
}
.alert.amber { border-color: #b45309; background: rgba(69, 26, 3, .4); color: #fde68a; }

/* ---- breakpoints ------------------------------------------------------- */

.wide-only { display: none; }
.when { display: none; }   /* phones show the age only; the timestamp needs room */

@media (min-width: 56rem) {
  .wide-only { display: block; }
  .when { display: inline; }
  .narrow-only { display: none !important; }
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .panels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
