/* OOPanel console — one stylesheet, no build step, no CDN.
   Light and dark come from the platform preference and an explicit override the operator can
   set. Colour is never the only signal: every status badge also carries its own word. */

:root {
  /* Without this the browser paints native widgets — a <select>, its option list, a scrollbar — in the
     light scheme no matter what the tokens say, so a console in dark mode grows a white control that
     nothing in the stylesheet can reach. */
  color-scheme: light dark;
  --bg: #f6f7f9;
  --bg-raised: #ffffff;
  --bg-sunken: #eef0f4;
  --border: #d8dde6;
  --border-strong: #b9c2d0;
  --text: #14181f;
  --text-muted: #5a6473;
  --accent: #1f5cc0;
  --accent-ink: #ffffff;
  --accent-soft: #e7efff;
  --ok-fg: #14562f;
  --ok-bg: #dcf3e4;
  --partial-fg: #6b4a05;
  --partial-bg: #fbeecb;
  --warn-fg: #7a2e12;
  --warn-bg: #fbe0d4;
  --error-fg: #7c1d2c;
  --error-bg: #fadde1;
  --pending-fg: #3d4653;
  --pending-bg: #e6e9ef;
  --shadow: 0 1px 2px rgba(14, 20, 31, .06), 0 8px 24px rgba(14, 20, 31, .05);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117;
    --bg-raised: #151b23;
    --bg-sunken: #10151c;
    --border: #273040;
    --border-strong: #3a475b;
    --text: #e6ebf2;
    --text-muted: #97a3b6;
    --accent: #6ea8ff;
    --accent-ink: #06193a;
    --accent-soft: #16283f;
    --ok-fg: #7ee2ab;
    --ok-bg: #12331f;
    --partial-fg: #f2cf7a;
    --partial-bg: #3a2e10;
    --warn-fg: #f7b49a;
    --warn-bg: #3d2015;
    --error-fg: #ffa9b8;
    --error-bg: #3f1720;
    --pending-fg: #a9b4c6;
    --pending-bg: #1b2431;
    --shadow: none;
  }
}

/* An explicit light theme pins the widget scheme too: without this an operator on a dark-mode OS gets a
   light-styled page whose dropdown is still painted dark. */
:root[data-theme="light"] { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-raised: #151b23;
  --bg-sunken: #10151c;
  --border: #273040;
  --border-strong: #3a475b;
  --text: #e6ebf2;
  --text-muted: #97a3b6;
  --accent: #6ea8ff;
  --accent-ink: #06193a;
  --accent-soft: #16283f;
  --ok-fg: #7ee2ab;
  --ok-bg: #12331f;
  --partial-fg: #f2cf7a;
  --partial-bg: #3a2e10;
  --warn-fg: #f7b49a;
  --warn-bg: #3d2015;
  --error-fg: #ffa9b8;
  --error-bg: #3f1720;
  --pending-fg: #a9b4c6;
  --pending-bg: #1b2431;
  --shadow: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  text-rendering: optimizeLegibility;
}

.mono { font-family: var(--mono); font-size: .92em; font-variant-numeric: tabular-nums; }
.small { font-size: .85rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--accent); color: var(--accent-ink); padding: .6rem 1rem; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- shell ---------- */

.shell { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  padding: 1.1rem .9rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); align-self: center; }
.brand-name { font-weight: 700; letter-spacing: -.02em; font-size: 1.05rem; }
.brand-version { color: var(--text-muted); }

.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .52rem .6rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--bg-sunken); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-label { min-width: 0; }

.side-meta { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .25rem .6rem; font-size: .8rem; }
.side-meta dt { color: var(--text-muted); }
.side-meta dd { margin: 0; overflow-wrap: anywhere; }
.side-note { margin: auto 0 0; font-size: .78rem; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: .7rem; }

.content { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  padding: .8rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky; top: 0; z-index: 5;
}
.page-title { font-size: 1.05rem; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.inline-form { margin: 0; display: inline; }

.main { padding: 1.4rem; display: grid; gap: 1.2rem; align-content: start; }
.footer {
  margin-top: auto; padding: 1rem 1.4rem; border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: .8rem; display: flex; gap: 1rem; flex-wrap: wrap;
}

/* ---------- cards ---------- */

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card, .panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 1rem 1.1rem; }
.panel { padding: 1.1rem 1.3rem 1.3rem; }
.card-title, .panel-title {
  margin: 0 0 .5rem; font-size: .82rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 650;
}
.panel-title { font-size: .95rem; text-transform: none; letter-spacing: -.01em; color: var(--text); }
.panel-hint { margin: 0 0 1rem; color: var(--text-muted); font-size: .87rem; max-width: 74ch; }

.metric { margin: .2rem 0 .4rem; display: flex; align-items: baseline; gap: .35rem; }
.metric-value { font-size: 1.9rem; font-weight: 650; letter-spacing: -.03em; }
.metric-unit { color: var(--text-muted); font-size: .85rem; }
.metric-empty { font-size: 1.2rem; color: var(--text-muted); }
.card-sub { margin: 0; font-size: .82rem; color: var(--text-muted); }

/* ---------- facts ---------- */

.facts { margin: 0; display: grid; grid-template-columns: minmax(9rem, auto) minmax(0, 1fr); gap: .4rem 1rem; }
.facts dt { color: var(--text-muted); font-size: .85rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- badges and chips ---------- */

.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .12rem .45rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-partial { background: var(--partial-bg); color: var(--partial-fg); }
.badge-unavailable, .badge-not-configured { background: var(--pending-bg); color: var(--pending-fg); }
.badge-pending { background: var(--pending-bg); color: var(--pending-fg); }
.badge-error { background: var(--error-bg); color: var(--error-fg); }
.badge-disabled, .badge-unknown { background: var(--pending-bg); color: var(--pending-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }

.chip {
  display: inline-block; padding: .1rem .45rem; margin: 0 .25rem .25rem 0;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: .3rem; }
.dot-ok { background: #2ea45f; }
.dot-partial { background: #d8a13a; }

/* ---------- tables ---------- */

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table caption { text-align: left; }
.table th, .table td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table thead th {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  background: var(--bg-sunken); border-bottom-color: var(--border-strong);
}
.table tbody th[scope="row"] { font-weight: 500; }
.table .num { text-align: right; }
.table tr:last-child td, .table tr:last-child th { border-bottom: 0; }

/* ---------- notices ---------- */

.notice {
  margin: .9rem 0 0; padding: .7rem .9rem; border-radius: var(--radius-sm);
  background: var(--bg-sunken); border: 1px solid var(--border); font-size: .87rem;
}
.notice-critical { background: var(--warn-bg); border-color: transparent; color: var(--warn-fg); }
.notice-success { border-left: 3px solid var(--ok-fg); }
.notice-error {
  background: var(--error-bg); border-color: transparent; border-left: 3px solid var(--error-fg);
  color: var(--error-fg);
}
.notice ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.empty-state { margin: 0; color: var(--text-muted); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.refusal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; font-size: .87rem; }
.refusal-code { color: var(--text-muted); }
.session-note { margin: 0; font-size: .82rem; color: var(--text-muted); }

/* ---------- buttons and forms ---------- */

.primary-button, .ghost-button, .icon-button {
  font: inherit; cursor: pointer; border-radius: var(--radius-sm);
  padding: .45rem .85rem; border: 1px solid var(--border-strong); background: var(--bg-raised); color: var(--text);
}
.primary-button { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; width: 100%; }
.primary-button:hover { filter: brightness(1.06); }
.ghost-button:hover, .icon-button:hover { background: var(--bg-sunken); }
.nav-open { display: none; }

/* ---------- standalone (login, setup, problem) ---------- */

.standalone { display: grid; place-items: center; min-height: 100vh; padding: 1.2rem; }
.standalone-main { width: 100%; display: grid; place-items: center; }
.auth-card {
  width: min(460px, 100%); background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow);
}
.auth-head { display: flex; flex-direction: column; gap: .2rem; margin-bottom: 1.1rem; }
.auth-head h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.02em; }
.auth-sub { margin: 0; color: var(--text-muted); font-size: .87rem; }
.auth-form { display: grid; gap: .9rem; }
.field { display: grid; gap: .3rem; }
.field label { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.field input, .field select {
  font: inherit; padding: .55rem .7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
/* A select is a choice the node measured, not text the operator typed, so it must read as a control and
   not as the browser's own default widget sitting in a themed card. */
.field select { cursor: pointer; }
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.form-row > .field { flex: 1 1 12rem; min-width: 0; }
.form-row > .form-action { flex: 0 0 auto; }
/* .primary-button stretches to its container for the auth card; inside a row it would size to the row's
   leftover space and push the line past a phone's width. */
.form-row > .form-action .primary-button { width: auto; }
/* Three binding changes are three questions, not one long form; without a divider the second form's
   first label sits directly under the first form's submit button. */
.panel form + form { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.auth-foot { margin: .9rem 0 0; font-size: .8rem; color: var(--text-muted); }
.help-list { margin: 0; padding-left: 1.2rem; font-size: .87rem; }
.link { color: var(--accent); }
.row-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.small-link { font-size: .8rem; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border);
    display: none;
  }
  body.nav-visible .sidebar { display: flex; }
  .nav-open { display: inline-block; }
  .main { padding: 1rem; }
  .topbar { padding: .7rem 1rem; }
  .facts { grid-template-columns: minmax(0, 1fr); }
  .facts dt { margin-top: .5rem; }
  .table { font-size: .84rem; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table tr { display: grid; gap: .15rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
  .table td, .table th { border: 0; padding: .1rem 0; }
  .table .num { text-align: left; }
  /* With the header row hidden every cell needs its own label, authored in the markup. */
  .table td[data-label]::before {
    content: attr(data-label); display: block; font-size: .7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .sidebar, .topbar, .footer { display: none; }
  .shell { grid-template-columns: 1fr; }
}
