:root {
  color-scheme: dark;
  --bg: #08111d;
  --panel: #101c2b;
  --panel-2: #142438;
  --line: #263950;
  --text: #edf5ff;
  --muted: #96a9bf;
  --accent: #47c5ff;
  --accent-2: #2f91ff;
  --good: #42d392;
  --warn: #f5b94c;
  --danger: #ff6b7a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 80% -10%, #153c61 0, transparent 38%), var(--bg); color: var(--text); }
header, main { width: min(1180px, calc(100% - 32px)); margin-inline: auto; }
header { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; padding: 54px 0 32px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2.2rem, 5vw, 4.4rem); letter-spacing: -0.055em; line-height: .95; }
h2 { margin-bottom: 0; font-size: 1.35rem; }
h3 { margin: 18px 0 20px; font-size: 1.02rem; overflow-wrap: anywhere; }
.eyebrow { margin-bottom: 10px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.subtitle { max-width: 690px; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; }
.summary { min-width: 120px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: #0d1927cc; text-align: center; }
.summary span { display: block; font-size: 2rem; font-weight: 800; }
.summary small { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
main { display: grid; gap: 28px; padding-bottom: 64px; }
.panel, .device-card { border: 1px solid var(--line); background: linear-gradient(145deg, #122136ed, #0d1826ed); box-shadow: 0 20px 60px #0004; }
.panel { padding: 26px; border-radius: 22px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.section-heading .eyebrow { margin-bottom: 5px; }
.pill { padding: 8px 12px; border: 1px solid #2d4d69; border-radius: 999px; color: #bad3e8; background: #0a1725; font-size: .8rem; }
form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) minmax(170px, .65fr) auto; align-items: start; gap: 16px; }
.stack-panel { border-color: #27628b; background: linear-gradient(145deg, #102d47ed, #0d1826ed); }
.stack-description { max-width: 860px; color: var(--muted); }
.stack-form { grid-template-columns: 1fr; margin-top: 20px; }
.stack-basics, .stack-credentials { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stack-credentials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack-credentials[hidden] { display: none; }
fieldset { min-width: 0; margin: 0; padding: 18px; border: 1px solid var(--line); border-radius: 14px; }
legend { padding: 0 8px; color: #d8ebfc; font-size: .84rem; font-weight: 800; }
.block-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stack-block { min-width: 0; padding: 14px; border: 1px solid #29445d; border-radius: 12px; background: #091827; transition: opacity .15s, border-color .15s; }
.stack-block[data-enabled="false"] { opacity: .55; }
.stack-block[data-enabled="true"] { border-color: #397ea9; }
.block-enable, .check-option, .sensor-option { display: flex; align-items: center; gap: 9px; }
.block-enable { padding-bottom: 12px; border-bottom: 1px solid var(--line); color: #e6f4ff; }
.block-enable span { margin-left: auto; color: var(--muted); font-size: .68rem; font-weight: 500; }
.block-enable input, .check-option input, .sensor-option input { flex: 0 0 auto; width: 17px; min-height: 17px; margin: 0; accent-color: var(--accent); }
.block-sensors { display: grid; gap: 14px; max-height: 310px; margin-top: 12px; padding-right: 5px; overflow-y: auto; scrollbar-color: #315a78 #091827; }
.sensor-category { display: grid; gap: 9px; }
.sensor-category h4 { position: sticky; top: 0; z-index: 1; margin: 0; padding: 4px 0; color: #73d4ff; background: #091827; font-size: .67rem; letter-spacing: .12em; text-transform: uppercase; }
.sensor-option { color: #bcd0e2; font-size: .76rem; font-weight: 600; }
.gateway-options { display: grid; grid-template-columns: minmax(180px, .7fr) minmax(180px, .7fr) minmax(240px, 1fr); align-items: start; gap: 18px; }
.check-option { min-height: 44px; padding: 10px 12px; border: 1px solid #29445d; border-radius: 10px; background: #091827; }
.check-option span { margin-left: auto; color: var(--muted); font-size: .7rem; font-weight: 400; text-align: right; }
.stack-form > .primary { justify-self: start; min-width: 240px; margin-top: 0; }
label { display: grid; gap: 8px; color: #c9d7e6; font-size: .82rem; font-weight: 700; }
select, input, button { font: inherit; }
select, input { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid #304861; border-radius: 10px; color: var(--text); background: #081421; outline: none; }
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #47c5ff24; }
.hint { min-height: 2.4em; color: var(--muted); font-size: .73rem; font-weight: 400; line-height: 1.35; }
.input-with-unit { display: flex; align-items: center; gap: 9px; }
.input-with-unit span { color: var(--muted); font-size: .8rem; }
button { min-height: 40px; padding: 0 15px; border: 1px solid transparent; border-radius: 10px; font-weight: 750; cursor: pointer; }
button:hover { filter: brightness(1.12); }
button:disabled { cursor: not-allowed; filter: grayscale(.7); opacity: .48; }
.primary { min-height: 44px; margin-top: 25px; color: #04111d; background: linear-gradient(135deg, var(--accent), #78e1ff); }
.secondary { border-color: #35516e; color: #dcecff; background: #172b41; }
.danger { border-color: #643844; color: #ffd4d9; background: #351c27; }
.notice { margin: 14px 0 0; color: var(--muted); font-size: .78rem; }
.fleet-section { padding-top: 4px; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.device-card { padding: 20px; border-radius: 18px; }
.card-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px #f5b94c19; }
.device-card[data-healthy="true"] .status-dot { background: var(--good); box-shadow: 0 0 0 4px #42d3921c; }
.device-id { margin-left: auto; color: #6e87a0; }
.device-group { display: inline-flex; width: fit-content; margin: -8px 0 16px; padding: 5px 9px; border: 1px solid #32658a; border-radius: 999px; color: #bde7ff; background: #12304a; font-size: .72rem; }
dl { display: grid; gap: 10px; margin: 0; }
dl div { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; }
dt { color: var(--muted); font-size: .75rem; }
dd { margin: 0; color: #dceaff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; overflow-wrap: anywhere; }
a { color: var(--accent); }
.sensor-list { display: grid; gap: 6px; margin: 16px 0 0; padding: 14px 14px 14px 30px; border: 1px solid var(--line); border-radius: 10px; color: #cfe4f7; background: #081421; font-size: .75rem; }
.camera-feed-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; margin-top: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #081421; }
.camera-feed-control[hidden] { display: none; }
.camera-feed-control .hint { grid-column: 1 / -1; min-height: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.actions button { min-height: 34px; padding: 0 10px; font-size: .72rem; }
.message { margin-bottom: 18px; padding: 12px 14px; border: 1px solid #315271; border-radius: 11px; color: #cde9ff; background: #102840; }
.message[data-kind="success"] { border-color: #287052; color: #b9f3d8; background: #102b22; }
.message[data-kind="error"] { border-color: #7c3f4a; color: #ffd0d6; background: #321a23; }
.empty { color: var(--muted); }
dialog { width: min(620px, calc(100% - 32px)); padding: 26px; border: 1px solid var(--line); border-radius: 18px; color: var(--text); background: var(--panel); box-shadow: 0 24px 90px #000b; }
dialog::backdrop { background: #02070dcc; backdrop-filter: blur(4px); }
dialog form { grid-template-columns: 1fr 1fr; }
dialog h2, dialog p, dialog .actions { grid-column: 1 / -1; }

@media (max-width: 900px) {
  form, .stack-form { grid-template-columns: 1fr 1fr; }
  .stack-form { grid-template-columns: 1fr; }
  .stack-basics, .gateway-options { grid-template-columns: 1fr 1fr; }
  .block-grid { grid-template-columns: 1fr 1fr; }
  .primary { margin-top: 0; }
  .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  header { align-items: flex-start; padding-top: 34px; }
  .summary { display: none; }
  form, .stack-form, .device-grid { grid-template-columns: 1fr; }
  .stack-basics, .stack-credentials, .gateway-options, .block-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
}
