/* BAPC Feature Flags & Configuration - operator console.
   Mobile-first; desktop gets a sidebar. Status is never conveyed by color alone: every badge
   carries text, and focus indicators are always visible (spec §11 accessibility). */

:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #17201b;
  --muted: #59645d;
  --line: #d6dbd4;
  --brand: #1f5c45;
  --brand-ink: #ffffff;
  --accent: #b5832b;
  --ok: #1d6b3f;
  --ok-bg: #e2f2e7;
  --warn: #8a5a00;
  --warn-bg: #fbf0d9;
  --bad: #a3261b;
  --bad-bg: #fbe3df;
  --info: #24527a;
  --info-bg: #e2edf7;
  --focus: #2a6df4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 2px 8px rgba(20, 30, 25, 0.05);
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #101512;
    --surface: #171e1a;
    --surface-2: #1f2822;
    --text: #e7ece8;
    --muted: #9aa69e;
    --line: #2d3831;
    --brand: #4fae86;
    --brand-ink: #08130d;
    --accent: #d9a74a;
    --ok: #7ed3a0;
    --ok-bg: #173323;
    --warn: #f0c46a;
    --warn-bg: #3a2c10;
    --bad: #ff8f84;
    --bad-bg: #3d1915;
    --info: #8cc0ef;
    --info-bg: #15283a;
    --focus: #7aa7ff;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #101512;
  --surface: #171e1a;
  --surface-2: #1f2822;
  --text: #e7ece8;
  --muted: #9aa69e;
  --line: #2d3831;
  --brand: #4fae86;
  --brand-ink: #08130d;
  --accent: #d9a74a;
  --ok: #7ed3a0;
  --ok-bg: #173323;
  --warn: #f0c46a;
  --warn-bg: #3a2c10;
  --bad: #ff8f84;
  --bad-bg: #3d1915;
  --info: #8cc0ef;
  --info-bg: #15283a;
  --focus: #7aa7ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip-link:focus { left: 8px; }

/* ---------- shell ---------- */
.topbar {
  position: static; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.scope { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.scope label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.scope select { min-width: 120px; }
.whoami { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

.layout { display: block; }
.sidenav { display: none; }
main { padding: 16px 16px 96px; max-width: 1200px; margin: 0 auto; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; overflow-x: auto; gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a, .sidenav a {
  flex: 0 0 auto; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600;
  padding: 8px 10px; border-radius: 8px; white-space: nowrap;
}
.tabbar a[aria-current='page'], .sidenav a[aria-current='page'] { background: var(--surface-2); color: var(--text); }
/* Shared BAPC language button: on phones, start it above the bottom menu (only while it sits
   in its default spot; once someone drags it, its own saved position wins). */
@media (max-width: 899px) {
  body > div[translate='no'][style*='bottom: 14px'] { bottom: calc(60px + env(safe-area-inset-bottom)) !important; }
}

@media (min-width: 900px) {
  .topbar { position: sticky; top: 0; }
  .layout { display: grid; grid-template-columns: 220px 1fr; }
  .sidenav { display: block; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
    padding: 12px; border-right: 1px solid var(--line); background: var(--surface); }
  .sidenav a { display: block; font-size: 14px; padding: 9px 12px; margin-bottom: 2px; }
  .sidenav .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 14px 12px 6px; }
  .tabbar { display: none; }
  main { padding: 24px 28px 48px; }
}

/* ---------- content ---------- */
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.lede { color: var(--muted); margin: 0 0 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.cols-2 { grid-template-columns: repeat(2, 1fr); } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin-top: 0; }
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.stat { font-size: 26px; font-weight: 700; line-height: 1.1; }
.muted { color: var(--muted); }
.mono, code, pre { font-family: var(--mono); font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; max-height: 420px; margin: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td a { font-weight: 600; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.badge::before { font-size: 10px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.ok::before { content: '\25CF'; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.warn::before { content: '\25B2'; }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.bad::before { content: '\25A0'; }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.neutral { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

/* ---------- forms ---------- */
form.stack, .stack { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; font-weight: 600; }
.field small { color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { font-family: var(--mono); font-size: 13px; min-height: 140px; resize: vertical; }
input[type='checkbox'] { width: auto; }
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; display: inline-flex; gap: 6px; align-items: center;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:hover { filter: brightness(1.05); background: var(--brand); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.danger-outline { color: var(--bad); border-color: var(--bad); }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
button.small { padding: 4px 10px; font-size: 13px; }

.emergency-zone { border: 2px solid var(--bad); background: var(--bad-bg); border-radius: var(--radius); padding: 14px 16px; }
.emergency-zone h3 { color: var(--bad); margin-top: 0; }

.notice { border-left: 4px solid var(--info); background: var(--info-bg); padding: 10px 12px; border-radius: 6px; font-size: 14px; margin: 12px 0; }
.notice.warn { border-color: var(--warn); background: var(--warn-bg); }
.notice.bad { border-color: var(--bad); background: var(--bad-bg); }
.notice.ok { border-color: var(--ok); background: var(--ok-bg); }

.toast-region { position: fixed; right: 16px; bottom: 84px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
@media (min-width: 900px) { .toast-region { bottom: 20px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 15, 12, 0.45); }
dialog .dlg-body { padding: 18px; }
dialog h2 { margin-top: 0; }

.diff-row { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
@media (min-width: 700px) { .diff-row { grid-template-columns: 220px 1fr 1fr; } }
.diff-before { color: var(--bad); }
.diff-after { color: var(--ok); }
.diff-before::before { content: '\2212 '; font-weight: 700; }
.diff-after::before { content: '+ '; font-weight: 700; }

.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.step.done { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.step.current { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.login { max-width: 420px; margin: 8vh auto; }
.empty { padding: 24px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { color: var(--muted); padding: 16px 0; }
.token-box { word-break: break-all; }
