/* YTUX-ESP flasher — branded to match the on-device theme (ui_core/theme.cpp dark
   palette). Framework-free, no web fonts / CDN, works from file://.
   Accent: #3a86e8 (YTUX-ESP blue). */
:root {
  --bg: #0b0e12;            /* page — matches the device splash */
  --panel: #161d26;         /* cards (device "surface") */
  --header: #05070a;        /* header + footer bars (device "bar") */
  --ink: #e9eef4;
  --muted: #9ab0c4;
  --faint: #5a6a78;
  --line: #24303d;
  --brand: #3a86e8;         /* YTUX-ESP accent (blue) */
  --brand-hover: #2f6fd0;
  --on-brand: #ffffff;
  --err: #e85a4a;
  --ok: #58c26a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; min-height: 100%;
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ── branded header ──────────────────────────────────────────────────────── */
.brand-header {
  flex: 0 0 56px;           /* lock height — never grow/shrink */
  box-sizing: border-box;
  display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--header); border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--ink); font-weight: 700; letter-spacing: 0.08em; font-size: 1.05rem;
}
.brand-mark { color: var(--brand); display: block; }
.brand:hover { color: var(--brand); }
.brand-sep { width: 1px; height: 24px; background: var(--line); }
.brand-sub {
  color: var(--muted); font-size: 0.95rem; letter-spacing: 0.02em;
  /* the tagline yields (ellipsis) before the right-side credit/socials do */
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* right side of the header: builder credit + social icons */
.brand-built { margin-left: auto; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.brand-built strong { color: var(--ink); font-weight: 600; }
.socials { display: inline-flex; align-items: center; gap: 12px; flex-shrink: 0; }
.socials a { display: inline-flex; color: var(--muted); }
.socials a:hover { color: var(--brand); }
.socials svg { display: block; }

/* ── layout ──────────────────────────────────────────────────────────────── */
/* #app (and the browser-gate) grow to fill the viewport so the footer stays pinned
   to the bottom even when content is short */
#app, #gate { flex: 1 0 auto; }
#app { display: flex; flex-direction: column; }
.page { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 20px; }

/* tabs — clean underline style; active tab marked by the brand accent */
.tabs {
  display: flex; gap: 24px; width: 100%; max-width: 860px; margin: 10px auto 0;
  padding: 0 20px; border-bottom: 1px solid var(--line);
}
.tab {
  padding: 10px 2px; cursor: pointer; font: inherit; font-size: 14px;
  color: var(--muted); background: transparent; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.tab:focus { outline: none; }
.tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 2px; }
.tabpanel { padding-top: 4px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 18px; margin: 10px 0;
}
.card h2 { margin: 0 0 10px; font-size: 17px; }
.card.warn { border-color: var(--brand); }
p { margin: 8px 0; color: var(--muted); }

/* ── "what you need" — one-line post-it note above step 1 ────────────────── */
.note {
  display: flex; gap: 8px; align-items: center; margin: 12px 0 2px;
  padding: 8px 14px; border-radius: 8px; font-size: 13px;
  background: rgba(250, 204, 21, 0.10); border: 1px solid rgba(250, 204, 21, 0.30);
  color: #e6d9a8;
}
.note strong { color: #f3e7bd; }
.note-icon { flex: 0 0 auto; }

/* ── device picker: trigger button + selected summary + modal popup ─────────
   The board list will grow, so the picker is a searchable/filterable popup
   rather than an always-open grid. */
.pick-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.pick-btn:hover { border-color: var(--brand); }
.pick-btn::after { content: "▾"; color: var(--muted); font-weight: 400; }
.pick-count { color: var(--faint); font-weight: 400; font-size: 13px; }

.selected {
  display: flex; gap: 12px; align-items: center; margin-top: 12px; padding: 10px 12px;
  border: 1px solid var(--brand); border-radius: 8px; background: rgba(58, 134, 232, 0.08);
}
/* `display: flex` above beats the UA's [hidden] rule — restate it, or the empty
   card shows as a bare outline before a device is picked */
.selected[hidden] { display: none; }
.sel-photo {
  flex: 0 0 auto; width: 72px; aspect-ratio: 4 / 3; object-fit: contain;
  border-radius: 6px; background: var(--bg);
}
.sel-body { min-width: 0; flex: 1; }
.sel-name { font-weight: 600; color: var(--ink); }
.sel-specs { color: var(--muted); font-size: 13px; }
.sel-fw:not(:empty) {
  font-size: 12px; color: var(--faint); margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
/* purchase / referral link + BSP component-page link — shown on each
   device; the two share one style, differing only in text */
.buy-link, .bsp-link { color: var(--brand); font-weight: 600; text-decoration: none; white-space: nowrap; }
.sel-buy, .sel-bsp { flex: 0 0 auto; padding: 6px 14px; border: 1px solid var(--brand); border-radius: 8px; }
.sel-buy:hover, .sel-bsp:hover { background: rgba(58, 134, 232, 0.12); }

.picker-modal {
  /* match the main UI column: .page is 860px minus its 2×20px padding */
  width: min(820px, 92vw); max-height: 82vh; padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ink);
}
.picker-modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.picker-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.picker-head h2 { margin: 0; font-size: 17px; }
.picker-x {
  background: transparent; border: 0; color: var(--muted);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 4px;
}
.picker-x:hover { color: var(--ink); }
.picker-search {
  display: block; width: calc(100% - 36px); margin: 14px 18px 8px; padding: 9px 12px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; font: inherit;
}
.picker-search:focus { outline: none; border-color: var(--brand); }
.picker-filters { padding: 0 18px 6px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-label {
  flex: 0 0 40px; font-size: 11px; color: var(--faint);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--brand); color: var(--ink); }
.chip.is-on { background: rgba(58, 134, 232, 0.15); border-color: var(--brand); color: var(--ink); }
.picker-list {
  /* FIXED height (not max-height): the list scrolls inside a constant-size box,
     so filtering never resizes the modal — a centered <dialog> would otherwise
     jump around as the row count changes. Short lists just show empty space. */
  overflow-y: auto; height: min(360px, 55vh); padding: 8px 18px 18px;
  display: flex; flex-direction: column; gap: 8px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  /* Reserve the scrollbar gutter so rows keep a constant width whether or not
     the list scrolls (it now scrolls past ~4 boards, see .picker-row below). */
  scrollbar-gutter: stable;
}
.picker-list::-webkit-scrollbar { width: 8px; }
.picker-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
/* Row split into two cells: the device (selects it) + a Buy link. */
.picker-row {
  display: flex; align-items: stretch; width: 100%; overflow: hidden;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
  /* Don't shrink: the list is a fixed-height flex COLUMN, and `overflow:hidden`
     collapses a row's auto min-height to 0 — so without this the rows compress
     to fit once there are enough boards to overflow (instead of scrolling),
     making item height depend on how many pass the filter. */
  flex-shrink: 0;
}
.picker-row:hover { border-color: var(--brand); }
.picker-row.is-selected { border-color: var(--brand); background: rgba(58, 134, 232, 0.10); }
.picker-pick {
  flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center;
  padding: 10px; text-align: left; background: transparent; border: 0;
  color: inherit; font: inherit; cursor: pointer;
}
.picker-pick:hover { background: rgba(58, 134, 232, 0.06); }
.picker-row .buy-link, .picker-row .bsp-link {
  flex: 0 0 auto; display: flex; align-items: center; padding: 0 18px;
  border-left: 1px solid var(--line);
}
.picker-row .buy-link:hover, .picker-row .bsp-link:hover { background: rgba(58, 134, 232, 0.12); }
.row-photo {
  flex: 0 0 auto; width: 60px; aspect-ratio: 4 / 3; object-fit: contain;
  border-radius: 6px; background: var(--panel);
}
.row-body { min-width: 0; }
.row-name { font-weight: 600; }
/* BETA pill next to a device name (kinds.js `beta: true`) — support maturing. */
.badge-beta {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em;
  color: #7a4d00; background: #ffd57e; border-radius: 999px;
  vertical-align: 2px;
}
.row-specs { color: var(--muted); font-size: 13px; }
.row-fw:not(:empty) {
  font-size: 12px; color: var(--faint); margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.picker-empty { color: var(--faint); padding: 24px; text-align: center; }


/* ── features — bullet list of firmware highlights ───────────────────────── */
.feature-list {
  margin: 0; padding-left: 20px;
  display: flex; flex-direction: column; gap: 8px;
  color: var(--muted);
}
.feature-list li::marker { color: var(--brand); }
.feature-list strong { color: var(--ink); }

/* ── controls ────────────────────────────────────────────────────────────── */
button.primary {
  background: var(--brand); color: var(--on-brand); border: 0; border-radius: 8px;
  padding: 10px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button.primary:hover { background: var(--brand-hover); }
button.primary:disabled { opacity: .5; cursor: default; }
button.danger {
  background: transparent; color: var(--err); border: 1px solid var(--err);
  border-radius: 8px; padding: 10px 16px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button.danger:hover { background: var(--err); color: #fff; }
button.danger:disabled { opacity: .5; cursor: default; }

.adv-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 6px; }
label { display: block; margin: 10px 0; color: var(--muted); }
.field-hint { margin: 8px 0 4px; font-size: 12px; color: var(--muted); }
.field-hint strong { color: var(--ink); font-weight: 600; }
input[type=text], input[type=password], select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
  font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--brand); }
.device-addr { color: var(--muted); } .device-addr .mono { color: var(--ink); }

/* ── timezone + city — two independent columns, side by side ─────────────────
   stacks to one column on narrow screens. Each column has its own Set button. */
.setup-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px 22px; align-items: start;
}
.setup-col { display: flex; flex-direction: column; }
.setup-col button.primary { align-self: start; margin-top: 2px; }
.setup-col .field-hint { margin-top: 6px; }
/* "optional" tag next to a section heading */
.badge {
  margin-left: 8px; padding: 2px 8px; border-radius: 999px; vertical-align: middle;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line);
}

/* ── progress ────────────────────────────────────────────────────────────── */
.bar { height: 8px; background: var(--bg); border-radius: 6px; margin: 14px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.bar-label { color: var(--muted); font-size: 13px; min-height: 18px; }

/* ── status + collapsible technical log ──────────────────────────────────── */
/* Set the status/log apart as their own feedback block within the Install card
   (a rule beats `.card h2`, so this overrides its tight default margins). */
#status {
  margin: 16px 0 10px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 16px;
}
#status.ok { color: var(--ok); } #status.err { color: var(--err); }
.log-wrap > summary { color: var(--muted); font-size: 13px; cursor: pointer; }
.log {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 10px; margin-top: 10px; max-height: 240px; overflow: auto; white-space: pre-wrap;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted);
}
/* hint while no output yet — disappears once logging starts (not :empty) */
.log:empty::before {
  content: "Detailed progress and any errors during install will appear here.";
  color: var(--faint); font-style: italic;
}

/* ── branded footer ──────────────────────────────────────────────────────── */
.brand-footer {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 8px 20px;
  background: var(--header); border-top: 1px solid var(--line);
  font-size: 0.85rem; color: var(--muted);
}
.brand-footer a { color: var(--muted); }
.brand-footer a:hover { color: var(--brand); }
.brand-footer .spacer { flex: 1; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }

/* ── license popup — the picker's frame, narrower, with scrolling text ───── */
.license-modal { width: min(680px, 92vw); }
.license-tldr {
  /* same sticky-note yellow as .note above */
  margin: 14px 18px 0; padding: 10px 14px; font-size: 0.9rem; border-radius: 8px;
  background: rgba(250, 204, 21, 0.10); border: 1px solid rgba(250, 204, 21, 0.30);
  color: #e6d9a8;
}
.license-tldr strong { color: #f3e7bd; }
.license-text {
  margin: 0; padding: 14px 18px 18px; overflow: auto; max-height: min(420px, 55vh);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem; white-space: pre-wrap; color: var(--muted);
}
