/* Fleet admin — light/dark theme, responsive from 320px phones to wide desktops. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --border: #e2e6ef;
  --text: #111827;
  --muted: #6b7280;
  --accent: #c2410c;           /* brand orange, dark enough for white text (AA) */
  --accent-hover: #9a3412;
  --accent-soft: #fff1e6;
  --on-accent: #ffffff;
  --ok: #059669;
  --ok-soft: #e7f8f1;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #131a26;
  --surface-2: #1a2333;
  --border: #263044;
  --text: #e6e9f0;
  --muted: #94a0b4;
  --accent: #fb923c;
  --accent-hover: #fdba74;
  --accent-soft: #3a2113;
  --on-accent: #0b0f17;
  --ok: #34d399;
  --ok-soft: #0f2a22;
  --warn: #fbbf24;
  --warn-soft: #2d2410;
  --danger: #f87171;
  --danger-soft: #2f1517;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 20px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .9em; }
h1 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem); line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
p { margin: 0 0 1rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: .5rem 1rem;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem 1.25rem;
  grid-template-areas: "brand tabs tools";
}
.brand { grid-area: brand; display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand img { display: block; }
.brand-logo { height: 36px; width: auto; }
.brand .brand-icon { display: none; width: 38px; height: 38px; }
.brand-app { color: var(--muted); font-weight: 600; font-size: .95rem; padding-left: .7rem; border-left: 1px solid var(--border); }
.theme-dark-only { display: none !important; }
[data-theme="dark"] .theme-dark-only { display: block !important; }
[data-theme="dark"] .theme-light-only { display: none !important; }
.tabs { grid-area: tabs; display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs svg { width: 18px; height: 18px; flex-shrink: 0; }
.tabs a {
  white-space: nowrap; color: var(--muted); padding: .5rem .8rem; border-radius: 999px; font-weight: 550;
  display: inline-flex; align-items: center; gap: .4rem; min-height: 40px;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.tabs .count { background: var(--accent); color: var(--on-accent); border-radius: 999px; font-size: .72rem; padding: 0 .45rem; line-height: 1.4; }
.tools { grid-area: tools; display: flex; align-items: center; gap: .4rem; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-width: 40px; height: 40px; padding: 0 .6rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; list-style: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.theme-light { display: none; }
[data-theme="dark"] .theme-light { display: inline; }
[data-theme="dark"] .theme-dark { display: none; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 3px; background: var(--surface); }
.segmented button {
  border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700;
  height: 32px; min-width: 38px; padding: 0 .6rem; border-radius: 999px; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* User menu */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #f97316, #c2410c); color: #fff; font-weight: 700; cursor: pointer; text-transform: uppercase;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .4rem;
}
.menu-panel .who { padding: .5rem .7rem; color: var(--muted); font-size: .85rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.menu-panel a, .menu-panel button {
  display: flex; width: 100%; align-items: center; gap: .55rem; padding: .6rem .7rem; border-radius: 8px;
  color: var(--text); background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-2); text-decoration: none; }
.menu-panel svg { width: 17px; height: 17px; color: var(--muted); }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.narrow { max-width: 720px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head p { color: var(--muted); margin: 0; }
.stack > * + * { margin-top: 1.25rem; }
.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .grid-2 { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); align-items: start; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card > :last-child { margin-bottom: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 1.1rem 1.25rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Auth (login, reauthenticate, 2FA) */
.auth { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .auth-logo { display: flex; justify-content: center; margin-bottom: 1rem; }
.auth-card .auth-logo { margin-bottom: 1.5rem; }
.auth-card .auth-logo img { height: 64px; width: auto; max-width: 100%; }
.auth-card h1 { text-align: center; margin-bottom: 1rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 40px; padding: .5rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; line-height: 1.2; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.95); background: var(--ok); }
[data-theme="dark"] .btn-ok { color: #0b0f17; }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.actions form { margin: 0; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field .help { display: block; color: var(--muted); font-size: .82rem; margin-top: .35rem; }
.field .help ul { margin: .25rem 0 0; padding-left: 1.1rem; }
input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="file"], textarea, select {
  width: 100%; min-height: 44px; padding: .6rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea { resize: vertical; }
textarea[readonly] { font-family: var(--mono); background: var(--surface-2); letter-spacing: .05em; }
input[type="file"] { padding: .45rem; }
input[type="file"]::file-selector-button {
  border: 0; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font: inherit; font-weight: 600;
  padding: .45rem .8rem; margin-right: .75rem; cursor: pointer;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.check { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.errorlist { list-style: none; margin: 0 0 .5rem; padding: 0; color: var(--danger); font-size: .88rem; font-weight: 500; }
.search { display: flex; gap: .5rem; }
.search input { flex: 1; min-width: 0; }

/* ---------- Alerts / badges ---------- */
.messages { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: .5rem; }
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); }
.alert.success { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert.warning, .alert.info { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .6rem; border-radius: 999px;
  font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tables (become cards on small screens) ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 650; padding: .75rem 1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.table td.wrap, .table td .wrap { white-space: normal; min-width: 12rem; overflow-wrap: anywhere; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table .actions { justify-content: flex-end; flex-wrap: nowrap; }
.table tr.dim { opacity: .55; }
.hash { font-family: var(--mono); font-size: .82rem; color: var(--muted); }

@media (max-width: 900px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: .25rem 0; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; text-align: right; white-space: normal; }
  .table td.wrap { min-width: 0; overflow-wrap: anywhere; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; flex-shrink: 0; }
  .table td[data-label=""]::before, .table td:not([data-label])::before { content: none; }
  .table td.primary { display: block; font-size: 1rem; font-weight: 650; text-align: left; padding-bottom: .4rem; }
  .table td.primary .muted { font-weight: 400; margin-top: .15rem; }
  .table td.primary::before { content: none; }
  .table .actions { justify-content: stretch; padding-top: .6rem; }
  .table .actions > * { flex: 1; }
  .table .actions .btn { width: 100%; }
}

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: .5rem; }

.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: 1rem; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .5rem 1rem; margin: 0; font-size: .9rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; }

/* Auth card: full-width buttons */
.auth-card .actions .btn { width: 100%; }

/* ---------- Phones ---------- */
@media (max-width: 860px) {
  .topbar-inner { grid-template-columns: 1fr auto; grid-template-areas: "brand tools" "tabs tabs"; padding-bottom: .35rem; }
  .tabs { margin: 0 -1rem; padding: 0 1rem .15rem; }
}
@media (max-width: 640px) {
  /* backdrop-filter would turn the header into the containing block of the fixed tab bar */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
  .topbar-inner { grid-template-areas: "brand tools"; padding-bottom: .5rem; }
  .brand .brand-logo, .brand-app { display: none !important; }
  .brand .brand-icon { display: block; }
  /* App-style bottom tab bar */
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; margin: 0;
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 0;
    padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px);
    border-top: 1px solid var(--border);
  }
  .tabs a { flex-direction: column; gap: .15rem; padding: .35rem .2rem; border-radius: 12px; font-size: .7rem; min-height: 52px; justify-content: center; white-space: normal; text-align: center; line-height: 1.15; }
  .tabs svg { width: 22px; height: 22px; }
  body.has-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  .container { padding: 1rem .75rem 2.5rem; }
  .card { padding: 1rem; border-radius: 12px; }
  .card.flush .card-head { padding: 1rem 1rem 0; }
  .page-head .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Firmware products */
.product-list { display: grid; }
.product-row {
  display: flex; align-items: center; gap: .9rem; padding: .9rem 1.25rem; color: var(--text);
  border-top: 1px solid var(--border);
}
.product-row:first-child { margin-top: .9rem; }
.product-row:hover { background: var(--surface-2); text-decoration: none; }
.product-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.product-icon svg { width: 20px; height: 20px; }
.product-main { display: grid; flex: 1; min-width: 0; }
.chev { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.chips { display: inline-flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; }
.chip { font-family: var(--mono); font-size: .78rem; padding: .1rem .5rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.pills { display: flex; flex-wrap: wrap; gap: .35rem; }
.pills a { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: .85rem; font-weight: 600; }
.pills a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.pills a[aria-current="page"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* Campaign progress: installed (green) and failed (red) share of the devices. */
.progress { display: flex; height: 6px; min-width: 120px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .35rem; }
.progress .ok { background: var(--ok); }
.progress .fail { background: var(--danger); }
.device-pick { display: grid; gap: .1rem; margin-bottom: 1rem; }
.device-pick .check { margin: 0; padding: .45rem .25rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.device-pick .check:last-child { border-bottom: 0; }
.segmented-choice { display: flex; flex-wrap: wrap; gap: 1.25rem; }
.segmented-choice .check { margin: 0; }
[hidden] { display: none !important; }
.filters { align-items: flex-start; }
.filters .search { flex: 1; max-width: 560px; }
.filters .search select { width: auto; max-width: 12rem; }
.bulk { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .25rem 0 .5rem; }
.bulk .check { margin: 0; }
.bulk select { width: auto; }
a.chip:hover { text-decoration: none; background: var(--accent-soft); color: var(--accent); }
.role-badge { font-size: .72rem; font-weight: 650; letter-spacing: .02em; padding: .2rem .55rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.role-badge.role-superuser { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.role-badge.role-admin { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.check-list ul { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.check-list label { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
