/* DeviceControl dashboard - palette per the validated default instance
   (see dataviz skill references/palette.md). Light is default; dark applies
   both via prefers-color-scheme and an explicit data-theme toggle. */

:root {
  color-scheme: light;
  --surface-1:      #fcfcfb;
  --page-plane:     #f9f9f7;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);

  --series-1: #2a78d6; /* blue - sequential default / primary categorical */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1a1a19;
    --page-plane:     #0d0d0d;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1a1a19;
  --page-plane:     #0d0d0d;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* { box-sizing: border-box; }

/* Several elements below set their own `display` (flex, etc.) for when they're
   shown, which would otherwise silently beat the browser's default
   `[hidden] { display: none }` rule (author CSS always wins over UA CSS at
   equal specificity) - this keeps the hidden attribute authoritative. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-plane);
  color: var(--text-primary);
}

.muted { color: var(--text-secondary); }
.muted.small { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 360px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { margin: 0 0 16px; font-size: 13.5px; }
.login-card label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-secondary); }
.login-card input {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  margin-bottom: 14px;
  font-size: 14px;
}
.form-error { color: var(--status-critical); font-size: 13px; margin: -8px 0 12px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font);
  font-size: 13.5px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}
.btn:hover { background: var(--gridline); }
.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
  width: 100%;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--gridline); }
.btn-danger { border-color: var(--status-critical); color: var(--status-critical); }
.btn-danger:hover { background: var(--status-critical); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link-btn {
  background: none; border: none; color: var(--series-1); font-size: 12.5px;
  cursor: pointer; padding: 0; font-family: var(--font);
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; }
.topbar-title h1 { font-size: 17px; margin: 0; }
.topbar-actions { display: flex; gap: 8px; }

.content { padding: 20px 24px 48px; max-width: 1180px; margin: 0 auto; }

/* ---------- KPI tiles ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  position: relative;
}
.stat-label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 600; font-variant-numeric: proportional-nums; }
.sparkline { position: absolute; right: 16px; bottom: 14px; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 12px; }
.card-header h2 { font-size: 15px; margin: 0; }
.search-input {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 13px;
  min-width: 240px;
}

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
.data-table tbody tr { cursor: default; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--page-plane); }
.data-table td.num { font-variant-numeric: tabular-nums; }
.snippet-cell { max-width: 320px; overflow-wrap: anywhere; color: var(--text-secondary); }

/* ---------- Status badges (icon + label, never color alone) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge-good { color: var(--status-good); }
.badge-good .badge-dot { background: var(--status-good); }
.badge-muted { color: var(--text-muted); }
.badge-muted .badge-dot { background: var(--text-muted); }
.badge-warning { color: var(--status-warning); }
.badge-warning .badge-dot { background: var(--status-warning); }
.badge-serious { color: var(--status-serious); }
.badge-serious .badge-dot { background: var(--status-serious); }
.badge-critical { color: var(--status-critical); }
.badge-critical .badge-dot { background: var(--status-critical); }

/* ---------- Drawer ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw);
  background: var(--surface-1); border-left: 1px solid var(--border);
  z-index: 21; display: flex; flex-direction: column; overflow: hidden;
}
.drawer-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.drawer-header h2 { margin: 0 0 2px; font-size: 16px; }
.drawer-body { overflow-y: auto; padding: 4px 20px 32px; }
.drawer-section { padding: 16px 0; border-bottom: 1px solid var(--gridline); }
.drawer-section:last-child { border-bottom: none; }
.drawer-section h3 { font-size: 13px; margin: 0 0 10px; color: var(--text-secondary); }

.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.kv-list dt { color: var(--text-secondary); }
.kv-list dd { margin: 0; }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.chart-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-container { position: relative; }

/* ---------- Confirm modal ---------- */
#confirm-backdrop { z-index: 30; }
.confirm-modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; width: min(380px, calc(100vw - 32px)); z-index: 31;
}
.confirm-modal h3 { margin: 0 0 8px; font-size: 15px; }
.confirm-modal p { font-size: 13.5px; color: var(--text-secondary); margin: 0 0 14px; }
.confirm-modal label { display: block; font-size: 13px; margin-bottom: 14px; }
.confirm-modal input {
  width: 100%; margin-top: 6px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--page-plane); color: var(--text-primary);
}
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Chart primitives ---------- */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-bar { fill: var(--series-1); }
.chart-bar-label { fill: var(--text-secondary); font-size: 12px; }
.chart-axis-label { fill: var(--text-muted); font-size: 11px; }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--series-1); opacity: 0.10; }
.chart-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart-crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
.chart-hit { fill: transparent; }
.chart-bar:hover, .chart-hit:hover ~ .chart-dot { filter: brightness(1.15); }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  white-space: nowrap;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.08s;
}
.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-value { font-weight: 700; color: var(--text-primary); }
.chart-tooltip .tt-label { color: var(--text-secondary); margin-left: 6px; }

.chart-table { display: none; }
.chart-table.visible { display: table; }
.chart-container.table-mode .chart-svg { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 8px; font-size: 13.5px; z-index: 40;
}

@media (max-width: 720px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .action-grid { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
}
