/* PlanOut console. All colours are tokens on :root; dark mode redefines them
   (data-theme set by /assets/theme.js, with a media-query fallback). */
:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --fg: #171a21;
  --muted: #565d6b;
  --line: #d6dae3;
  --accent: #1d4ed8;
  --accent-fg: #ffffff;
  --accent-soft: #e4ecff;
  --focus: #1d4ed8;
  --ok: #14632b;
  --ok-bg: #dff3e6;
  --warn: #7a4300;
  --warn-bg: #fcebc8;
  --bad: #a3180f;
  --bad-bg: #fde4e1;
  --info: #1b45a8;
  --info-bg: #e1eaff;
  --neutral: #4a5160;
  --neutral-bg: #e8ebf1;
  --danger: #b42318;
  --danger-fg: #ffffff;
  --seg-online: #1f9d4d;
  --seg-offline: #8a93a5;
  --seg-failed: #d92d20;
  --seg-pending: #3b6fe0;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 22%);
  --radius: 10px;
  --radius-sm: 6px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1015;
  --surface: #171a21;
  --surface-2: #1f232c;
  --fg: #e9ebf0;
  --muted: #a3a9b7;
  --line: #2b303b;
  --accent: #7ba3ff;
  --accent-fg: #07102a;
  --accent-soft: #1b2748;
  --focus: #9dbcff;
  --ok: #6fd994;
  --ok-bg: #143322;
  --warn: #f2b955;
  --warn-bg: #3a2b0c;
  --bad: #ff948b;
  --bad-bg: #421a17;
  --info: #9bb8ff;
  --info-bg: #1b2748;
  --neutral: #b4bac8;
  --neutral-bg: #262b36;
  --danger: #ff8479;
  --danger-fg: #2a0705;
  --seg-online: #4cc77a;
  --seg-offline: #7b8394;
  --seg-failed: #ff6f63;
  --seg-pending: #6f9bff;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 60%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0e1015;
    --surface: #171a21;
    --surface-2: #1f232c;
    --fg: #e9ebf0;
    --muted: #a3a9b7;
    --line: #2b303b;
    --accent: #7ba3ff;
    --accent-fg: #07102a;
    --accent-soft: #1b2748;
    --focus: #9dbcff;
    --ok: #6fd994;
    --ok-bg: #143322;
    --warn: #f2b955;
    --warn-bg: #3a2b0c;
    --bad: #ff948b;
    --bad-bg: #421a17;
    --info: #9bb8ff;
    --info-bg: #1b2748;
    --neutral: #b4bac8;
    --neutral-bg: #262b36;
    --danger: #ff8479;
    --danger-fg: #2a0705;
    --seg-online: #4cc77a;
    --seg-offline: #7b8394;
    --seg-failed: #ff6f63;
    --seg-pending: #6f9bff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 22px; line-height: 1.25; margin: 0 0 16px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.spacer { flex: 1; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: 8px; top: -48px; z-index: 100; background: var(--accent); color: var(--accent-fg); padding: 8px 12px; border-radius: var(--radius-sm); }
.skip:focus { top: 8px; }
#main:focus { outline: none; }

/* ── Shell ───────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.shell.signed-out { grid-template-columns: minmax(0, 1fr); }
.shell.signed-out .sidebar { display: none; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 16px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px; }
.brand small { font-weight: 500; color: var(--muted); }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-weight: 800; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); color: var(--fg); text-decoration: none; font-weight: 500;
}
#nav a:hover { background: var(--surface-2); }
#nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  min-height: 52px;
}
main { padding: 24px; max-width: 1280px; width: 100%; }
.who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.env-wrap { position: relative; }
.env-badge {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 10px;
  border-radius: 999px; background: var(--warn-bg); color: var(--warn); border: 1px solid transparent;
}
button.env-badge { cursor: pointer; border-color: currentColor; }
.env-badge .icon { width: 14px; height: 14px; }
.menu {
  position: absolute; left: 0; top: calc(100% + 6px); min-width: 240px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 4px;
}
.menu-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--fg); text-decoration: none; font-weight: 600;
}
.menu-item small { margin-left: auto; font-weight: 400; }
.menu-item .ph { width: 18px; }
a.menu-item:hover, a.menu-item:focus-visible { background: var(--surface-2); }
.menu-item.current { color: var(--ok); }

/* ── Controls ────────────────────────────────────────────────────────── */
button, input, select, textarea { font: inherit; color: inherit; }
.btn, .btn-icon {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  border-radius: var(--radius-sm); padding: 6px 12px; cursor: pointer; text-decoration: none; font-weight: 500;
  min-height: 34px;
}
.btn:hover:not([disabled]), .btn-icon:hover:not([disabled]) { background: var(--surface-2); }
.btn.small { padding: 3px 10px; min-height: 28px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover:not([disabled]) { filter: brightness(1.08); background: var(--accent); }
.btn.danger { background: var(--danger); color: var(--danger-fg); border-color: var(--danger); }
.btn.danger:hover:not([disabled]) { filter: brightness(1.08); background: var(--danger); }
.btn.danger-outline { color: var(--bad); border-color: var(--bad); }
.btn-icon { padding: 0; width: 34px; }
button[disabled] { opacity: 0.55; cursor: not-allowed; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; min-height: 34px;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.icon { flex: none; }

/* ── Layout bits ─────────────────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head h1 { margin-bottom: 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lead { max-width: 72ch; }
.card, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.panel { margin-bottom: 16px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sub-h { margin-top: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; margin: 4px 0; overflow-wrap: anywhere; }
.stat.bad .stat-value { color: var(--bad); }
.stat.good .stat-value { color: var(--ok); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.chip.info { color: var(--info); background: var(--info-bg); border-color: transparent; font-weight: 600; }
.chip.muted { color: var(--muted); }
.chip.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.login { max-width: 420px; margin: 8vh auto; text-align: center; }
.login h1 { margin-bottom: 8px; }
.banner { border: 1px solid var(--bad); background: var(--bad-bg); color: var(--bad); border-radius: var(--radius-sm); padding: 10px 14px; margin: 0 0 16px; }
.back { text-decoration: none; }
.back::before { content: "\2190"; margin-right: 6px; }
.cycle-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 8px 0 12px; }
.toolbar label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 600; }
.toolbar .search { flex: 1 1 220px; }
.toolbar .search input { width: 100%; }
#f-count { align-self: center; }

/* ── Pills / status ──────────────────────────────────────────────────── */
.pill { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 600; background: var(--neutral-bg); color: var(--neutral); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.activity { font-size: 12px; color: var(--info); margin-top: 2px; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.dt { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel .dt { box-shadow: none; }
.table-wrap { overflow: auto; max-height: 68vh; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; }
table.data thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); text-align: left;
  padding: 0; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 700; white-space: nowrap;
}
table.data thead th:not(:has(button)) { padding: 8px 12px; }
.sort-btn {
  display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: 0; border-radius: 0;
  padding: 8px 12px; cursor: pointer; font-weight: 700; text-align: left; min-height: 36px;
}
.sort-btn:hover { background: var(--line); }
.sort-ind { color: var(--muted); font-size: 10px; }
th[aria-sort="ascending"] .sort-ind, th[aria-sort="descending"] .sort-ind { color: var(--accent); }
.coltype { display: block; font-weight: 400; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
table.data td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
td.err { max-width: 360px; overflow-wrap: anywhere; color: var(--bad); font-size: 13px; }
td.host { overflow-wrap: anywhere; min-width: 190px; max-width: 260px; }
td.row-actions { white-space: nowrap; }
td.row-actions .btn + .btn { margin-left: 6px; }
.plink { font-weight: 600; text-decoration: none; }
.plink:hover { text-decoration: underline; }
.empty-row:hover td { background: transparent !important; }
.pager { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); justify-content: flex-end; flex-wrap: wrap; }
.pager-size { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-right: auto; }
.pager-size select { min-height: 30px; padding: 2px 6px; }
.pager-label { color: var(--muted); min-width: 90px; text-align: right; }
.pager .btn-icon { width: 32px; min-height: 30px; }

/* ── States, skeletons ───────────────────────────────────────────────── */
.state { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 16px; text-align: center; }
.state .icon { width: 28px; height: 28px; color: var(--muted); }
.state.error .icon, .state.error strong { color: var(--bad); }
.skeleton {
  display: block; height: 12px; width: 70%; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton.wide { width: 90%; margin-top: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  animation: pop 0.18s ease-out;
}
.toast.ok { border-left-color: var(--seg-online); }
.toast.error { border-left-color: var(--seg-failed); }
.toast span { flex: 1; overflow-wrap: anywhere; }
.toast .btn-icon { width: 24px; min-height: 24px; border: 0; background: none; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* ── Charts ──────────────────────────────────────────────────────────── */
.status-chart { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut { width: 140px; height: 140px; transform: rotate(0deg); }
.donut circle { stroke-width: 5; }
.donut-track { stroke: var(--surface-2); }
.seg-online { stroke: var(--seg-online); }
.seg-offline { stroke: var(--seg-offline); }
.seg-failed { stroke: var(--seg-failed); }
.seg-pending { stroke: var(--seg-pending); }
.donut-total { fill: var(--fg); font-size: 8px; font-weight: 700; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; min-width: 150px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend strong { margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-online { background: var(--seg-online); }
.dot-offline { background: var(--seg-offline); }
.dot-failed { background: var(--seg-failed); }
.dot-pending { background: var(--seg-pending); }
.hosts { display: grid; gap: 10px; }
.host-line { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.hbar { grid-column: 1 / -1; width: 100%; height: 6px; }
.hbar-track { fill: var(--surface-2); }
.hbar-fill { fill: var(--accent); }
.jobs { list-style: none; margin: 0; padding: 0; }
.jobs li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.jobs li:last-child { border-bottom: 0; }
.jobs .err { color: var(--bad); font-size: 13px; overflow-wrap: anywhere; }

/* ── Modal ───────────────────────────────────────────────────────────── */
dialog.modal {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--fg);
  box-shadow: var(--shadow-lg); width: min(480px, calc(100vw - 32px));
}
dialog.modal::backdrop { background: rgb(8 10 16 / 60%); }
dialog.modal h2 { margin: 0; padding: 18px 20px 0; font-size: 17px; }
.modal-body { padding: 12px 20px; display: grid; gap: 8px; overflow-wrap: anywhere; }
.modal-body p { margin: 0; }
.modal-proj { font-weight: 700; font-size: 15px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.field { display: grid; gap: 6px; font-weight: 600; }
.field input { width: 100%; }

/* ── Table browser ───────────────────────────────────────────────────── */
.browser { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.tables { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px; max-height: 80vh; overflow: auto; position: sticky; top: 68px; }
.tables h3 { padding: 0 8px 8px; color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: 0.05em; }
.table-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.table-list li > .skeleton { margin: 10px 8px; }
.table-item { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; border-radius: var(--radius-sm); padding: 7px 8px; cursor: pointer; text-align: left; }
.table-item:hover { background: var(--surface-2); }
.table-item[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.table-item .tname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-item[aria-current="true"] .count { color: inherit; }
.browser-main { min-width: 0; }
.note { margin: 0 0 8px; }
td.cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: copy; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
td.cell.nul { color: var(--muted); font-style: italic; }
td.cell:focus-visible { outline-offset: -2px; background: var(--accent-soft); }
td.cell:hover { background: var(--accent-soft) !important; }
textarea.sql { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 13px; resize: vertical; }
.sql-actions { display: flex; align-items: center; gap: 12px; margin: 8px 0; flex-wrap: wrap; }
.inline-error { border: 1px solid var(--bad); background: var(--bad-bg); color: var(--bad); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 12px; overflow-x: auto; }
  .brand { display: none; }
  #nav { flex-direction: row; }
  #nav a { white-space: nowrap; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; position: static; }
  main { padding: 16px; }
  .grid-2, .browser { grid-template-columns: minmax(0, 1fr); }
  .tables { position: static; max-height: 220px; }
  .who, #status { display: none; }
  .table-wrap { max-height: 60vh; }
}
@media (max-width: 720px) {
  table.data { min-width: 760px; }
  .grid table.data { min-width: 0; }
  td.err { max-width: 200px; }
  .pager { justify-content: center; }
  .pager-size { margin-right: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
