:root {
  color-scheme: dark;
  --bg: #0b0d0c;
  --surface: #121513;
  --surface-2: #181c19;
  --surface-3: #202520;
  --line: #2a302b;
  --line-strong: #3a443c;
  --text: #f0f3ed;
  --muted: #939d95;
  --faint: #626b64;
  --accent: #b8df77;
  --accent-ink: #10170b;
  --success: #83c76b;
  --danger: #ef7b6f;
  --warning: #e7bd68;
  --sans: Inter, "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}
button { border: 0; color: inherit; cursor: pointer; font: inherit; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { cursor: default; opacity: .38; }

.top {
  align-items: center;
  background: rgba(11, 13, 12, .94);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  height: 68px;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1240px) / 2));
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { align-items: center; display: flex; gap: 12px; }
.mark { fill: var(--accent); height: 24px; width: 24px; }
.brand-name { display: block; font-size: 15px; font-weight: 750; letter-spacing: .14em; line-height: 1.15; }
.brand-text { display: grid; gap: 2px; }
.conn { align-items: center; color: var(--muted); display: flex; font-size: 11px; gap: 5px; }
.status-dot { background: var(--faint); border-radius: 50%; height: 6px; width: 6px; }
.conn.live .status-dot { background: var(--success); }
.conn.idle .status-dot { background: var(--danger); }
.actions { align-items: center; display: flex; gap: 8px; position: relative; }
.more-menu {
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  display: grid;
  gap: 6px;
  min-width: 140px;
  padding: 8px;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
}
.more-menu .button { justify-content: flex-start; width: 100%; }

.button, .icon-button, .filter {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  justify-content: center;
  min-height: 36px;
  padding: 7px 13px;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.button.primary:hover { background: #c8eb92; }
.button.secondary, .icon-button { background: var(--surface-2); }
.button.secondary:hover, .icon-button:hover { background: var(--surface-3); border-color: var(--line-strong); }
.button.danger { color: var(--danger); }
.danger-filled { background: var(--danger); border-color: var(--danger); color: #1c0b09; font-weight: 650; }
.icon-button { color: var(--muted); font-size: 20px; padding: 0; width: 36px; }

.workspace { margin: 0 auto; max-width: 1288px; padding: 38px 24px 28px; }
.hero { align-items: end; display: flex; gap: 32px; justify-content: space-between; margin-bottom: 38px; }
.eyebrow { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .16em; margin: 0 0 6px; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 4vw, 42px); letter-spacing: -.035em; line-height: 1.1; margin-bottom: 10px; }
.hero-copy { color: var(--muted); font-size: 15px; margin: 0; max-width: 570px; }
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex: none; }
.metric { min-width: 108px; padding: 14px 16px; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric strong { display: block; font-size: 22px; letter-spacing: -.03em; line-height: 1.15; }
.metric span { color: var(--muted); font-size: 11px; }

.device-section, .systems-section { margin-top: 30px; }
.section-head { align-items: end; display: flex; gap: 20px; justify-content: space-between; margin-bottom: 14px; }
.section-head h2 { font-size: 20px; letter-spacing: -.02em; margin: 0; }
.section-status { color: var(--muted); font-size: 12px; }
.minis-row { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); min-height: 76px; }
.mini {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 76px;
  padding: 13px 14px;
}
.mini-card { display: grid; gap: 10px; }
.mini-head { align-items: center; display: grid; gap: 10px; grid-template-columns: 36px 1fr auto; }
.device-icon { align-items: center; background: var(--surface-3); border-radius: 8px; color: var(--muted); display: flex; font-family: var(--mono); font-size: 12px; height: 36px; justify-content: center; }
.mini b { display: block; font-size: 13px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini span { color: var(--muted); display: block; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state-pill { background: var(--surface-3); border-radius: 99px; color: var(--muted); font-size: 10px; padding: 3px 7px; }
.state-pill.on { background: rgba(131, 199, 107, .12); color: var(--success); }
.channel-row { display: flex; flex-wrap: wrap; gap: 6px; }
.channel { background: var(--surface-3); border-radius: 99px; color: var(--faint); font-size: 10px; letter-spacing: .04em; padding: 3px 8px; }
.channel.on { background: rgba(131, 199, 107, .12); color: var(--success); }
.mini-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.mini-actions .button { flex: 1; min-height: 32px; }

.systems-head { align-items: center; }
.filters { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; display: flex; padding: 3px; }
.filter { background: transparent; border: 0; border-radius: 6px; color: var(--muted); min-height: 29px; padding: 4px 10px; }
.filter:hover { color: var(--text); }
.filter.active { background: var(--surface-3); color: var(--text); }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-height: 218px;
  padding: 17px;
  transition: border-color .15s ease, transform .15s ease;
}
.card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.card.hidden-by-filter { display: none; }
.card-top { align-items: flex-start; display: flex; gap: 10px; justify-content: space-between; }
.card-identity { align-items: center; display: flex; gap: 11px; min-width: 0; }
.system-icon { align-items: center; background: var(--surface-3); border-radius: 8px; color: var(--muted); display: flex; flex: none; font-size: 13px; font-weight: 700; height: 38px; justify-content: center; width: 38px; }
.card.is-online .system-icon { background: rgba(131, 199, 107, .1); color: var(--success); }
.card-top h3 { font-size: 15px; line-height: 1.2; margin: 1px 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group { color: var(--muted); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
.card-status { align-items: center; border-radius: 99px; display: flex; flex: none; font-size: 10px; gap: 5px; padding: 4px 8px; }
.card-status .dot { background: var(--faint); border-radius: 50%; height: 6px; width: 6px; }
.card-status.online { background: rgba(131, 199, 107, .1); color: var(--success); }
.card-status.online .dot { background: var(--success); }
.card-status.offline { background: rgba(239, 123, 111, .08); color: var(--danger); }
.card-status.offline .dot { background: var(--danger); }
.detail { color: var(--muted); font-size: 12px; min-height: 18px; overflow-wrap: anywhere; }
.notice { border-left: 2px solid var(--warning); color: var(--warning); font-size: 11px; padding-left: 9px; }
.log { background: var(--bg); border-radius: 6px; color: var(--faint); font-family: var(--mono); font-size: 10px; overflow: hidden; padding: 7px 9px; text-overflow: ellipsis; white-space: nowrap; }
.row-btns { display: flex; gap: 7px; margin-top: auto; }
.row-btns button { flex: 1; min-height: 33px; padding: 5px 9px; }
.row-btns .open { color: var(--accent); }

.empty { border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); grid-column: 1 / -1; padding: 22px; text-align: center; }
.foot { border-top: 1px solid var(--line); color: var(--faint); display: flex; font-size: 11px; justify-content: space-between; margin-top: 26px; padding-top: 16px; }
.skeleton { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; opacity: .7; }
.device-skeleton { height: 76px; }
.card-skeleton { height: 218px; }

.toast-region { bottom: 20px; display: grid; gap: 8px; pointer-events: none; position: fixed; right: 20px; width: min(360px, calc(100vw - 40px)); z-index: 50; }
.toast { background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: 9px; color: var(--text); font-size: 12px; padding: 11px 13px; }
.toast.error { border-color: rgba(239, 123, 111, .55); color: var(--danger); }
.toast.success { border-color: rgba(131, 199, 107, .45); }

.modal { align-items: center; background: rgba(5, 7, 6, .82); display: flex; inset: 0; justify-content: center; padding: 20px; position: fixed; z-index: 60; }
.modal.hidden { display: none; }
.modal-card { background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: 14px; padding: 24px; width: min(440px, 100%); }
.modal-icon { align-items: center; background: rgba(239, 123, 111, .12); border-radius: 50%; color: var(--danger); display: flex; font-weight: 700; height: 38px; justify-content: center; margin-bottom: 16px; width: 38px; }
.modal-card h3 { font-size: 20px; margin-bottom: 8px; }
.modal-card p { color: var(--muted); margin-bottom: 22px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.hidden { display: none !important; }
.login-screen {
  align-items: center;
  background: var(--bg);
  display: flex;
  inset: 0;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 12px;
  max-width: 380px;
  padding: 28px;
  width: 100%;
}
.login-card label { color: var(--muted); display: grid; font-size: 12px; gap: 6px; }
.login-card input, #prompt-text {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}
.login-error { color: var(--danger); font-size: 12px; min-height: 16px; }
.role-pill { background: var(--surface-3); border-radius: 99px; color: var(--muted); font-size: 11px; padding: 6px 10px; }
.quick-section {
  background: var(--bg);
  margin-bottom: 10px;
  padding: 8px 0 14px;
  position: sticky;
  top: 68px;
  z-index: 15;
}
.quick-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.quick-btn { flex: none; min-height: 40px; scroll-snap-align: start; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--text);
  font-size: 11px;
  min-height: 28px;
  padding: 4px 10px;
}
.chip:hover { border-color: var(--line-strong); }
.chip.mini-chip { min-height: 36px; padding: 6px 12px; }

@media (max-width: 780px) {
  body { padding-bottom: env(safe-area-inset-bottom); }
  .top {
    height: auto;
    min-height: 56px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    gap: 10px;
  }
  .brand-text .conn { display: none; }
  .actions { flex-wrap: nowrap; gap: 6px; }
  .actions .role-pill { display: none; }
  .actions .button { font-size: 12px; min-height: 40px; padding-inline: 10px; }
  .workspace {
    display: flex;
    flex-direction: column;
    padding: 14px 14px 28px;
  }
  .hero {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
    order: 0;
  }
  .hero-text .eyebrow,
  .hero-text h1,
  .hero-text .hero-copy { display: none; }
  .summary { width: 100%; }
  .metric { flex: 1; min-width: 0; padding: 10px; }
  .metric strong { font-size: 18px; }
  .metric span { display: block; line-height: 1.2; }
  .quick-section {
    order: 1;
    padding-top: 0;
    position: sticky;
    top: calc(56px + env(safe-area-inset-top));
    z-index: 15;
  }
  .quick-section .section-head h2 { font-size: 16px; }
  .device-section { order: 2; margin-top: 18px; }
  .systems-section { order: 3; margin-top: 18px; }
  .foot { order: 4; }
  .section-head { align-items: stretch; flex-direction: column; }
  .filters {
    align-self: stretch;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .filter { flex: none; min-height: 36px; }
  .cards { grid-template-columns: 1fr; }
  .minis-row { grid-template-columns: 1fr; }
  .quick-btn, .mini-actions .button, .mini-chip, .chip, .row-btns button { min-height: 44px; }
  .chip, .mini-chip { font-size: 13px; padding: 8px 12px; }
  .card.has-chips .row-btns.secondary-acts { display: none; }
  .modal {
    align-items: flex-end;
    padding: 0;
  }
  .modal-card {
    border-radius: 16px 16px 0 0;
    max-height: min(90vh, 640px);
    overflow: auto;
    padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
    width: 100%;
  }
  .modal-actions {
    display: grid;
    gap: 8px;
  }
  .modal-actions .button { min-height: 48px; width: 100%; }
  .toast-region {
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 14px;
    right: 14px;
    width: auto;
  }
}
