:root {
  --bg: #eef1f4;
  --sidebar: #15202b;
  --sidebar-text: #c5d0da;
  --sidebar-active: #1f9d7a;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #5f6e7c;
  --line: #d7dee6;
  --accent: #0f7a5f;
  --accent-soft: #e6f5f0;
  --warn: #9a5b12;
  --warn-soft: #fff3e0;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --ok: #0f7a5f;
  --ok-soft: #e6f5f0;
  --shadow: 0 1px 2px rgba(21, 32, 43, 0.06), 0 8px 24px rgba(21, 32, 43, 0.04);
  --font: "Source Sans 3", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.85rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0.65rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 0.75rem;
}
.sidebar-brand strong {
  display: block;
  color: #fff;
  font-size: 0.98rem;
}
.sidebar-brand span {
  display: block;
  font-size: 0.78rem;
  opacity: 0.7;
}
.logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(145deg, #1f9d7a, #0b5a46);
  flex-shrink: 0;
}

.nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }

.nav-group { display: flex; flex-direction: column; gap: 0.2rem; }
.nav-group:not(.open) .nav-children { display: none; }
.nav-product {
  appearance: none;
  border: 0;
  background: transparent;
  color: #fff;
  font: inherit;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  font-weight: 600;
  font-size: 0.92rem;
}
.nav-product:hover { background: rgba(255,255,255,0.06); }
.nav-group.active > .nav-product {
  background: rgba(31, 157, 122, 0.12);
}

.nav-children {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-left: 0.55rem;
  margin-left: 0.65rem;
  border-left: 1px solid rgba(255,255,255,0.1);
}
.nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: none;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-child {
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
}
.nav-item.active {
  background: rgba(31, 157, 122, 0.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--sidebar-active);
}
.nav-count {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: rgba(255,255,255,0.1);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}
.nav-count.warn { background: #9a5b12; color: #fff; }

.sidebar-foot {
  padding: 0.85rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.82rem;
  display: grid;
  gap: 0.35rem;
}
.pill-row { display: flex; align-items: center; gap: 0.45rem; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #6b7785;
}
.dot.ok { background: #2ecc9b; }
.muted { opacity: 0.7; }

.main {
  padding: 1.5rem 1.75rem 2.5rem;
  min-width: 0;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-head h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
.page-head p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.view { display: none; }
.view.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}
.metric .value {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 1.1;
}
.metric .label {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel.narrow { max-width: 480px; }
.panel-bar {
  padding: 1rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.panel-bar.split {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}
.panel-bar h2 {
  margin: 0.35rem 0 0;
  font-size: 1.05rem;
}
.panel-bar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.toolbar input,
.toolbar select,
input, select {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  background: #fff;
  color: var(--ink);
}
.toolbar input[type="search"] { min-width: 240px; flex: 1; }

.table-wrap { overflow: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f7f9fb;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr:hover { background: #f8fafb; }
.mono { font-family: var(--mono); font-size: 0.86rem; }
.device-name { font-weight: 600; }
.sub { color: var(--muted); font-size: 0.82rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: #eef1f4; color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.protocol { background: #e8eef7; color: #274472; }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 0.12rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.chip.muted-chip {
  background: #eef1f4;
  color: var(--muted);
}

button, .btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.danger { background: var(--danger); }
button.linkish {
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-weight: 600;
}
button.small {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}
.row-actions { display: flex; gap: 0.35rem; justify-content: flex-end; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

[hidden] { display: none !important; }
.stack-form {
  display: grid;
  gap: 0.85rem;
  padding: 1rem 1.1rem 1.25rem;
}
.stack-form label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  width: min(460px, 94vw);
  box-shadow: var(--shadow);
  background: #fff;
}
dialog#dest-dialog {
  width: min(640px, 96vw);
}
dialog::backdrop { background: rgba(21, 32, 43, 0.4); }
#device-form, #dest-form, #customer-form {
  padding: 1.2rem;
  display: grid;
  gap: 0.75rem;
}
#device-form h3, #dest-form h3, #customer-form h3 { margin: 0; }
#device-form label, #dest-form label, #customer-form label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
}
#device-form label.check, #dest-form label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}
.dest-fields {
  display: grid;
  gap: 0.65rem;
}
.imei-toolbar {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: end;
}
.imei-toolbar .grow { flex: 1; min-width: 180px; }
.imei-actions { display: flex; gap: 0.35rem; }
.imei-meta {
  font-size: 0.82rem;
  color: var(--muted);
}
.imei-list {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem;
  display: grid;
  gap: 0.15rem;
  background: #fafbfc;
}
.imei-list label {
  display: flex !important;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.4rem 0.45rem;
  border-radius: 6px;
  color: var(--ink) !important;
}
.imei-list label:hover { background: #eef3f7; }
.imei-list .imei-main { display: grid; gap: 0.1rem; }
.imei-list .mono { font-size: 0.8rem; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem;
}
#dest-checks { display: grid; gap: 0.4rem; }
#dest-checks label {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.customer-picker {
  display: grid;
  gap: 0.3rem;
}
.customer-picker .picker-label {
  font-size: 0.9rem;
  color: var(--muted);
}
.customer-picker .req { color: #b42318; }
.picker-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}
.combobox {
  position: relative;
  flex: 1;
  min-width: 0;
}
.combobox input {
  width: 100%;
}
.combo-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 200px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.combo-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.combo-item:hover,
.combo-item.active {
  background: #eef3f7;
}
.combo-empty {
  padding: 0.55rem 0.7rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.icon-btn {
  min-width: 2.4rem;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 0.55rem;
}

.clickable { cursor: pointer; }
.clickable:hover { color: var(--accent); }

.analytics-toolbar {
  flex-wrap: wrap;
  align-items: end;
  gap: 0.65rem;
}
.preset-row {
  display: flex;
  gap: 0.3rem;
}
.analytics-note {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.vol-bar {
  height: 8px;
  border-radius: 4px;
  background: #d7e2ea;
  overflow: hidden;
  min-width: 80px;
}
.vol-bar > span {
  display: block;
  height: 100%;
  background: var(--accent, #2f6fed);
  border-radius: 4px;
}
.lat-warn { color: #b54708; font-weight: 600; }
.lat-bad { color: #b42318; font-weight: 600; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
  color: var(--muted);
}
.pager-left,
.pager-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.pager select {
  width: auto;
  min-width: 4.5rem;
  padding: 0.3rem 0.45rem;
}
.pager .page-label {
  min-width: 6.5rem;
  text-align: center;
  color: var(--ink);
}
.pager button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

body.booting .shell,
body.booting .auth-gate,
body.locked .shell { display: none; }
.auth-gate {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: #15202b;
}
body.locked .auth-gate { display: flex; }
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 1.15rem 1.15rem 0.25rem;
}
.auth-brand strong { display: block; }
.auth-brand span { display: block; font-size: 0.82rem; color: var(--muted); }
.auth-lead { margin: 0; color: var(--muted); font-size: 0.92rem; }
.auth-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
}
.totp-qr {
  display: block;
  width: 280px;
  height: 280px;
  max-width: 100%;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
#totp-secret {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}
.head-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}


@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav {
    flex-direction: column;
  }
  .sidebar-foot { display: none; }
}
