/* Clean Air CRM theme - taken from the logo: deep navy, bright sky blue, grey ring. */
:root {
  --navy-950: #04133a;
  --navy-900: #071d55;
  --navy-800: #0a2a7a;
  --navy: #002a8c;
  --blue: #1452b8;
  --sky: #0a8fe0;
  --sky-300: #4cb7f2;
  --sky-100: #e3f3fd;
  --ring: #7d8288;
  --ring-300: #b9bdc2;
  --ring-100: #eef0f2;

  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #0f1b33;
  --muted: #5d6879;
  --border: #dde3ec;

  --ok: #11875d;   --ok-bg: #e3f6ee;
  --warn: #b46a00; --warn-bg: #fff3dc;
  --bad: #c62f3c;  --bad-bg: #fde8ea;
  --info: var(--blue); --info-bg: #e6eefc;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(7, 29, 85, .06), 0 4px 16px rgba(7, 29, 85, .06);
  --grad: linear-gradient(135deg, var(--navy) 0%, var(--blue) 55%, var(--sky) 100%);
  font-family: Ubuntu, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); font-size: 14px; line-height: 1.45; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; color: var(--navy-900); }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--navy-900) 0%, var(--navy-950) 100%);
  color: #cfe0ff; padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 42px; height: 42px; background: #fff; border-radius: 50%; padding: 4px; }
.brand b { display: block; color: #fff; font-size: 17px; letter-spacing: .2px; }
.brand span { font-size: 11px; color: var(--sky-300); text-transform: uppercase; letter-spacing: 1.2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: #c4d4f3; font-weight: 500; text-decoration: none;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: linear-gradient(90deg, rgba(10,143,224,.28), rgba(10,143,224,.06)); color: #fff; box-shadow: inset 3px 0 0 var(--sky); }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.nav .count.zero { display: none; }
.sidebar .foot { margin-top: auto; font-size: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar .foot a { color: var(--sky-300); }
.sidebar .ring-line { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--ring), var(--ring-300), var(--ring)); opacity: .55; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .title { flex: 1; min-width: 0; }
.topbar .title .muted { font-size: 12px; }
.sync-box { display: flex; align-items: center; gap: 12px; }
.sync-meta { text-align: right; font-size: 12px; color: var(--muted); line-height: 1.3; }
.sync-meta b { color: var(--text); font-weight: 600; }
.user-chip { display: flex; align-items: center; gap: 8px; padding-left: 14px; border-left: 1px solid var(--border); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; }
.btn.mobile-bar { display: none; }

/* top-bar device finder */
.find { position: relative; width: min(300px, 32vw); }
.find svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); }
.find input { padding-left: 32px; background: var(--surface-2); }
mark { background: #ffe58a; color: inherit; border-radius: 3px; padding: 0 1px; }
.where { display: flex; align-items: stretch; gap: 6px; flex-wrap: wrap; background: var(--sky-100); border-radius: 10px; padding: 10px 12px; }
.where-step { display: flex; flex-direction: column; min-width: 0; }
.where-step span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; }
.where-step b { color: var(--navy-900); overflow-wrap: anywhere; }
.where-arrow { align-self: center; color: var(--sky); font-size: 20px; font-weight: 700; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 9px; padding: 7px 13px; font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { border-color: var(--ring-300); background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--navy); }
.btn.sync {
  background: var(--grad); border: 0; color: #fff; padding: 10px 20px; font-size: 15px; border-radius: 11px;
  box-shadow: 0 6px 18px rgba(10,143,224,.35);
}
.btn.sync:hover { filter: brightness(1.07); }
.btn.sync.spinning svg { animation: spin 1s linear infinite; }
.btn.start { background: var(--sky); border-color: var(--sky); color: #fff; }
.btn.start:hover { background: #0679c0; }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sky-300); outline-offset: 0; border-color: var(--sky); }
textarea { min-height: 84px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 12px; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 160px; }
.filters .grow { flex: 1; min-width: 200px; }

/* ---------- cards / KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h2 { flex: 1; }
.card-b { padding: 16px 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; right: -30px; bottom: -30px; width: 78px; height: 78px; border-radius: 50%; border: 8px solid var(--ring-100); }
.kpi > * { position: relative; z-index: 1; }
.kpi .v { font-size: 28px; font-weight: 700; color: var(--navy-900); line-height: 1.1; margin-top: 4px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.bad .v { color: var(--bad); }
.kpi.warn .v { color: var(--warn); }
.kpi.ok .v { color: var(--ok); }
.kpi.sky .v { color: var(--sky); }
.grid-2 { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; }

/* ---------- tables (worksheet look) ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); background: var(--surface-2); font-weight: 700; position: sticky; top: 0; }
tbody tr:hover { background: #f5f9ff; }
tr.clickable { cursor: pointer; }
.sheet th, .sheet td { border-right: 1px solid var(--border); }
.sheet th:first-child, .sheet td:first-child { border-left: 0; }
.sheet td { background: var(--surface); }
.sheet .col-device { min-width: 170px; }
.sheet .col-problem { min-width: 220px; }
.sheet tr.row-in_repair td { background: #eef7fe; }
.sheet tr.row-waiting_parts td { background: #fff9ec; }
.sheet tr.row-repaired td, .sheet tr.row-closed td { color: var(--muted); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-online, .b-repaired, .b-ok, .b-low { color: var(--ok); background: var(--ok-bg); }
.b-offline, .b-high, .b-error { color: var(--bad); background: var(--bad-bg); }
.b-warning, .b-medium, .b-waiting_parts { color: var(--warn); background: var(--warn-bg); }
.b-in_repair { color: #fff; background: var(--sky); }
.b-open { color: var(--blue); background: var(--info-bg); }
.b-closed, .b-unknown, .b-resolved, .b-paused { color: var(--ring); background: var(--ring-100); }
.b-admin { color: var(--navy); background: var(--info-bg); }
.b-technician { color: var(--ring); background: var(--ring-100); }

/* ---------- dashboard: live status ---------- */
.live-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.live-kpis a.card { text-decoration: none !important; color: inherit; transition: transform .1s, box-shadow .1s; }
.live-kpis a.card:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(7,29,85,.12); }
.kpi.muted-kpi .v { color: #7d8288; }
.live-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--ring-100); }
.live-bar i { display: block; height: 100%; }
a.num { display: inline-block; min-width: 34px; text-align: center; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-decoration: none !important; }
a.num.ok { background: #e5f5e5; color: #2f8a2f; }
a.num.grey { background: var(--ring-100); color: #5f656c; }
a.num.blue { background: #e3edf8; color: #2a659c; }
a.num.bad { background: #fbe6e6; color: #c23b3b; }
a.num.zero { color: var(--muted); }

/* ---------- dashboard: clients and their problems ---------- */
.client-issues { border-bottom: 1px solid var(--border); }
.client-issues:last-child { border-bottom: 0; }
.client-issues summary { display: flex; align-items: center; gap: 12px; padding: 13px 18px; cursor: pointer; list-style: none; flex-wrap: wrap; }
.client-issues summary::-webkit-details-marker { display: none; }
.client-issues summary::before { content: "▸"; color: var(--sky); font-size: 14px; transition: transform .15s; }
.client-issues[open] summary::before { transform: rotate(90deg); }
.client-issues[open] summary { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.client-issues .cname { min-width: 170px; color: var(--navy-900); font-size: 15px; }
.client-issues .chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--ring-100); color: var(--muted); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.sky { background: var(--sky-100); color: var(--blue); }
.ci-foot { padding: 8px 18px 12px; font-size: 13px; }

/* ---------- client page (portal-style device cards) ---------- */
.client-banner { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 18px 22px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--navy-900), #2d3f6b); color: #d7e3fb; }
.client-banner h2 { color: #fff; font-size: 22px; }
.client-banner b { color: #fff; }
.client-banner .headline { margin-top: 6px; font-size: 15px; color: #e3ecff; }
.room-row td { background: var(--sky-100); font-weight: 700; color: var(--navy-900); }
tr.has-issue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.client-issues .cname small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); }
.client-banner > div:first-child { flex: 1; min-width: 200px; }
.banner-stats { display: flex; gap: 22px; }
.banner-stats div { text-align: center; }
.banner-stats b { display: block; font-size: 24px; color: #fff; }
.banner-stats span { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #a9bde6; }
.state-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; background: var(--surface);
  border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 13px; text-decoration: none !important; }
.legend-chip i { width: 12px; height: 12px; border-radius: 3px; }
.legend-chip b { color: var(--navy-900); }
.legend-chip.on { border-color: var(--blue); box-shadow: 0 0 0 2px var(--sky-100); }
.seg { display: inline-flex; gap: 4px; }
.dev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.dev-card { background: color-mix(in srgb, var(--st) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--st) 35%, var(--border));
  border-top: 6px solid var(--st); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.dev-card:hover { box-shadow: var(--shadow); }
.dev-head { display: flex; gap: 8px; align-items: flex-start; }
.dev-head h3 { flex: 1; font-size: 15px; word-break: break-word; }
.state-pill { display: inline-block; white-space: nowrap; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 99px;
  color: #fff; background: var(--st); }
.dev-kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.dev-kv dt { color: var(--muted); }
.dev-kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.lamp { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 5px; background: var(--ring-100); color: var(--ring); }
.lamp.on { background: var(--blue); color: #fff; }
.dev-problem { font-size: 12.5px; font-weight: 600; color: #8a4b00; background: var(--warn-bg); border-radius: 8px; padding: 7px 9px; }
.dev-actions { display: flex; justify-content: flex-end; }

/* ---------- schedules ---------- */
.day-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.day-pick { flex-direction: row; align-items: center; gap: 5px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13px; cursor: pointer; background: var(--surface); }
.day-pick input { width: auto; }
.day-pick:has(input:checked) { background: var(--sky-100); border-color: var(--sky); color: var(--navy-900); }
tr.muted td { opacity: .6; }

/* ---------- client portal ---------- */
.client-top { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: linear-gradient(90deg, var(--navy-900), var(--navy-950)); color: #cfe0ff; }
.client-top .brand { border: 0; padding: 0; flex: 1; }
.client-top-right { display: flex; align-items: center; gap: 10px; }
.client-top-right .btn { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.18); }
.client-main { max-width: 1280px; margin: 0 auto; width: 100%; }
.client-issue { display: flex; gap: 12px; align-items: flex-start; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.client-issue:last-child { border-bottom: 0; }
@media (max-width: 820px) { .client-top { padding: 10px 14px; flex-wrap: wrap; } #lastSync { display: none; } }

/* ---------- client cards ---------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.client { padding: 16px; display: flex; flex-direction: column; gap: 12px; border-top: 4px solid var(--sky); }
.client.has-high { border-top-color: var(--bad); }
.client.sync-error { border-top-color: var(--warn); }
.client .row { display: flex; align-items: center; gap: 8px; }
.client .row h3 { flex: 1; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-row div { background: var(--surface-2); border-radius: 8px; padding: 6px 2px; }
.stat-row b { display: block; font-size: 18px; color: var(--navy-900); }
.stat-row span { font-size: 11px; color: var(--muted); }
.bar { height: 6px; border-radius: 6px; background: var(--ring-100); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(4, 19, 58, .45); z-index: 50; display: flex; justify-content: flex-end; }
.overlay.center { justify-content: center; align-items: center; padding: 16px; }
.drawer { width: min(560px, 100%); height: 100%; background: var(--surface); overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.2); }
.modal { width: min(520px, 100%); max-height: 92vh; overflow-y: auto; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.drawer-h, .modal-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.drawer-h h2, .modal-h h2 { flex: 1; }
.drawer-b, .modal-b { padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.readings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.readings div { background: var(--surface-2); border-radius: 9px; padding: 9px 11px; }
.readings b { display: block; font-size: 17px; color: var(--navy-900); }
.readings span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { padding-left: 16px; border-left: 2px solid var(--sky-100); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--sky); }
.steps { display: flex; gap: 4px; }
.steps span { flex: 1; text-align: center; font-size: 11px; font-weight: 600; padding: 6px 2px; border-radius: 6px; background: var(--ring-100); color: var(--ring); }
.steps span.done { background: var(--sky-100); color: var(--blue); }
.steps span.now { background: var(--sky); color: #fff; }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--navy-900); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; border-left: 4px solid var(--sky); }
.toast.err { border-left-color: var(--bad); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.login-art {
  background: radial-gradient(circle at 30% 20%, rgba(76,183,242,.35), transparent 50%), linear-gradient(160deg, var(--navy-900), var(--navy-950));
  color: #d7e6ff; display: flex; flex-direction: column; justify-content: center; padding: 56px; gap: 22px; position: relative; overflow: hidden;
}
.login-art::after { content: ""; position: absolute; width: 520px; height: 520px; right: -180px; bottom: -200px; border-radius: 50%; border: 40px solid rgba(125,130,136,.25); }
.login-art img { width: 120px; background: #fff; border-radius: 50%; padding: 12px; }
.login-art h1 { color: #fff; font-size: 34px; }
.login-art p { max-width: 420px; font-size: 15px; color: #b9cdf2; margin: 0; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.login-form form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; }
.login-form .logo-full { width: 150px; margin: 0 auto 6px; }
.login-form input { padding: 11px 13px; }
.login-form .btn { padding: 11px; font-size: 15px; }
.error-box { background: var(--bad-bg); color: var(--bad); padding: 10px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .grid-2 { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-art { display: none; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .btn.mobile-bar { display: inline-flex; }
  .topbar h1 { font-size: 18px; }
  #pageSub, .avatar { display: none; }
  .find { order: 5; width: 100%; }
  .topbar { padding: 10px 16px; flex-wrap: wrap; gap: 10px; }
  .user-chip .name, .sync-meta { display: none; }
  .content { padding: 16px 16px 40px; }
  .form-grid { grid-template-columns: 1fr; }
  .client-issues summary { gap: 6px 10px; padding: 12px 14px; }
  .client-issues .cname { min-width: 0; flex: 1; }
  .client-issues .chips { flex: 1 1 100%; order: 3; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .banner-stats { gap: 14px; width: 100%; justify-content: space-between; }
  .readings { grid-template-columns: repeat(2, 1fr); }
  .filters input, .filters select { min-width: 0; flex: 1 1 140px; }
  .btn.sync { padding: 9px 14px; font-size: 14px; }
}


/* ---------- air quality cards (sensor dashboard style) ---------- */
.air-summary { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.air-summary b { color: var(--bad); }
.air-wrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.air-card { background: linear-gradient(165deg, #1b2a4a, #0d1a36); color: #e9f0ff; border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 6px 22px rgba(7,29,85,.18); display: flex; flex-direction: column; gap: 10px; }
.air-card.offline { filter: grayscale(.85); opacity: .8; }
.air-head { display: flex; flex-direction: column; }
.air-head b { font-size: 15px; letter-spacing: .3px; }
.air-head span { font-size: 12px; color: #9fb3d9; }
.air-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.air-th { display: flex; align-items: baseline; gap: 3px; }
.air-th b { font-size: 24px; font-weight: 500; }
.air-th span { font-size: 13px; color: #9fb3d9; }
.air-th.right { justify-content: flex-end; }
.air-gauge { width: 132px; height: 132px; }
.air-gauge .g-label { fill: #e9f0ff; font-size: 11px; font-weight: 700; letter-spacing: .5px; }
.air-gauge .g-value { font-size: 40px; font-weight: 500; }
.air-gauge .g-unit { fill: #9fb3d9; font-size: 10px; }
.air-band { text-align: center; font-weight: 700; letter-spacing: 1px; color: #0b1430; padding: 7px; border-radius: 6px; font-size: 14px; }
.air-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; }
.air-grid.two { grid-template-columns: repeat(2, 1fr); }
.air-tile { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 1px; }
.air-tile .t-label { font-size: 13px; color: #c9d6f2; }
.air-tile b { font-size: 18px; font-weight: 500; }
.air-tile .t-unit { font-size: 10.5px; color: #9fb3d9; }
.air-tile .t-bar { display: block; width: 86%; height: 5px; border-radius: 3px; margin-top: 4px; }
.air-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: #9fb3d9; border-top: 1px solid rgba(255,255,255,.1); padding-top: 8px; }
@media (max-width: 820px) { .air-wrap { grid-template-columns: 1fr; } }

/* =====================================================================
   Phone layout: looks and behaves like an app (bottom tabs, cards, sheets)
   ===================================================================== */
.tabbar, .login-hero, .backdrop, .side-logout { display: none; }

@media (max-width: 820px) {
  html { -webkit-text-size-adjust: 100%; }
  body { background: var(--bg); overscroll-behavior-y: none; }
  input, select, textarea { font-size: 16px; }            /* stops iOS zooming into fields */
  .btn { min-height: 38px; }
  .btn.sm { min-height: 32px; }

  /* app header */
  .topbar { position: sticky; top: 0; padding: calc(8px + env(safe-area-inset-top)) 14px 10px; gap: 8px;
    background: linear-gradient(180deg, var(--navy-900), var(--navy-800)); border-bottom: 0; color: #fff; }
  .topbar h1 { color: #fff; font-size: 19px; }
  .btn.mobile-bar, .user-chip, .sync-meta { display: none !important; }
  .topbar .title { order: 1; flex: 1; }
  .sync-box { order: 2; }
  .btn.sync { padding: 8px 14px; font-size: 14px; box-shadow: none; background: rgba(255,255,255,.14); }
  .find { order: 3; width: 100%; }
  .find input { background: rgba(255,255,255,.95); border-color: transparent; }

  /* bottom tab bar */
  body:has(.tabbar) .content { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: var(--surface);
    border-top: 1px solid var(--border); box-shadow: 0 -4px 18px rgba(7,29,85,.08); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0; position: relative;
    font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none !important; }
  .tabbar a svg { width: 23px; height: 23px; }
  .tabbar a.active { color: var(--blue); }
  .tabbar a.active svg { stroke: var(--sky); }
  .tab-count { position: absolute; top: 0; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 99px;
    font-size: 10px; line-height: 16px; min-width: 16px; padding: 0 4px; text-align: center; }
  .sidebar { z-index: 80; width: 270px; padding-top: calc(18px + env(safe-area-inset-top)); }
  .backdrop.show { display: block; position: fixed; inset: 0; z-index: 75; background: rgba(4,19,58,.45); }
  .side-logout { display: inline-flex; background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.2); }
  .toasts { bottom: calc(82px + env(safe-area-inset-bottom)); left: 16px; right: 16px; max-width: none; }

  /* content */
  .content { padding: 14px 14px 32px; gap: 14px; }
  .card { border-radius: 14px; }
  .kpi { padding: 12px 14px; }
  .kpi .v { font-size: 24px; }
  .filters { gap: 8px; }
  .filters .btn { flex: 1 1 auto; }
  .card-h { flex-wrap: wrap; }
  .card-h h2 { flex: 1 1 100%; }

  /* tables become cards */
  .table-wrap { overflow: visible; }
  .card:has(> .table-wrap > table.cardable) { background: transparent; border: 0; box-shadow: none; }
  table.cardable, table.cardable tbody, table.cardable tr, table.cardable td { display: block; width: 100%; }
  table.cardable thead { display: none; }
  table.cardable tr { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; margin: 0 0 10px; padding: 10px 14px; box-shadow: var(--shadow); }
  table.cardable tr.has-issue { border-left: 4px solid var(--bad); }
  table.cardable tr.has-issue td:first-child { box-shadow: none; }
  table.cardable td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0;
    border: 0 !important; background: transparent !important; text-align: right; min-height: 0; }
  table.cardable td::before { content: attr(data-label); font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .4px; color: var(--muted); text-align: left; flex: none; max-width: 45%; }
  table.cardable td:not([data-label])::before, table.cardable td[data-label=""]::before { content: none; }
  table.cardable td.card-title { order: -1; display: block; text-align: left; font-size: 15px; padding-bottom: 6px;
    margin-bottom: 4px; border-bottom: 1px solid var(--border) !important; }
  table.cardable td.card-title::before { content: none; }
  table.cardable td:empty { display: none; }
  table.cardable tr.group-row { background: transparent; border: 0; box-shadow: none; padding: 8px 2px 2px; margin: 4px 0 6px; }
  table.cardable tr.group-row td { display: block; text-align: left; border: 0 !important; padding: 0; margin: 0; font-size: 14px; }
  .sheet tr.row-in_repair, .sheet tr.row-waiting_parts { background: var(--surface); }
  .col-device, .col-problem { min-width: 0 !important; }

  /* drawers full screen, dialogs as bottom sheets */
  .drawer { width: 100%; }
  .drawer-h { padding-top: calc(14px + env(safe-area-inset-top)); }
  .overlay.center { align-items: flex-end; padding: 0; }
  .overlay.center .modal { width: 100%; max-height: 90vh; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .modal-f .btn { flex: 1; }

  /* login: app-style welcome screen */
  .login-page { display: flex; flex-direction: column; min-height: 100vh; background: linear-gradient(170deg, var(--navy-900), var(--navy-950)); }
  .login-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: calc(48px + env(safe-area-inset-top)) 24px 36px; color: #fff; }
  .login-hero img { width: 92px; height: 92px; background: #fff; border-radius: 50%; padding: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
  .login-hero b { font-size: 26px; letter-spacing: .3px; }
  .login-form { flex: 1; align-items: center; justify-content: flex-start; flex-direction: column; background: var(--surface); border-radius: 26px 26px 0 0; padding: 28px 22px calc(28px + env(safe-area-inset-bottom)); }
  .login-form .logo-full { display: none; }
  .login-form .btn { padding: 14px; border-radius: 12px; }
  .login-form input { padding: 13px 14px; border-radius: 12px; }

  /* client portal header */
  .client-top { position: sticky; top: 0; z-index: 30; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; }
  .client-top .brand img { width: 34px; height: 34px; }
}

/* installed as an app: no browser chrome, so keep content clear of the notch */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; }
  input, textarea { -webkit-user-select: text; user-select: text; }
}
