/* Admin console styles (gateway-aligned red/dark theme). UI-SPEC tokens: 4 font sizes (14/16/20/28), 2 weights (400/600), spacing multiples of 4. */
:root:not([data-theme=dark]), :root[data-theme="light"] {
  --pico-font-size: 16px;
  --pico-line-height: 1.5;
  --pico-font-weight: 400;
  --pico-spacing: 16px;
  --pico-block-spacing-vertical: 24px;
  --pico-block-spacing-horizontal: 16px;
  --pico-form-element-spacing-vertical: 8px;
  --pico-form-element-spacing-horizontal: 16px;
  --pico-border-radius: 4px;
  --pico-background-color: #ffffff;
  --pico-color: #1f2933;
  --pico-muted-color: #52606d;
  --pico-primary: #e11d2e;
  --pico-primary-background: #e11d2e;
  --pico-primary-border: #e11d2e;
  --pico-primary-underline: rgba(225, 29, 46, 0.5);
  --pico-primary-hover: #b91c1c;
  --pico-primary-hover-background: #b91c1c;
  --pico-primary-hover-border: #b91c1c;
  --pico-primary-hover-underline: #b91c1c;
  --pico-primary-focus: rgba(225, 29, 46, 0.35);
  --pico-primary-inverse: #ffffff;
  --pico-secondary: #52606d;
  --pico-secondary-background: #52606d;
  --pico-secondary-hover-background: #3e4a55;
  --pico-secondary-underline: rgba(82, 96, 109, 0.5);
  --pico-table-row-stripped-background-color: #f3f5f7;
  --admin-surface: #f3f5f7;
  --admin-accent: #e11d2e;
  --admin-chrome: #111111;
  --admin-chrome-text: #f4f4f5;
  --admin-chrome-muted: #a1a1aa;
  --admin-chrome-hover: rgba(255, 255, 255, 0.08);
  --admin-destructive: #c62828;
  --admin-muted: #52606d;
  --admin-text: #1f2933;
}

body {
  font-size: 16px;
  font-weight: 400;
  background: #ffffff;
  color: var(--admin-text);
}

h1, h2 { font-weight: 600; line-height: 1.2; }
h1 { font-size: 20px; }
h2 { font-size: 20px; }
h3, h4, h5, h6 { font-size: 16px; font-weight: 600; }
strong, b, th, label, summary { font-weight: 600; }
th, label, nav a { font-size: 14px; }
small { font-size: 14px; }

:where(a, button, input, select, textarea, summary, [role="button"]):focus-visible {
  outline: 2px solid var(--admin-accent);
  outline-offset: 2px;
}
.shell-nav a:focus-visible, .shell > .shell-header :focus-visible { outline-color: #ffffff; }

.muted { color: var(--admin-muted); font-size: 16px; font-weight: 400; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: inherit; }
.accent-link { color: var(--admin-accent); }
.overflow-auto { overflow: auto; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: #ffffff;
  padding: 8px 16px;
  z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

/* Shell */
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "nav main";
  min-height: 100vh;
}
.shell-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 32px;
  background: var(--admin-surface);
  border-bottom: 1px solid #d9dee3;
}
.shell > .shell-header {
  padding: 12px 24px;
  background: var(--admin-chrome);
  border-bottom: 0;
  color: var(--admin-chrome-text);
}
.shell-brand { font-size: 20px; font-weight: 600; margin: 0; }
/* Brand wordmark: deliberate 700 weight exception to the 400/600 token to match the gateway. */
.shell > .shell-header .shell-brand {
  color: #ffffff;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 16px;
  font-stretch: condensed;
  font-family: "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
}
.shell-user { display: flex; align-items: center; gap: 16px; }
.shell > .shell-header .shell-user .muted { color: #ffffff; font-size: 14px; }
.shell-user form { margin: 0; }
.shell-user button { margin: 0; width: auto; }
.role-pill { display: inline-block; font-size: 12px; font-weight: 600; line-height: 1.4; padding: 2px 8px; border-radius: 4px; }
.role-pill-admin { background: #e11d2e; color: #ffffff; }
.role-pill-approver { background: #3f3f46; color: #f4f4f5; }
.link-button {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  width: auto;
  box-shadow: none;
  color: inherit;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  text-decoration: none;
}
.link-button:hover, .link-button:focus { text-decoration: underline; background: transparent; box-shadow: none; }
.shell > .shell-header .link-button { color: #ffffff; }
.shell-nav {
  grid-area: nav;
  background: var(--admin-chrome);
  padding: 16px 0;
  border-right: 0;
}
/* Pico styles nav and nav ul as a centred horizontal flex row; the sidebar is a vertical list. */
.shell-nav { display: block; overflow: visible; }
.shell-nav ul, .shell-nav ul:first-of-type { display: flex; flex-direction: column; align-items: stretch; list-style: none; margin: 0; padding: 0; }
.shell-nav li { margin: 0; padding: 0; }
.shell-nav a {
  display: block;
  margin: 2px 8px;
  padding: 8px 12px;
  border-radius: 4px;
  border-left: 0;
  font-weight: 400;
  font-size: 14px;
  color: var(--admin-chrome-text);
  text-decoration: none;
}
.shell-nav a:hover { background: var(--admin-chrome-hover); color: #ffffff; }
.shell-nav a[aria-current="page"] {
  background: #e11d2e;
  color: #ffffff;
  font-weight: 600;
}
.shell-nav-group + .shell-nav-group { margin-top: 16px; }
.shell-nav-heading { margin: 0 0 4px; padding: 0 20px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--admin-chrome-muted); line-height: 1.4; }
.shell-main { grid-area: main; padding: 32px; }
.shell-main { min-width: 0; }
.shell-main > .container, main.container { max-width: none; padding: 0; margin: 0; }
.shell-main table { border: 1px solid #e4e4e7; }
.shell-main th { font-size: 14px; background: #fafafa; }
/* Compact controls inside table cells so the Actions column stays visible. */
.shell-main td .inline-form { display: inline-block; margin: 0 4px 4px 0; }
.shell-main td button, .shell-main td [role="button"] { width: auto; margin: 0; padding: 4px 10px; font-size: 14px; }
.shell-main td small { overflow-wrap: anywhere; }

@media (max-width: 1023px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "nav"
      "main";
  }
  .shell-nav { border-right: 0; border-bottom: 0; padding: 8px 0; }
  .shell-nav a { margin: 2px 4px; }
  .shell-nav ul, .shell-nav ul:first-of-type { flex-direction: row; flex-wrap: wrap; }
  .shell-nav-heading { display: none; }
  .shell-nav-group + .shell-nav-group { margin-top: 0; }
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  border: 0;
  line-height: 1.5;
}
.badge-allowed { color: #1b7f3b; background: #e6f4ea; }
.badge-denied { color: #8a5a00; background: #fff4db; }
.badge-failed { color: #c62828; background: #fdecea; }
.badge-caution { color: #8a5a00; background: #fff4db; }
.badge-neutral { color: #1f2933; background: #e4e7eb; }

/* Buttons */
button.destructive, .destructive {
  --pico-background-color: #ffffff;
  --pico-border-color: #b91c1c;
  --pico-color: #b91c1c;
  border-color: #b91c1c;
  color: #b91c1c;
}
button.destructive {
  background-color: #ffffff;
  border: 1px solid #b91c1c;
}
button.destructive:hover { background-color: #fef2f2; border-color: #991b1b; color: #991b1b; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > * { margin-left: 8px; }

/* Secret reveal */
.secret-panel {
  background: var(--admin-surface);
  border: 1px solid #d9dee3;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 24px;
}
.secret-box {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  background: #ffffff;
  border: 1px solid #52606d;
  border-radius: 4px;
  padding: 8px 16px;
  word-break: break-all;
  user-select: all;
}
.secret-warning { font-weight: 600; margin: 8px 0; }

/* Filter bar */
.filter-bar {
  background: var(--admin-surface);
  padding: 16px;
  border-radius: 4px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}
.filter-bar > * { margin: 0; }

/* Forms */
.field { margin-bottom: 16px; }
.field-helper { color: var(--admin-muted); display: block; margin-top: 4px; }
.field-error { color: var(--admin-destructive); display: block; margin-top: 4px; font-weight: 600; font-size: 14px; }

/* Confirm panel */
details.confirm-panel { display: inline-block; text-align: left; }
details.confirm-panel > summary { display: inline-block; cursor: pointer; color: var(--admin-destructive); list-style: none; }
details.confirm-panel > summary::-webkit-details-marker { display: none; }
details.confirm-panel > summary::after { display: none; }
.confirm-body {
  background: var(--admin-surface);
  border: 1px solid #d9dee3;
  border-radius: 4px;
  padding: 16px;
  margin-top: 8px;
  max-width: 480px;
  white-space: normal;
}
.confirm-body h2 { font-size: 16px; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions button { margin: 0; width: auto; }

/* Table pagination */
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.pagination .pager { display: flex; gap: 16px; }
.empty-state { padding: 24px 0; }

/* Flash and banners */
.flash {
  background: var(--admin-surface);
  border-left: 4px solid #1b7f3b;
  padding: 8px 16px;
  margin-bottom: 24px;
}
.flash-error { border-left-color: #c62828; background: #fdecea; color: #c62828; }
.banner { padding: 8px 16px; border-radius: 4px; margin-bottom: 16px; background: var(--admin-surface); }
.banner-error { background: #fdecea; color: #c62828; border-left: 4px solid #c62828; }
.banner-warning { background: #fff8e1; border-left: 4px solid #b26a00; }
.banner-info { border-left: 4px solid #52606d; }

/* Login */
.login-page { max-width: 480px; margin: 0 auto; padding-top: 64px; }
.login-page h1 { font-size: 28px; font-weight: 600; line-height: 1.2; }

[aria-busy="true"] { opacity: 0.7; }

.tag-chip {
  display: inline-block;
  margin-right: 0.25rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: #1f2933;
  background: #e4e7eb;
}
button.htmx-request { cursor: progress; opacity: 0.6; }

/* Requests */
.plan-box {
  border: 1px solid #d9dee3;
  background: var(--admin-surface);
  padding: 16px;
  border-radius: 4px;
  margin-bottom: 24px;
}
.plan-box header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.plan-box dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0 0 16px; }
.plan-box dt { font-weight: 600; }
.plan-box dd { margin: 0; }
.plan-box ol { margin: 0; padding-left: 24px; }
.timeline { list-style: none; margin: 0 0 24px; padding: 0; }
.timeline li { border-left: 4px solid #d9dee3; padding: 0 0 16px 16px; }
.timeline .timeline-label { font-size: 14px; font-weight: 600; display: block; }
.timeline .timeline-time { font-weight: 400; color: #52606d; }
.step-log td.mono { word-break: break-all; }
.row-note { color: #52606d; }
.from-upstream { background: #F3F5F7; border-left: 4px solid #52606D; padding: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Approval page (no admin nav) */
.approval-shell { max-width: 960px; margin: 0 auto; padding: 0 16px 48px; }
.approval-shell .shell-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 0; }
.approval-main { padding-top: 24px; }
.notice-card { background: var(--admin-surface); border: 1px solid #d9dee3; border-radius: 4px; padding: 24px; margin-bottom: 24px; }
.notice-card h1 { font-size: 28px; font-weight: 600; line-height: 1.2; }
.decision-bar { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.decision-bar details.decision-accept > summary { color: var(--admin-accent); }
.decision-bar details.decision-reject > summary { color: var(--admin-destructive); }
.interstitial { max-width: 480px; margin: 0 auto; padding-top: 64px; }
.interstitial h1 { font-size: 28px; font-weight: 600; line-height: 1.2; }

/* ===== Policy workflow diagram (quick 261013-vwk) ===== */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.policy-flow { margin: 8px 0 24px; overflow-x: auto; background: #ffffff; border: 1px solid #e4e4e7; border-radius: 6px; padding: 8px; }
.policy-flow-svg { width: 100%; max-width: 820px; height: auto; display: block; }
.policy-flow-details { margin-bottom: 8px; }
.policy-flow-details > summary { cursor: pointer; padding: 8px 0; }
.flow-node rect.flow-box { fill: #ffffff; stroke-width: 1.5; }
.flow-node .flow-title { font-size: 13px; font-weight: 600; }
.flow-node .flow-sub { font-size: 11px; fill: var(--admin-muted); }
.flow-node .flow-glyph { font-size: 14px; font-weight: 700; }
.flow-node-start rect.flow-box, .flow-node-process rect.flow-box { stroke: #2563eb; }
.flow-node-start .flow-icon, .flow-node-process .flow-icon { fill: #eff6ff; }
.flow-node-start .flow-title, .flow-node-process .flow-title, .flow-node-start .flow-glyph, .flow-node-process .flow-glyph { fill: #2563eb; }
.flow-node-review rect.flow-box { stroke: #d97706; }
.flow-node-review .flow-icon { fill: #fff7ed; }
.flow-node-review .flow-title, .flow-node-review .flow-glyph { fill: #d97706; }
.flow-node-done rect.flow-box { stroke: #1b7f3b; }
.flow-node-done .flow-icon { fill: #e6f4ea; }
.flow-node-done .flow-title, .flow-node-done .flow-glyph { fill: #1b7f3b; }
.flow-node-danger rect.flow-box { stroke: var(--admin-destructive); }
.flow-node-danger .flow-icon { fill: #fdecea; }
.flow-node-danger .flow-title, .flow-node-danger .flow-glyph { fill: var(--admin-destructive); }
.flow-node-warning rect.flow-box { stroke: #8a5a00; }
.flow-node-warning .flow-icon { fill: #fff4db; }
.flow-node-warning .flow-title, .flow-node-warning .flow-glyph { fill: #8a5a00; }
.flow-node-muted rect.flow-box { stroke: var(--admin-muted); }
.flow-node-muted .flow-icon { fill: #e4e7eb; }
.flow-node-muted .flow-title, .flow-node-muted .flow-glyph { fill: var(--admin-muted); }
.flow-edge { stroke: #9aa5b1; stroke-width: 1.5; fill: none; }
.flow-arrow { fill: #9aa5b1; }
.flow-pill-text { fill: #ffffff; font-size: 11px; font-weight: 600; }
.flow-pill-dark { fill: #3f3f46; }
.flow-pill-green { fill: #1b7f3b; }
.flow-pill-red { fill: var(--admin-accent); }
.flow-pill-amber { fill: #b26a00; }
.flow-pill-neutral { fill: #52606d; }

/* Page-level tabs (Policies / Example), same look as the gateway: red underline on the active tab. */
.page-tabs { display: flex; gap: 4px; border-bottom: 1px solid #e4e4e7; margin: 0 0 16px; }
.page-tabs a { padding: 8px 16px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--admin-muted); text-decoration: none; font-weight: 600; }
.page-tabs a:hover { color: var(--admin-text); }
.page-tabs a[aria-current="page"] { color: var(--admin-accent); border-bottom-color: var(--admin-accent); }

/* Query log: long SQL wraps inside the cell and never widens the page. */
.sql-cell { max-width: 360px; overflow-wrap: anywhere; }
.sql-cell summary { cursor: pointer; font-size: 13px; }
.sql-cell pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 0; padding: 8px; font-size: 12px; max-height: 320px; overflow: auto; }
