/* =====================================================================
   LLM Hardware Explorer — styles
   Design goals: read 40+ columns of numbers without eye strain, never
   trap the user when they switch to Arabic (RTL), and stay usable on a
   phone where a 40-row table is the enemy.
   ===================================================================== */

:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --border:    #dfe3e8;
  --text:      #16191d;
  --text-dim:  #5d6672;
  --accent:    #2563eb;
  --accent-soft: #e6efff;
  --good:      #15803d;
  --good-soft: #e7f6ec;
  --warn:      #b45309;
  --warn-soft: #fdf3e3;
  --bad:       #b91c1c;
  --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --radius:    10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #101317;
    --surface:   #171b21;
    --surface-2: #1e232b;
    --border:    #2b323c;
    --text:      #e8ebef;
    --text-dim:  #9aa4b2;
    --accent:    #6ea8ff;
    --accent-soft: #1b2a44;
    --good:      #4ade80;
    --good-soft: #14281d;
    --warn:      #fbbf24;
    --warn-soft: #2a2113;
    --bad:       #f87171;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 4px 18px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

body[dir="rtl"] { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1800px; margin: 0 auto; padding: 0 18px 64px; }

/* ---------- header ---------- */
header.site {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-inner {
  max-width: 1800px; margin: 0 auto; padding: 14px 18px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
/* The mark centres against the text block instead of sitting on its baseline. */
.brand .mark { align-self: center; flex: none; display: block; }
.brand h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.brand .sub { font-size: 12.5px; color: var(--text-dim); }
.spacer { flex: 1 1 auto; }

.lang-switch { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.lang-switch button {
  border: 0; background: transparent; color: var(--text-dim);
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 6px; cursor: pointer;
}
.lang-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-dim);
  width: 34px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1;
}

/* ---------- controls ---------- */
.controls {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin: 20px 0 12px;
}
.controls input[type="search"], .controls select {
  font: inherit; font-size: 14px;
  padding: 8px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-width: 150px;
}
.controls input[type="search"] { min-width: 240px; flex: 1 1 240px; max-width: 380px; }
.controls input[type="search"]:focus, .controls select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 8px 13px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { font-size: 12.5px; padding: 5px 10px; }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 12px; }
.chip {
  font-size: 12.5px; padding: 4px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.result-line { font-size: 13px; color: var(--text-dim); margin: 0 0 10px; display: flex; gap: 14px; flex-wrap: wrap; }
.result-line strong { color: var(--text); }

/* ---------- table ---------- */
.table-shell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 74vh;
  /* Vertical scrolling only. A horizontal bar here means a cell was allowed to
     push the table wider than its box — the table is fixed-layout and always
     100% wide, so that must never happen. */
  overflow-y: auto; overflow-x: hidden;
}
/* Fixed layout keeps the table exactly as wide as its box, so there is no
   horizontal scrollbar to chase. The cells WRAP rather than truncate: a cut-off
   "NVIDIA Quadro RTX…" tells you nothing, while a name over two lines does.
   overflow-wrap covers the one case fixed layout cannot: an unbreakable string
   longer than its column. */
table.grid {
  border-collapse: separate; border-spacing: 0;
  width: 100%; table-layout: fixed;
  font-size: 12.5px;
}

table.grid thead th {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 6px 7px; text-align: start;
  /* Labels wrap instead of being cut: "Max model Q4" over two lines is
     readable, "Max mode…" is not. */
  white-space: normal; line-height: 1.15; vertical-align: bottom;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: var(--text-dim); cursor: pointer; user-select: none;
}
table.grid thead th:hover { color: var(--accent); }
table.grid thead th .dir { font-size: 10px; margin-inline-start: 3px; }
table.grid thead th[data-nosort] { cursor: default; }

table.grid tbody td {
  padding: 5px 7px; border-bottom: 1px solid var(--border);
  /* Wrap, never truncate. Numbers are short enough that wrapping never fires
     for them; long device names and vendor lines get a second line instead of
     an ellipsis. */
  white-space: normal; vertical-align: middle;
  overflow-wrap: anywhere;
}
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid tbody tr.selected td { background: var(--accent-soft); }
table.grid tbody tr[hidden] { display: none; }

.num { text-align: end; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
body[dir="rtl"] .num { text-align: start; }

/* The device column holds by far the widest content, so it takes a set share of
   the width and the rest divide what is left. Nothing is sticky: with no
   horizontal scrolling there is nothing to stick against. */
table.grid th.col-device, table.grid td.col-device { width: 22%; }
table.grid th.col-memory, table.grid td.col-memory { width: 9%; }
table.grid th.col-bandwidth, table.grid td.col-bandwidth { width: 7%; }
table.grid th.col-tensorCores, table.grid td.col-tensorCores { width: 8%; }
table.grid th.col-maxModelQ4, table.grid td.col-maxModelQ4 { width: 8%; }
table.grid th.col-tokens, table.grid td.col-tokens { width: 10%; }
table.grid th.col-tdp, table.grid td.col-tdp { width: 7%; }
table.grid th.col-price, table.grid td.col-price { width: 11%; }
table.grid th.col-pricePerGb, table.grid td.col-pricePerGb { width: 9%; }
table.grid th.col-availability, table.grid td.col-availability { width: 9%; }
table.grid tbody td.col-device { white-space: normal; }

/* the vendor's own name for a non-NVIDIA accelerator block */
table.grid .unit { font-size: 9.5px; color: var(--text-dim); letter-spacing: .02em; }

/* The name wraps in full — no line clamp and no ellipsis. A truncated model
   name ("NVIDIA Quadro RTX…") is useless when the whole point of the row is to
   identify the card. */
.device-name {
  font-weight: 650; white-space: normal; line-height: 1.25;
  overflow-wrap: anywhere;
}
/* The vendor/year line wraps too, for the same reason. */
.device-meta {
  display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 1px;
  white-space: normal; overflow-wrap: anywhere;
}

.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 5px; background: var(--surface-2);
  color: var(--text-dim); border: 1px solid var(--border); text-transform: uppercase;
}
.badge.cat { text-transform: none; }

.dim { color: var(--text-dim); }
.miss { color: var(--text-dim); opacity: .45; }
.good { color: var(--good); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }
.bad  { color: var(--bad); font-weight: 600; }

.tps { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tps sup { font-size: 9px; color: var(--text-dim); margin-inline-start: 2px; }

/* ---------- compare tray ---------- */
/* Pinned to the viewport bottom so a selection is always reachable, but it
   must never sit ON the table. A bottom bar overlays the page: it used to
   cover the last rows and the table's own scrollbar — and with them the
   checkboxes you need to undo a selection. layoutTray() in app.js measures the
   tray and caps the table box to the space left above it. */
.tray {
  position: fixed; bottom: 14px; z-index: 45;
  inset-inline: 18px; max-width: 1764px; margin-inline: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 11px 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
/* A class with `display: flex` beats the [hidden] attribute, which left an
   EMPTY bar covering the table on every page load before anything was picked. */
.tray[hidden] { display: none; }

/* Reserve the tray's footprint so it cannot hide the footer either. */
body.tray-open { padding-bottom: calc(var(--tray-h, 74px) + 30px); }
body.tray-open .table-shell { max-height: var(--shell-max, 74vh); }

/* On a cramped viewport (tall header, wrapped chips) there is no room for both
   a pinned bar AND a usable table. Rather than let the bar cover the table — the
   exact bug this replaced — it stops being pinned and sits below it in normal
   flow, where it cannot overlap anything. */
body.tray-inline { padding-bottom: 0; }
body.tray-inline .tray { position: static; margin-top: 14px; }
body.tray-inline .table-shell { max-height: 74vh; }

.tray .label { font-size: 13px; font-weight: 700; }
.tray-items { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }
.tray-item {
  font-size: 12.5px; background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px; padding: 3px 6px 3px 11px;
  display: inline-flex; align-items: center; gap: 7px; font-weight: 600;
}
/* The remove control measured 8x14px with zero padding — a miss far more often
   than a hit. Give it a real 22px box and a visible hover state. */
.tray-item button {
  border: 0; background: transparent; color: inherit; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0;
  width: 22px; height: 22px; min-width: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.tray-item button:hover, .tray-item button:focus-visible {
  background: color-mix(in srgb, currentColor 20%, transparent);
}

/* ---------- compare panel ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(8, 12, 18, .55);
  display: flex; align-items: flex-start; justify-content: center; padding: 34px 16px;
  overflow: auto;
}
.overlay[hidden] { display: none; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); width: min(1240px, 100%); padding: 20px 22px 24px;
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-head .x {
  margin-inline-start: auto; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px;
}

table.compare { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13.5px; }
table.compare th, table.compare td { padding: 8px 11px; border-bottom: 1px solid var(--border); text-align: start; }
table.compare thead th {
  position: sticky; top: 0; background: var(--surface-2); font-size: 13px;
  border-bottom: 2px solid var(--border);
}
table.compare tbody th {
  font-weight: 600; color: var(--text-dim); font-size: 12.5px;
  position: sticky; inset-inline-start: 0; background: var(--surface); white-space: nowrap;
}
table.compare td.win { background: var(--good-soft); color: var(--good); font-weight: 700; }
table.compare tr.section th {
  background: var(--surface-2); color: var(--text); font-weight: 700;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
}

/* ---------- detail drawer ---------- */
.detail dl { display: grid; grid-template-columns: 190px 1fr; gap: 6px 16px; margin: 0 0 16px; }
.detail dt { color: var(--text-dim); font-size: 13px; }
.detail dd { margin: 0; font-size: 13.5px; }
.detail h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-dim); margin: 20px 0 8px; }
.detail ul { margin: 0; padding-inline-start: 20px; font-size: 13px; }
.detail ul li { margin-bottom: 4px; }

/* ---------- footer ---------- */
footer.site {
  margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-dim);
}
footer.site .freshness { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; }
footer.site .disclaimer { max-width: 900px; line-height: 1.6; }

/* Author credit, set apart from the disclaimer above it: that block is a caveat
   about the data, this is authorship, and they should not read as one thing. */
footer.site .credit {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border);
}
footer.site .credit .heart { color: var(--bad); font-size: 13px; line-height: 1; }
footer.site .credit strong { color: var(--text); font-weight: 600; }
footer.site .credit a {
  color: var(--text-dim); text-decoration: none;
  border-bottom: 1px solid var(--border); padding-bottom: 1px;
}
footer.site .credit a:hover, footer.site .credit a:focus-visible {
  color: var(--accent); border-bottom-color: var(--accent);
}
footer.site .credit .sep { opacity: .45; }
footer.site .credit .year { font-variant-numeric: tabular-nums; }

.empty-state { padding: 46px 20px; text-align: center; color: var(--text-dim); }

/* ---------- responsive ---------- */

/* Two levers, in this order. First whole columns are dropped, because under
   table-layout:fixed a column that is too narrow never overflows — it truncates
   to an ellipsis — and a column reading "8,0…" is worse than no column at all.
   Second, the optional half of a cell's text is dropped, because "1,024 GB
   unified" and "950,000–1,100,000" are each half again as wide as the number
   they qualify, and the qualifier is the part that can be spared.
   Columns go roughly in reverse order of usefulness, so the five that answer
   "what is it, how much memory, what can it run, how fast, what does it cost"
   survive to a phone. Availability is dropped first among the defaults because
   it is also a filter in the toolbar above. */
@media (max-width: 1150px) {
  table.grid .tps-model, table.grid .mem-note { display: none; }
}
@media (max-width: 950px) {
  table.grid .p-range { display: none; }
}

@media (max-width: 1400px) {
  table.grid .col-availability,
  table.grid .col-msrp, table.grid .col-psu, table.grid .col-year { display: none; }
}
@media (max-width: 1150px) {
  table.grid .col-tdp, table.grid .col-pricePerGb,
  table.grid .col-category, table.grid .col-memType, table.grid .col-maxRam,
  table.grid .col-cpuCores, table.grid .col-bus, table.grid .col-maxModelQ8 { display: none; }
}
@media (max-width: 950px) {
  table.grid .col-bandwidth { display: none; }
  /* Fewer columns means the survivors can afford to be wider, and the device
     name is the one cell that is useless when squeezed. */
  table.grid th.col-device, table.grid td.col-device { width: 30%; }
}
@media (max-width: 760px) {
  table.grid .col-tensorCores { display: none; }
  table.grid th.col-device, table.grid td.col-device { width: 38%; }
}
@media (max-width: 560px) {
  table.grid { font-size: 11.5px; }
  table.grid .num { font-size: 11.5px; }
  table.grid thead th { padding: 5px 5px; }
  table.grid tbody td { padding: 4px 5px; }
  table.grid .col-tokens { display: none; }
  table.grid th.col-device, table.grid td.col-device { width: 44%; }
}
@media (max-width: 420px) {
  table.grid .col-maxModelQ4 { display: none; }
}

@media (max-width: 780px) {
  .site-inner { padding: 11px 14px; }
  .brand h1 { font-size: 16px; }
  .brand .mark { width: 22px; height: 22px; }
  .brand .sub { display: none; }
  .wrap { padding: 0 12px 48px; }
  .table-shell { max-height: none; }
  /* On a phone the table is full-height and the PAGE scrolls, so a bar pinned to
     the viewport bottom would cover the last rows and the footer. Keep the tray
     in normal flow below the table instead — then it cannot overlap anything. */
  .tray { position: static; inset-inline: auto; max-width: none; margin-top: 14px; }
  body.tray-open { padding-bottom: 0; }
  body.tray-open .table-shell, body.tray-inline .table-shell { max-height: none; }
  .controls input[type="search"] { flex-basis: 100%; max-width: none; }
  .detail dl { grid-template-columns: 1fr; gap: 0; }
  .detail dt { margin-top: 8px; font-weight: 600; }
}

@media print {
  header.site, .controls, .chip-row, .tray, .overlay { display: none !important; }
  .table-shell { max-height: none; overflow: visible; border: 0; box-shadow: none; }
}