:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #171b21;
  --line: #252b33;
  --text: #f4f7fb;
  --muted: #8d98a6;
  --soft: #c5cbd3;
  --good: #4fd18b;
  --warn: #f0b84b;
  --bad: #ff6b6b;
  --info: #75a7ff;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif; }
a { color: inherit; text-decoration: none; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); background: #0d1014; padding: 22px 16px; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 24px; }
.brand-mark { width: 35px; height: 35px; border-radius: 11px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; letter-spacing: .05em; }
.brand small { color: var(--muted); margin-top: 1px; }
nav { display: grid; gap: 5px; }
.nav-item { padding: 11px 12px; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 600; }
.nav-item:hover { color: var(--text); background: var(--panel); }
.nav-item.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); }
.danger-link { margin-top: 10px; color: #e69393; }
.sidebar-foot { margin-top: auto; padding: 12px; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.dot { width: 7px; height: 7px; display: inline-block; border-radius: 50%; background: var(--muted); }
.dot.live { background: var(--good); box-shadow: 0 0 0 4px rgba(79,209,139,.08); }

.content { min-width: 0; padding: 28px 34px 48px; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.topbar h1 { margin: 4px 0 0; font-size: 30px; letter-spacing: -.035em; }
.eyebrow { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .14em; font-weight: 700; }
.topbar-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

.grid { display: grid; gap: 14px; }
.metrics { grid-template-columns: repeat(6, minmax(0,1fr)); margin-bottom: 20px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 17px; min-height: 104px; }
.metric .label { color: var(--muted); font-size: 12px; margin-bottom: 17px; }
.metric .value { font-size: 29px; font-weight: 750; letter-spacing: -.04em; }
.metric .sub { color: var(--muted); font-size: 11px; margin-top: 5px; }
.two-col { grid-template-columns: minmax(0, 1.55fr) minmax(320px, .75fr); align-items: start; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-head { min-height: 54px; padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.card-head h2 { font-size: 14px; margin: 0; }
.card-head .hint { color: var(--muted); font-size: 12px; }
.card-body { padding: 18px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; padding: 11px 13px; border-bottom: 1px solid var(--line); }
td { padding: 12px 13px; border-bottom: 1px solid rgba(37,43,51,.7); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.018); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.clip { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 750; line-height: 1; border: 1px solid var(--line); background: var(--panel-2); color: var(--soft); }
.badge.delivered, .badge.online, .badge.ready, .badge.submitted { color: var(--good); border-color: rgba(79,209,139,.28); background: rgba(79,209,139,.06); }
.badge.failed, .badge.offline, .badge.error { color: var(--bad); border-color: rgba(255,107,107,.25); background: rgba(255,107,107,.06); }
.badge.unknown, .badge.degraded, .badge.processing, .badge.executing { color: var(--warn); border-color: rgba(240,184,75,.25); background: rgba(240,184,75,.06); }
.badge.queued, .badge.pending, .badge.leased, .badge.acked { color: var(--info); border-color: rgba(117,167,255,.25); background: rgba(117,167,255,.06); }

.filters { display: grid; grid-template-columns: 1.2fr .7fr .8fr auto; gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); }
input, select, button { font: inherit; }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; background: #0d1014; color: var(--text); outline: none; }
input:focus, select:focus { border-color: #4b5665; }
button, .button { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--text); color: var(--bg); font-weight: 750; cursor: pointer; }
.button.secondary { background: var(--panel-2); color: var(--text); }

.gateway-list, .client-list { display: grid; gap: 12px; }
.gateway, .client { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.gateway-top, .client-top { display: flex; justify-content: space-between; align-items: center; gap: 15px; padding: 15px 17px; border-bottom: 1px solid var(--line); }
.gateway-name, .client-name { font-weight: 750; }
.gateway-meta, .client-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.modem-grid, .project-grid { display: grid; gap: 9px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); padding: 13px; }
.modem, .project { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #0f1216; }
.modem-row, .project-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; font-size: 12px; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(300px,.7fr); gap: 14px; align-items: start; }
.message-box { white-space: pre-wrap; line-height: 1.55; font-size: 14px; background: #0d1014; border: 1px solid var(--line); border-radius: 12px; padding: 15px; }
.kv { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 9px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { display: grid; }
.event { display: grid; grid-template-columns: 145px 13px minmax(0,1fr); gap: 11px; }
.event-time { color: var(--muted); font-size: 11px; padding-top: 14px; }
.event-line { position: relative; }
.event-line::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 1px; background: var(--line); }
.event-line::after { content: ""; position: absolute; left: 3px; top: 17px; width: 7px; height: 7px; border-radius: 50%; background: var(--soft); }
.event-body { padding: 11px 0 15px; }
.event-title { font-size: 13px; font-weight: 700; }
.event-sub { font-size: 11px; color: var(--muted); margin-top: 5px; overflow-wrap: anywhere; }
.empty { padding: 26px; color: var(--muted); text-align: center; font-size: 13px; }

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .two-col, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .sidebar-foot { display: none; }
  .content { padding: 22px 14px 38px; }
  .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .filters { grid-template-columns: 1fr; }
  .topbar { align-items: start; }
  .topbar-meta { display: none; }
  .event { grid-template-columns: 95px 13px minmax(0,1fr); }
  .kv { grid-template-columns: 110px minmax(0,1fr); }
}
