:root {
  --bg: #f4f6f8; --panel: #ffffff; --panel-2: #f8fafb; --line: #e2e7ec; --text: #17212b; --muted: #5e6b78;
  --brand: #0e6e8c; --brand-2: #0a5670; --brand-soft: #e3f2f7;
  --ok: #1f8a4c; --ok-soft: #e4f4ea; --warn: #b26a00; --warn-soft: #fbf0dc; --bad: #c0392b; --bad-soft: #fbe6e3;
  --info: #2c6fb7; --info-soft: #e5eef9; --grey-soft: #eceff2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151b; --panel: #161e26; --panel-2: #1b242d; --line: #26323d; --text: #e6edf3; --muted: #93a1ae;
    --brand: #3fb0d3; --brand-2: #63c3e0; --brand-soft: #12313d;
    --ok: #4cc27c; --ok-soft: #12301f; --warn: #e3a440; --warn-soft: #34270f; --bad: #ef6b5e; --bad-soft: #3a1915;
    --info: #6ea8ec; --info-soft: #142740; --grey-soft: #222d37;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f151b; --panel: #161e26; --panel-2: #1b242d; --line: #26323d; --text: #e6edf3; --muted: #93a1ae;
  --brand: #3fb0d3; --brand-2: #63c3e0; --brand-soft: #12313d;
  --ok: #4cc27c; --ok-soft: #12301f; --warn: #e3a440; --warn-soft: #34270f; --bad: #ef6b5e; --bad-soft: #3a1915;
  --info: #6ea8ec; --info-soft: #142740; --grey-soft: #222d37;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---- brand ---- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-size: 17px; color: var(--text); font-weight: 500; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--brand); font-weight: 750; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 15px;
}
.brand-lg { font-size: 26px; }
.brand-lg .brand-mark { width: 40px; height: 40px; font-size: 21px; border-radius: 11px; }

/* ---- sign-in ---- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 36px 32px; max-width: 420px; width: 100%; text-align: center; }
.signin-card p { margin: 14px 0; }
.signin-msg { background: var(--warn-soft); color: var(--text); border-radius: 8px; padding: 10px 12px; text-align: left; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: 210px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar-mid { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.customer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-pick { max-width: 280px; }
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-name { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.menu-btn { display: none; }
.nav { background: var(--panel); border-right: 1px solid var(--line); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a { color: var(--text); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav-foot { margin-top: auto; padding: 12px; font-size: 12px; color: var(--muted); }
.view { padding: 24px; max-width: 1240px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---- cards / grid ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: 2fr 1fr; }
.stack { display: grid; gap: 16px; }
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 30px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { color: var(--muted); font-size: 12.5px; }
.kpi-ok .kpi-value { color: var(--ok); } .kpi-bad .kpi-value { color: var(--bad); } .kpi-info .kpi-value { color: var(--info); }

/* ---- meters and bars ---- */
.meter { height: 10px; background: var(--grey-soft); border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.meter.warn > span { background: var(--warn); } .meter.bad > span { background: var(--bad); }
.stacked { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--grey-soft); }
.stacked > span { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.c-grey { background: color-mix(in srgb, var(--muted) 45%, transparent); }
.c-ok { background: var(--ok); } .c-info { background: var(--info); } .c-bad { background: var(--bad); } .c-warn { background: var(--warn); }
.spark { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 6px; }
.spark > div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.spark .bar { width: 100%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.spark .bar.zero { background: var(--grey-soft); }
.spark-axis { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---- pills ---- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-grey { background: var(--grey-soft); color: var(--muted); }

/* ---- forms ---- */
input, select, button { font: inherit; }
input[type=text], input[type=email], input[type=number], input[type=search], select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-row label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 14px; min-height: 36px; cursor: pointer; font-weight: 600; }
.btn:hover { background: var(--panel-2); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-danger { color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 3px 10px; min-height: 28px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.icon-btn { border: 0; background: transparent; color: var(--text); font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--panel-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- client settings ---- */
.fields { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > label { font-size: 13.5px; }
.field input[type=text], .field textarea { width: 100%; }
.field .form-row { flex-wrap: nowrap; }
.field .form-row input[type=text] { width: auto; min-width: 0 !important; }
.field .form-row input.mono { flex: 3 1 0; }
.field .form-row input:not(.mono) { flex: 2 1 0; }
@media (max-width: 760px) { .field .form-row { flex-wrap: wrap; } .field .form-row input[type=text] { flex: 1 1 100%; } }
textarea { font: inherit; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; resize: vertical; }
.field-help { color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.field-check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.field-check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: 16px; }
.checks input { accent-color: var(--brand); }
.savebar { position: sticky; bottom: 0; margin-top: 16px; padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -2px 10px rgba(16, 24, 32, .06); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack .card h2 { margin-bottom: 14px; }
@media (min-width: 961px) { .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } .fields > .field:has(.form-row) { grid-column: 1 / -1; } }

/* ---- device detail ---- */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 20px; }
.facts dt { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 2px 0 0; word-break: break-word; }
.timeline { display: grid; gap: 12px; }
.run { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--panel); border-left: 4px solid var(--grey-soft); }
.run.r-ok { border-left-color: var(--ok); } .run.r-bad { border-left-color: var(--bad); } .run.r-info { border-left-color: var(--info); } .run.r-warn { border-left-color: var(--warn); }
.run-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; }
.run-meta { color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.step { font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); }
.step.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.step.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.log-text { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 62vh; overflow: auto; margin: 0; }

/* ---- licence ---- */
.key { font-family: var(--mono); font-size: 15px; font-weight: 600; letter-spacing: .03em; }
.lic-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---- modal / toast / loading ---- */
.modal { position: fixed; inset: 0; background: rgba(10, 16, 22, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--panel); border-radius: 12px; width: min(980px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px; overflow: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 30; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.loading { color: var(--muted); padding: 30px 0; }
.error-box { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); color: var(--text); padding: 12px 14px; border-radius: 8px; }
.note { background: var(--info-soft); border-radius: 8px; padding: 10px 12px; font-size: 13px; }

/* ---- small screens ---- */
@media (max-width: 960px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main, .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; }
  .menu-btn { display: inline-block; }
  .nav { display: none; grid-column: 1; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav.open { display: flex; }
  .nav-foot { display: none; }
  .view { padding: 16px; }
  .user-name { display: none; }
  .topbar { gap: 8px; padding: 0 10px; }
  .customer-pick { max-width: 100%; width: 100%; min-width: 0; }
  .topbar .brand > span:last-child { display: none; }
  .topbar-mid { min-width: 0; }
  .kpi .kpi-value { font-size: 24px; }
  th, td { padding: 8px 10px; }
  .hide-sm { display: none; }
}
