:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1b1f24;
  --muted: #667085;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --idle: #98a2b3;
  --idle-bg: #eef0f3;
  --mute: #7c3aed;
  --mute-bg: #ede9fe;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.12);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --panel: #171b21;
    --panel-2: #1e232b;
    --border: #2a303a;
    --text: #e6e9ee;
    --muted: #8b95a5;
    --accent: #4f8bff;
    --ok: #22c55e;
    --ok-bg: #12301f;
    --warn: #f59e0b;
    --warn-bg: #33270f;
    --bad: #f87171;
    --bad-bg: #3a1717;
    --idle: #6b7586;
    --idle-bg: #242a33;
    --mute: #a78bfa;
    --mute-bg: #2a2340;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--ok); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.me { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label > input, label > select { color: var(--text); font-size: 14px; }

/* summary tiles */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.tile:hover { border-color: var(--accent); }
.tile .n { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }

/* toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; }
.toolbar input { max-width: 420px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }

/* list */
.customer { margin-bottom: 18px; }
.customer-head { display: flex; align-items: baseline; gap: 8px; margin: 0 2px 6px; }
.customer-head h3 { margin: 0; font-size: 14px; }
.table { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 26px minmax(170px, 1.2fr) minmax(220px, 2.4fr) 110px minmax(150px, 1fr) 90px;
  gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); cursor: pointer;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--panel-2); }
.row.head { cursor: default; background: var(--panel-2); color: var(--muted); font-size: 12px; padding-top: 7px; padding-bottom: 7px; }
.ws-name { font-weight: 600; }
.ws-id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.empty { padding: 30px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--border); border-radius: var(--radius); }

/* status dot & chips */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); }
.dot.degraded { background: var(--warn); }
.dot.offline { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.dot.pending { background: var(--idle); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; background: var(--idle-bg); color: var(--muted); white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.down { background: var(--bad-bg); color: var(--bad); }
.chip.degraded, .chip.missing { background: var(--warn-bg); color: var(--warn); }
.chip.unknown, .chip.pending { background: var(--idle-bg); color: var(--muted); }
.pill { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.mute { background: var(--mute-bg); color: var(--mute); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.meters { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.meter { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; gap: 6px; }
.bar { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar > i.warn { background: var(--warn); }
.bar > i.bad { background: var(--bad); }

/* events */
.events-panel { margin-top: 26px; }
.events { list-style: none; margin: 0; padding: 0; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.events li { display: grid; grid-template-columns: 130px 90px 1fr; gap: 10px; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 13px; }
.events li:first-child { border-top: 0; }
.ev-kind { font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .03em; }
.ev-kind.down, .ev-kind.offline { color: var(--bad); }
.ev-kind.up, .ev-kind.online { color: var(--ok); }
.ev-kind.missing { color: var(--warn); }
.ev-kind.admin { color: var(--accent); }

/* dialogs */
dialog { border: 0; padding: 0; color: var(--text); background: var(--panel); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 14, 20, 0.45); }
.modal { border-radius: 12px; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px); }
.modal.wide { width: min(1000px, calc(100vw - 24px)); }
.modal.small-modal { width: min(440px, calc(100vw - 24px)); }
.modal-inner { padding: 20px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.error { color: var(--bad); min-height: 1em; margin: 8px 0 0; }

/* No `display` on .drawer itself: that would override the browser's hidden state for a closed dialog
   and leave the panel showing in the page. Only lay it out as flex while open. */
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(720px, 100vw);
  flex-direction: column; border-left: 1px solid var(--border);
}
.drawer[open] { display: flex; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 20px 8px; margin: 0; }
.drawer-title { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 650; }
.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button { border: 0; background: none; color: var(--muted); font: inherit; padding: 9px 10px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.drawer-body { padding: 18px 20px 30px; overflow-y: auto; flex: 1; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0 0 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.svc-status { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.svc-status .s { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 9px 12px; border-top: 1px solid var(--border); }
.svc-status .s:first-child { border-top: 0; }

/* service editor */
.svc-editor { display: flex; flex-direction: column; gap: 10px; }
.svc-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--panel); }
.svc-card.off { opacity: .5; }
.svc-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.svc-card-head input[type=text] { max-width: 180px; font-weight: 600; }
.svc-card-head .spacer { flex: 1; }
.check-row { display: grid; grid-template-columns: 110px 1fr 30px; gap: 6px; margin-bottom: 6px; }
.check-row select, .check-row input { padding: 5px 8px; font-size: 13px; }
.add-svc { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.cmd {
  position: relative; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 70px 10px 12px; font-family: var(--mono); font-size: 12.5px; word-break: break-all; margin: 8px 0 12px;
}
.cmd .copy { position: absolute; top: 8px; right: 8px; }
.callout-neutral { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin: 10px 0 14px; }
.callout { background: var(--warn-bg); color: var(--text); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin: 10px 0; }

.tpl { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.tpl-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.tpl-head input { max-width: 240px; }
.ws-pick { max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; margin: 8px 0; }
.ws-pick label { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; padding: 3px 0; }
.ws-pick input { width: auto; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 13px;
  transition: all .2s; pointer-events: none; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row { grid-template-columns: 22px 1fr; }
  .row > :nth-child(n+4) { display: none; }
  .row > :nth-child(3) { grid-column: 2; }
  .row.head { display: none; }
  .events li { grid-template-columns: 1fr; gap: 2px; }
  .grid2 { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .topbar { padding: 10px 16px; }
  main { padding: 14px 16px 30px; }
}

.update-bar {
  position: sticky; top: 0; z-index: 6; display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px; background: var(--accent); color: var(--accent-text); font-size: 13px;
}
.update-bar .btn { background: var(--accent-text); color: var(--accent); border-color: var(--accent-text); }
