@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --color-primary:    #020617;
  --color-secondary:  #0F172A;
  --color-text:       #334155;
  --color-muted:      #64748B;
  --color-accent:     #0091D2;
  --color-accent-alt: #0C6ECF;
  --color-border:     #E1E3EA;
  --color-panel:      #E2E8F0;
  --color-bg-tint:    #F8FAFC;
  --color-white:      #FFFFFF;
  --color-info:       #0091D2;
  --color-warning:    #F59E0B;
  --color-error:      #DC2626;
  --font-heading: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body:    'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg-tint);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3 { font-family: var(--font-heading); color: var(--color-secondary); margin: 0; font-weight: 600; }
a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-alt); }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--color-secondary);
  color: var(--color-white);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar nav { flex: 0 0 auto; }
.sidebar-hero {
  margin-top: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  /* No forced flex-stretch and no white background: the container hugs
     the image's natural aspect ratio so there are no white letterbox
     bars above/below the poster. On very short screens the hero is
     hidden entirely (see the display:none media query below), so we
     don't need flex-shrink to keep it from overflowing. */
  flex: 0 0 auto;
  align-self: stretch;
}
.sidebar-hero img {
  display: block;
  width: 100%;
  height: auto;            /* natural ratio → fills width edge-to-edge, no letterbox */
}
/* Short-screen / low-resolution adjustments: shrink the brand + nav so
   the hero image always has room. Anything under ~720 px tall benefits. */
@media (max-height: 800px) {
  .sidebar { padding: 16px 14px; }
  .sidebar .brand { margin-bottom: 16px; }
  .sidebar-hero { margin-top: 10px; }
  .main { padding: 16px 24px; padding-bottom: 80px; }
}
@media (max-height: 640px) {
  .sidebar { padding: 12px 12px; }
  .sidebar .brand { margin-bottom: 8px; }
  .sidebar nav.sidenav-compact a,
  .sidebar nav.sidenav-compact .sidenav-group > summary {
    padding: 5px 12px !important;
    font-size: 12px !important;
  }
  .sidebar-hero { margin-top: 6px; }
}
.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  padding: 8px;
}
.sidebar .brand img { height: 28px; }
.sidebar .brand .product {
  font-family: var(--font-heading);
  color: var(--color-white);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.sidebar nav a {
  display: block;
  padding: 10px 12px;
  color: #cbd5e1;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-weight: 500;
  font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: rgba(0, 145, 210, 0.18); color: #fff; }

.main { padding: 24px 32px; max-width: 1400px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0 20px;
}
.topbar h2 { font-size: 22px; }
.user-menu { display: flex; align-items: center; gap: 12px; }
.user-menu .who { color: var(--color-muted); font-size: 13px; }
.user-menu .role-pill {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--color-bg-tint);
  border: 1px solid var(--color-border);
  border-radius: 9999px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn {
  padding: 8px 16px;
  border: none;
  background: var(--color-accent);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-family: inherit;
  font-size: 13px;
}
.btn:hover { background: var(--color-accent-alt); }
.btn.secondary {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}
.btn.secondary:hover { background: var(--color-bg-tint); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  margin-bottom: 10px;
  font-weight: 600;
}
.card .value {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  color: var(--color-secondary);
  line-height: 1.15;
}
.card .value.accent { color: var(--color-accent); }
.card .value.error  { color: var(--color-error); }
.card .value.small  { font-size: 16px; font-weight: 600; }
.card .sub { font-size: 12px; color: var(--color-muted); margin-top: 8px; }

.filters {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
  box-shadow: var(--shadow-sm);
}
.filters label {
  display: block;
  font-size: 11px;
  color: var(--color-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.filters input, .filters select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-white);
}
.filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 145, 210, 0.15);
}

.table-wrap {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 12px;
  color: var(--color-muted);
}
table.logs {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.logs thead { background: var(--color-bg-tint); }
table.logs th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--color-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--color-border);
}
table.logs td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
table.logs tbody tr:last-child td { border-bottom: none; }
table.logs tbody tr:hover { background: var(--color-bg-tint); }
table.logs tr.sev-error   { background: #FEF2F2; }
table.logs tr.sev-warning { background: #FFFBEB; }
table.logs tr.sev-error:hover   { background: #FEE2E2; }
table.logs tr.sev-warning:hover { background: #FEF3C7; }
table.logs td.ts { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--color-muted); white-space: nowrap; }
table.logs td.msg { color: var(--color-text); max-width: 520px; }
table.logs td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.badge.info    { background: #E0F2FE; color: var(--color-accent); }
.badge.warning { background: #FEF3C7; color: #92400E; }
.badge.error   { background: #FEE2E2; color: var(--color-error); }

.empty {
  text-align: center;
  color: var(--color-muted);
  padding: 32px 16px;
  font-size: 14px;
}

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--color-bg-tint) 0%, #EEF2F7 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-white);
  padding: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
}
.login-card .brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-card .brand-row img { height: 40px; }
.login-card h1 {
  text-align: center;
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--color-secondary);
}
.login-card .subtitle {
  text-align: center;
  color: var(--color-muted);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-card input {
  width: 100%;
  padding: 12px;
  margin: 6px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
}
.login-card input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 145, 210, 0.15);
}
.login-card button {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
.login-card button:hover { background: var(--color-accent-alt); }
.login-card #message {
  min-height: 20px;
  color: var(--color-error);
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
}

/* ---------- Dashboard home two-column grid (main + right hero) ---------- */

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 16px;
    align-items: start;
}
.dashboard-content { min-width: 0; }
.dashboard-hero {
    position: sticky;
    top: 20px;
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.dashboard-hero img {
    display: block;
    width: 100%;
    height: auto;
}

@media (max-width: 1000px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .dashboard-hero { display: none; }
}

/* ---------- Rooms: ultra-compact horizontal strip list ---------- */

.rooms-list {
    display: flex; flex-direction: column; gap: 8px;
}

.room-row {
    background: var(--color-white);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 18px;
    padding: 16px 20px;
    align-items: center;
}
/* Border color reflects severity (computed server-side):
   green = accounted for; yellow = Ready past threshold; red = Not Connected */
.room-row[data-severity="green"]  { border-left: 4px solid #0091D2; }
.room-row[data-severity="yellow"] { border-left: 4px solid #F59E0B; }
.room-row[data-severity="red"]    { border-left: 4px solid #DC2626; }
.room-row[data-state="acquiring"] { border-left: 4px solid var(--color-accent); }
.room-row[data-state="ready"]     { /* Ready within threshold stays green unless severity promotes it */ }

.status-block {
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
}

.info-stack {
    display: flex; flex-direction: column; gap: 4px;
    min-width: 0;
}

/* sensor name (inline editable) */
.sensor-name-row {
    display: flex; align-items: baseline; gap: 8px;
}
.sensor-name {
    font-family: var(--font-heading);
    font-size: 17px; font-weight: 700; color: var(--color-secondary);
    letter-spacing: 0.01em;
    padding: 2px 4px; border-radius: var(--radius-sm);
    outline: none; cursor: text;
    min-width: 80px;
    transition: background 120ms ease;
}
.sensor-name:hover { background: var(--color-bg-tint); }
.sensor-name:focus { background: #F0F9FF; box-shadow: 0 0 0 2px rgba(0,145,210,0.25); }
.sensor-name.placeholder { color: var(--color-muted); font-style: italic; font-weight: 500; }
.edit-icon { width: 12px; height: 12px; color: var(--color-muted); flex-shrink: 0; cursor: pointer; opacity: 0.55; }
.sensor-name-row:hover .edit-icon { opacity: 1; color: var(--color-accent); }

.room-identity-line {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px; color: var(--color-muted);
}
.room-identity-line strong {
    color: var(--color-text); font-family: var(--font-body); font-weight: 600;
}

.info-line {
    display: flex; flex-wrap: wrap; gap: 4px 14px;
    font-size: 13px;
    align-items: baseline;
}
.info-line .num {
    font-family: var(--font-heading);
    font-weight: 700; color: var(--color-secondary);
    font-variant-numeric: tabular-nums;
}
.info-line .lbl { color: var(--color-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.info-line.metrics { border-top: 1px dashed var(--color-border); padding-top: 6px; margin-top: 2px; }

.quality-number[data-bucket="excellent"] { color: #0091D2; }
.quality-number[data-bucket="good"]      { color: var(--color-accent); }
.quality-number[data-bucket="fair"]      { color: #92400E; }
.quality-number[data-bucket="poor"]      { color: var(--color-error); }

.status-col { display: flex; align-items: center; gap: 8px; }
.status-pill {
    font-family: var(--font-heading);
    font-size: 10px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
    padding: 4px 11px; border-radius: 9999px; white-space: nowrap;
}
/* Status pills: green for accounted-for states (docked/ready/acquiring),
   red for Not Connected. Yellow override applied via [data-severity="yellow"]
   below when a Ready sensor is past the stuck-undocked threshold. */
.status-pill.docked        { color: #0C4A6E; background: #E1F2FA; }
.status-pill.ready         { color: #0C4A6E; background: #E1F2FA; }
.status-pill.connecting    { color: #0C4A6E; background: #E1F2FA; animation: pulse-fast 1.4s ease-in-out infinite; }
.status-pill.acquiring     { color: #fff;    background: var(--color-accent); animation: pulse-fast 0.9s ease-in-out infinite; }
.status-pill.receiving     { color: #fff;    background: var(--color-accent); animation: pulse-receiving 1.0s ease-in-out infinite; }
.status-pill.not_connected { color: #fff;    background: #DC2626; animation: pulse-fast 1.2s ease-in-out infinite; }
.status-pill.dock_disconnected { color: #fff; background: #6B7280; animation: pulse-fast 1.6s ease-in-out infinite; }
/* PC Offline — neutral gray, no animation (we don't know the current state) */
.status-pill.pc_offline        { color: #374151; background: #E5E7EB; }
.room-row[data-severity="yellow"] .status-pill { color: #78350F; background: #FEF3C7; }
.room-row[data-severity="red"]    .status-pill { color: #fff; background: #DC2626; animation: pulse-fast 1.2s ease-in-out infinite; }
/* PC Offline row: muted severity so the pill doesn't turn yellow/red and
   pull attention away from the last-known state pill. Override the
   severity-based background for pc_offline specifically. */
.room-row[data-state="pc_offline"] .status-pill.pc_offline { color: #374151; background: #E5E7EB; animation: none; }
.room-row[data-state="pc_offline"] .status-pill             { opacity: 1; }
@keyframes pulse-fast { 0%,100% { opacity: 1; } 50% { opacity: 0.72; } }
/* Receiving = a stronger, ring-pulsing animation so an in-flight image is
   unmistakable on the dashboard. */
@keyframes pulse-receiving {
    0%   { box-shadow: 0 0 0 0   rgba(0,145,210,0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(0,145,210,0);    }
    100% { box-shadow: 0 0 0 0   rgba(0,145,210,0);    }
}

.timer-display {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px; color: var(--color-muted); font-variant-numeric: tabular-nums;
}

.stat {
    display: flex; align-items: baseline; gap: 6px;
    white-space: nowrap;
    min-width: 110px;
    justify-content: flex-end;
}
.stat .stat-num {
    font-family: var(--font-heading);
    font-size: 18px; font-weight: 700; color: var(--color-secondary);
    letter-spacing: 0.01em;
    font-variant-numeric: tabular-nums;
}
.stat .stat-label { color: var(--color-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
/* Quality colored only via number tint, no badge pill */
.stat.quality[data-bucket="excellent"] .stat-num { color: #0091D2; }
.stat.quality[data-bucket="good"]      .stat-num { color: var(--color-accent); }
.stat.quality[data-bucket="fair"]      .stat-num { color: #92400E; }
.stat.quality[data-bucket="poor"]      .stat-num { color: var(--color-error); }

.chevron {
    width: 18px; height: 18px; color: var(--color-muted);
    transition: transform 180ms ease;
    flex-shrink: 0;
}
.room-row[open] .chevron { transform: rotate(180deg); color: var(--color-accent); }

/* Expanded details */
.room-details {
    padding: 14px 18px 16px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg-tint);
}
.room-details .detail-grid {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    font-size: 12px;
    margin-bottom: 12px;
}
.room-details .detail-item .label {
    color: var(--color-muted); font-size: 10px;
    text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
    margin-bottom: 2px;
}
.room-details .detail-item .value {
    font-family: var(--font-heading);
    font-size: 14px; font-weight: 700; color: var(--color-secondary);
}
.room-details .quality-row {
    display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.room-details .quality-row .label {
    color: var(--color-muted); font-size: 10px;
    text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
    min-width: 90px; flex-shrink: 0;
}
.room-details .quality-row .quality-bar-track { flex: 1; }

.quality-bar-track {
    height: 5px; background: var(--color-white); border-radius: 9999px; overflow: hidden;
    border: 1px solid var(--color-border);
}
.quality-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #dc2626 0%, #f59e0b 20%, #0C6ECF 40%, #0091D2 60%);
    transition: width 400ms ease;
}
.room-details .kpi-block {
    padding-top: 12px;
    border-top: 1px dashed var(--color-border);
    font-size: 12px;
}
.room-details .kpi-block .kpi-label { color: var(--color-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.room-details .kpi-block .kpi-value { font-family: var(--font-heading); color: var(--color-secondary); font-size: 16px; font-weight: 700; }
.room-details input[type="date"] {
    padding: 5px 8px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: 12px; background: var(--color-white);
}
.room-details .last-activity {
    margin-top: 10px; font-size: 10px; color: var(--color-muted);
    text-transform: uppercase; letter-spacing: 0.06em;
}

@media (max-width: 720px) {
    .room-summary {
        grid-template-columns: 1fr auto auto;
        grid-template-areas: "name status chev"
                             "images images images"
                             "quality quality quality";
        gap: 6px 10px;
    }
    .room-name  { grid-area: name; }
    .status-col { grid-area: status; }
    .chevron    { grid-area: chev; }
    .stat.images  { grid-area: images;  justify-content: flex-start; min-width: 0; }
    .stat.quality { grid-area: quality; justify-content: flex-start; min-width: 0; }
}

/* ---------- FTG-branded summary cards ---------- */
.card[data-accent="blue"]   { border-top: 3px solid var(--color-accent); }
.card[data-accent="amber"]  { border-top: 3px solid #F59E0B; }
.card[data-accent="red"]    { border-top: 3px solid var(--color-error); }
.card[data-accent="navy"]   { border-top: 3px solid var(--color-secondary); }
.quality-bar-label {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 10px; color: var(--color-muted); margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
}
.quality-bar-label .q-value { font-family: var(--font-heading); color: var(--color-secondary); font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
.quality-bar-label .q-bucket { font-size: 8px; padding: 1px 6px; border-radius: 9999px; text-transform: uppercase; letter-spacing: 0.08em; margin-left: 4px; font-weight: 700; }
.q-bucket.excellent { background: #E1F2FA; color: #0C4A6E; }
.q-bucket.good      { background: #E0F2FE; color: #0C4A6E; }
.q-bucket.fair      { background: #FEF3C7; color: #92400E; }
.q-bucket.poor      { background: #FEE2E2; color: #991B1B; }
.quality-bar-track {
    height: 5px; background: var(--color-bg-tint); border-radius: 9999px; overflow: hidden;
    border: 1px solid var(--color-border);
}
.quality-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #dc2626 0%, #f59e0b 20%, #0C6ECF 40%, #0091D2 60%);
    transition: width 400ms ease;
}

.room-card details { margin: 0; }
.room-card details > summary {
    cursor: pointer; font-size: 11px; color: var(--color-accent);
    font-weight: 600; list-style: none; padding: 2px 0;
}
.room-card details > summary::-webkit-details-marker { display: none; }
.room-card details > summary::before {
    content: "\25B8"; display: inline-block; margin-right: 6px; color: var(--color-muted);
    transition: transform 120ms ease;
}
.room-card details[open] > summary::before { transform: rotate(90deg); }

.room-card .kpi-panel {
    margin-top: 10px; padding-top: 10px;
    border-top: 1px dashed var(--color-border);
    font-size: 12px;
}
.room-card .kpi-panel .kpi-label { color: var(--color-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.room-card .kpi-panel .kpi-value { font-family: var(--font-heading); color: var(--color-secondary); font-size: 18px; font-weight: 700; }
.room-card .kpi-panel input[type="date"] {
    width: 100%; padding: 6px 8px; background: var(--color-white);
    border: 1px solid var(--color-border); border-radius: var(--radius-sm);
    color: var(--color-text); font-family: inherit; font-size: 12px;
}

.room-card .last-activity {
    margin: 0; font-size: 10px; color: var(--color-muted);
    text-transform: uppercase; letter-spacing: 0.06em;
}

/* Settings link: hidden on desktop (lives under "More" group instead),
   visible on mobile where the "More" group is collapsed away. */
.sidebar nav.sidenav-compact a.nav-settings { display: none; }

/* ================================================================
   MOBILE RESPONSIVE — 768px and below
   ================================================================ */
@media (max-width: 768px) {
  /* --- Layout: single column, no sidebar --- */
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: auto;
    padding: 10px 14px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
  .sidebar .brand { margin-bottom: 0; padding: 4px; }
  .sidebar .brand img { height: 22px; }
  .sidebar .brand .product { font-size: 12px; }
  .sidebar-hero { display: none; }
  .sidebar nav.sidenav-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    flex: 1;
    justify-content: flex-end;
  }
  .sidebar nav.sidenav-compact a {
    margin-bottom: 0;
    padding: 8px 10px !important;
    font-size: 11px !important;
    border-radius: 4px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .sidebar nav.sidenav-compact .sidenav-group { display: none; }
  .sidebar nav.sidenav-compact a.nav-settings { display: inline-flex; }

  /* --- Main content area --- */
  .main { padding: 14px 12px; padding-bottom: 80px; }
  .topbar { padding: 0 0 12px; flex-wrap: wrap; gap: 8px; }
  .topbar h2 { font-size: 18px; }
  .user-menu { font-size: 11px; gap: 8px; }
  .user-menu .who { display: none; }

  /* --- KPI cards: stack vertically, 2-column on wider phones --- */
  .cards { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .card { padding: 12px 14px !important; }
  .card .value { font-size: 22px; }
  .card .label { font-size: 10px; margin-bottom: 6px; }
  .card .sub { font-size: 11px; }

  /* --- Room rows: stack vertically --- */
  .room-row {
    grid-template-columns: 1fr !important;
    gap: 10px;
    padding: 14px 16px;
  }
  .status-block { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
  .info-stack { gap: 3px; }
  .sensor-name { font-size: 15px; }
  .room-identity-line { font-size: 11px; }
  .info-line { font-size: 12px; gap: 3px 10px; }
  .stat { min-width: auto; justify-content: flex-start; }
  .stat .stat-num { font-size: 15px; }
  .stat .stat-label { font-size: 10px; }
  .status-pill { font-size: 9px; padding: 3px 9px; }
  .timer-display { font-size: 10px; }

  /* --- Room details (expanded) --- */
  .room-details { padding: 12px 14px; }
  .room-details .detail-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .room-details .detail-item .value { font-size: 13px; }

  /* --- Tables: horizontal scroll + smaller text --- */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.logs { font-size: 11px; min-width: 500px; }
  table.logs th, table.logs td { padding: 8px 10px; white-space: nowrap; }
  table.logs td.msg { white-space: normal; max-width: 200px; }
  .table-meta { flex-wrap: wrap; gap: 6px; font-size: 11px; padding: 10px 12px; }

  /* --- Filters: stack vertically --- */
  .filters {
    grid-template-columns: 1fr !important;
    gap: 10px;
    padding: 12px;
  }

  /* --- Forms: touch-friendly controls --- */
  input[type="text"], input[type="number"], input[type="email"],
  input[type="tel"], input[type="password"], input[type="date"],
  select, textarea {
    font-size: 16px !important; /* prevents iOS zoom on focus */
    padding: 12px !important;
    min-height: 44px;
  }
  .btn {
    padding: 12px 18px;
    font-size: 14px;
    min-height: 44px;
    touch-action: manipulation;
  }

  /* --- Settings page cards + inline grids --- */
  .card h3 { font-size: 15px; }
  .card form { flex-wrap: wrap !important; }
  /* Override inline grid-template-columns on settings/form grids */
  div[style*="grid-template-columns: repeat(2"] {
    grid-template-columns: 1fr !important;
  }
  div[style*="grid-template-columns:repeat(2"] {
    grid-template-columns: 1fr !important;
  }
  /* Inline flex forms (Save buttons alongside inputs) */
  form[style*="display:flex"] {
    flex-wrap: wrap !important;
  }
  form[style*="display:flex"] > div[style*="min-width"] {
    min-width: 100% !important;
    flex: 1 1 100% !important;
  }

  /* --- Login card --- */
  .login-card { padding: 24px 20px; }
  .login-card h1 { font-size: 18px; }

  /* --- Dashboard hero (right column) --- */
  .dashboard-grid { grid-template-columns: 1fr !important; }
  .dashboard-hero { display: none; }

  /* --- Practice switcher --- */
  #practice-switcher { margin: 0 0 0 auto !important; }
  #practice-switcher label { display: none; }
  #practice-select { font-size: 11px !important; padding: 5px 24px 5px 8px !important; min-height: auto; }
}

/* ================================================================
   EXTRA-SMALL PHONES — 420px and below
   ================================================================ */
@media (max-width: 420px) {
  .sidebar { padding: 8px 10px; }
  .sidebar nav.sidenav-compact a {
    padding: 6px 8px !important;
    font-size: 10px !important;
  }
  .main { padding: 10px 8px; }
  .topbar h2 { font-size: 16px; }
  .cards { grid-template-columns: 1fr !important; }
  .card .value { font-size: 20px; }
  .room-row { padding: 12px; }
  .sensor-name { font-size: 14px; }
  .room-details .detail-grid { grid-template-columns: 1fr; }
}

/* ================================================================
   PWA STANDALONE MODE — no browser chrome, safe-area padding
   ================================================================ */
@media (display-mode: standalone) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .main {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}
