/* Odoo Ops Control — palette values are the validated defaults from the
   data-viz reference palette (light + dark steps of the same hues). */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-soft: #cde2fb;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 4px 12px rgba(11, 11, 11, .04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-soft: #184f95;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-soft: #184f95;
  --shadow: none;
}

* { box-sizing: border-box; }
/* Must outrank the explicit `display` values below (.login-wrap, .panel,
   .modal-backdrop) — otherwise the [hidden] attribute those views are toggled
   with has no effect and everything renders at once. */
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
}
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 6px; font-weight: 600; }
code { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- controls */
.btn {
  font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); cursor: pointer;
}
.btn:hover { border-color: var(--baseline); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn.warn { background: var(--serious); border-color: var(--serious); color: #1a1a19; }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; }
input[type=text], input[type=password], input[type=number], select {
  font: inherit; padding: 8px 10px; border-radius: 8px; background: var(--surface-1);
  border: 1px solid var(--border); color: var(--text-primary);
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.check { display: flex; gap: 6px; align-items: center; color: var(--text-secondary); }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-secondary); }

/* ----------------------------------------------------------------- layout */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand div { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-right { display: flex; gap: 12px; align-items: center; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.good { background: var(--good); }
.dot.critical { background: var(--critical); }

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; }
.tab {
  font: inherit; padding: 8px 14px; border: 1px solid transparent; border-bottom: none;
  border-radius: 8px 8px 0 0; background: transparent; color: var(--text-secondary);
  cursor: pointer;
}
.tab.active { background: var(--surface-1); border-color: var(--border);
  color: var(--text-primary); font-weight: 600; }
.panel { padding: 16px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.split { display: grid; gap: 16px; grid-template-columns: 260px 1fr; }
@media (max-width: 720px) { .split { grid-template-columns: 1fr; } }

/* -------------------------------------------------------------- stat tiles */
.kpi-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .s { font-size: 12px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.pill .ic { font-size: 13px; }
.pill.good { color: var(--good); }
.pill.warning { color: var(--warning); }
.pill.serious { color: var(--serious); }
.pill.critical { color: var(--critical); }
.status-msg.critical { color: var(--critical); }

/* ---------------------------------------------------------------- actions */
.action { display: flex; flex-direction: column; gap: 10px; }
.action .cmd {
  display: block; padding: 8px 10px; background: var(--page);
  border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; white-space: pre;
}
.action.danger { border-color: rgba(208, 59, 59, .45); }
.action button { align-self: flex-start; }

/* second factor */
.otp-note { margin: 0; font-size: 12px; color: var(--text-secondary); }
.otp-note.blocked { color: var(--critical); font-weight: 500; }
.otp-label { display: flex; flex-direction: column; gap: 4px; margin-top: 12px;
  font-size: 12px; color: var(--text-secondary); }
#login-otp-code, #otp-code {
  font-family: var(--mono); font-size: 26px; letter-spacing: 10px; text-align: center;
  padding: 10px; width: 100%;
}
#otp-timer { margin: 8px 0 0; font-variant-numeric: tabular-nums; }

.toggle-wrap { display: flex; gap: 12px; align-items: center; }
.toggle {
  width: 56px; height: 30px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--grid); position: relative; cursor: pointer; padding: 0; flex: none;
}
.toggle .knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-1); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: left .15s;
}
.toggle[aria-checked="true"] { background: var(--good); }
.toggle[aria-checked="true"] .knob { left: 27px; }
.toggle-label { font-weight: 600; }

/* --------------------------------------------------------------- console */
.console-head { display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.console {
  font-family: var(--mono); font-size: 12px; line-height: 1.45; margin: 0;
  background: var(--page); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; max-height: 320px; overflow: auto; white-space: pre-wrap;
  word-break: break-word; color: var(--text-primary);
}
.console.tall { max-height: 60vh; }
.proc-list { max-height: 220px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.proc-list div { padding: 3px 0; border-bottom: 1px solid var(--grid); cursor: pointer; }
.proc-list div:hover { background: var(--page); }
.proc-list .main { color: var(--series-1); font-weight: 600; }

/* ----------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 500;
  padding: 6px 8px; border-bottom: 1px solid var(--baseline); white-space: nowrap;
}
.table td { padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.table tr.out td { background: var(--page); }
.table pre { margin: 0; font-size: 11px; white-space: pre-wrap; max-height: 260px; overflow: auto; }
.log-list { list-style: none; margin: 0; padding: 0; }
.log-list li { padding: 8px; border-radius: 8px; cursor: pointer; display: flex;
  justify-content: space-between; gap: 8px; }
.log-list li:hover { background: var(--page); }
.log-list li.active { background: var(--series-1-soft); }
.log-list .name { font-family: var(--mono); font-size: 12px; }

/* ----------------------------------------------------------------- chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; }
.chart .bar { fill: var(--series-1); }
.chart .bar:hover { fill: var(--text-primary); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--baseline); stroke-width: 1; }
.chart .lbl { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 3;
}

/* ------------------------------------------------------------------ htop */
.term { height: 62vh; background: #0d0d0d; border-radius: 8px; padding: 8px; overflow: hidden; }

/* ----------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: grid; place-items: center; z-index: 20; padding: 20px;
}
.modal { width: 460px; max-width: 100%; }
.modal .cmd {
  display: block; margin-top: 10px; padding: 10px; border-radius: 8px;
  background: var(--page); border: 1px solid var(--border); overflow-x: auto;
}

/* ------------------------------------------------------------------ SQL view */
.sqlbox {
  width: 100%; min-height: 140px; resize: vertical; padding: 10px 12px;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: var(--text-primary); background: var(--page);
  border: 1px solid var(--border); border-radius: 8px;
}
.sqlbox:focus { outline: none; border-color: var(--series-1); }

.sqlerror {
  margin: 10px 0 0; padding: 10px 12px; white-space: pre-wrap;
  font-family: var(--mono); font-size: 12px; line-height: 1.5;
  color: var(--critical); background: var(--page);
  border: 1px solid var(--critical); border-radius: 8px;
}

.sqlresult { margin-top: 12px; max-height: 60vh; overflow: auto;
             border: 1px solid var(--border); border-radius: 8px; }
.sqltable {
  border-collapse: collapse; width: max-content; min-width: 100%;
  font-family: var(--mono); font-size: 12px; line-height: 1.45;
}
.sqltable th, .sqltable td {
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  text-align: left; vertical-align: top;
  max-width: 480px; overflow-wrap: anywhere;
}
.sqltable thead th {
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
  background: var(--surface-1); border-bottom: 2px solid var(--baseline);
}
.sqltable tbody tr:nth-child(even) { background: var(--page); }
.sqltable td.isnull { color: var(--muted); font-style: italic; }
