:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #18202f;
  --ink-soft: #5b6578;
  --line: #e1e5ee;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --update: #d9480f;
  --update-bg: #fff1e8;
  --ok: #2b8a3e;
  --ok-bg: #ebf8ee;
  --stale: #a86400;
  --stale-bg: #fff7e0;
  --unknown: #6b7280;
  --unknown-bg: #f0f1f4;
  --danger: #c92a2a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131a;
    --surface: #171c25;
    --surface-2: #1d2330;
    --ink: #e6e9ef;
    --ink-soft: #9aa3b5;
    --line: #2a3242;
    --accent: #5b8ff9;
    --update: #ff8a4c;
    --update-bg: #3a2216;
    --ok: #63c97a;
    --ok-bg: #16301e;
    --stale: #f0b44c;
    --stale-bg: #33280f;
    --unknown: #9aa3b5;
    --unknown-bg: #232a37;
    --danger: #ff6b6b;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
.mono, code { font-family: "JetBrains Mono", ui-monospace, monospace; }
.muted { color: var(--ink-soft); }
.accent { color: var(--accent); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.brand svg { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger-ghost { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--ink-soft); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.req { color: var(--danger); }
.form-error { color: var(--danger); font-size: 14px; margin: 10px 0 0; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* Auth */
.auth-wrap {
  max-width: 1040px; margin: 0 auto; padding: 64px 24px;
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 56px; align-items: center;
}
.auth-intro h1 { font-size: clamp(30px, 4.5vw, 44px); line-height: 1.12; margin: 0 0 18px; letter-spacing: -.02em; }
.auth-intro p { color: var(--ink-soft); font-size: 17px; margin: 0 0 20px; }
.bullets { padding: 0; margin: 0; list-style: none; display: grid; gap: 10px; }
.bullets li { padding-left: 28px; position: relative; }
.bullets li::before { content: "✓"; position: absolute; left: 0; top: 0; color: var(--ok); font-weight: 700; }
.auth-card { padding: 24px; }
.auth-card form { display: grid; gap: 14px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; margin-bottom: 20px; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 7px; font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* App */
.app { max-width: 1180px; margin: 0 auto; padding: 24px; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); text-align: left; font: inherit; color: inherit; cursor: pointer;
}
.stat:hover { border-color: var(--accent); }
.stat.active { outline: 2px solid var(--accent); }
.stat .num { font-size: 30px; font-weight: 700; line-height: 1.1; display: block; }
.stat .lbl { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.stat.update .num { color: var(--update); }
.stat.stale .num { color: var(--stale); }
.stat.ok .num { color: var(--ok); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.filters input { max-width: 260px; }
.filters select { width: auto; }
.actions { display: flex; gap: 8px; }

.group { margin-bottom: 26px; }
.group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; }
.group h3 .count { font-weight: 500; text-transform: none; letter-spacing: 0; }

.device-table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.device-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-soft); padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.device-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.device-table tr:last-child td { border-bottom: 0; }
.device-table tbody tr:hover { background: var(--surface-2); }
.dev-cell { display: flex; align-items: center; gap: 12px; }
/* Model photo (lib/model_images.php). White tile so photos on white backgrounds look the same in dark mode. */
.dev-thumb { flex: none; width: 48px; height: 48px; border-radius: 8px; background: #fff; border: 1px solid var(--line); object-fit: contain; }
.dev-thumb.none { background: var(--surface-2); }
/* Model photo at the top of the add/edit dialog, shown once the manufacturer and model match a photo. */
.model-photo { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.model-photo[hidden] { display: none; }
.model-photo img { flex: none; width: 96px; height: 96px; border-radius: 10px; background: #fff; border: 1px solid var(--line); object-fit: contain; }
.dev-name { font-weight: 600; cursor: pointer; }
.dev-name:hover { color: var(--accent); }
.dev-sub { font-size: 13px; color: var(--ink-soft); }
.ver { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 13px; }
.ver.behind { color: var(--update); font-weight: 600; }
.ver.none { color: var(--ink-soft); font-family: inherit; font-style: italic; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.update { color: var(--update); background: var(--update-bg); }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.stale { color: var(--stale); background: var(--stale-bg); }
.badge.unknown { color: var(--unknown); background: var(--unknown-bg); }

.empty { text-align: center; padding: 56px 24px; }
.empty h2 { margin: 0 0 8px; }
.empty p { color: var(--ink-soft); margin: 0 0 20px; }

/* Dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(620px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 14, 22, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.dialog-head h2 { margin: 0; font-size: 19px; }
.dialog-foot { display: flex; gap: 8px; margin-top: 20px; }
.spacer { flex: 1; }
.check-match { margin: 10px 0; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; }
.check-match p { margin: 0 0 10px; }
.check-match-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.span2 { grid-column: 1 / -1; }
#checkForm label { margin-top: 6px; }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.history-list li:last-child { border-bottom: 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 500; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); z-index: 100;
}

/* Mobile */
@media (max-width: 820px) {
  .auth-wrap { grid-template-columns: 1fr; padding: 32px 16px; gap: 28px; }
  .app { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .user-email { display: none; }
  .summary { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .filters input { max-width: none; }
  .filters > * { flex: 1 1 140px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .grid2 { grid-template-columns: 1fr; }

  .device-table, .device-table tbody, .device-table tr, .device-table td { display: block; }
  .device-table thead { display: none; }
  .device-table tr { border-bottom: 1px solid var(--line); padding: 12px 14px; }
  .device-table tr:last-child { border-bottom: 0; }
  .device-table td { border: 0; padding: 3px 0; }
  .device-table td[data-label]::before { content: attr(data-label) ": "; color: var(--ink-soft); font-size: 13px; }
  .row-actions { justify-content: flex-start; margin-top: 8px; }
}
