/* HAA Owner Studio web UI (remote and local recovery). WCAG 2.2 AA:
   AA contrast in both color schemes, visible 3px focus indicators with 3:1
   contrast, targets of at least 24 by 24 CSS pixels, reflow to 320 CSS
   pixels, no sticky or fixed UI that could hide focus, reduced motion. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #16202b;
  --muted: #4a5664;
  --line: #8a96a3;
  --soft-line: #d5dbe2;
  --brand: #0b3d6e;
  --brand-ink: #ffffff;
  --accent: #0a5cad;
  --accent-ink: #ffffff;
  --ok: #135f2a;
  --ok-bg: #e5f4ea;
  --warn: #6b4100;
  --warn-bg: #fff3d6;
  --bad: #a4161a;
  --bad-bg: #fde8e8;
  --info-bg: #e8f0fb;
  --focus: #b3470b;
  --focus-on-brand: #ffd08a;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --panel: #1a2129;
    --ink: #e8edf2;
    --muted: #b3bdc8;
    --line: #7b8795;
    --soft-line: #36414d;
    --brand: #0f2740;
    --brand-ink: #e8edf2;
    --accent: #8cbcf2;
    --accent-ink: #0b1622;
    --ok: #86d9a0;
    --ok-bg: #173323;
    --warn: #f3c56b;
    --warn-bg: #3a2c10;
    --bad: #ffa3a3;
    --bad-bg: #3d1a1c;
    --info-bg: #182a40;
    --focus: #ffb070;
    --focus-on-brand: #ffb070;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { font-size: 100%; scroll-padding: 16px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-wrap: anywhere; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
iframe:focus, iframe:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--panel); color: var(--accent); padding: 10px 14px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* header */
header.top { background: var(--brand); color: var(--brand-ink); padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
header.top :focus-visible { outline-color: var(--focus-on-brand); }
.brand { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.brand .name { font-weight: 700; font-size: 1.1rem; margin: 0; }
.mode { border: 1px solid currentColor; border-radius: 99px; padding: 1px 10px; font-size: .85rem; font-weight: 600; }
.site-status { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; font-size: .9rem; }
.site-status div { display: flex; flex-wrap: wrap; gap: 4px; }
.site-status dt { font-weight: 600; }
.site-status dd { margin: 0; }
.user { margin: 0 0 0 auto; font-size: .9rem; }

/* primary navigation */
nav.primary { background: var(--panel); border-bottom: 1px solid var(--soft-line); padding: 6px 12px; }
nav.primary ul { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; }
nav.primary a { display: inline-block; padding: 8px 12px; min-height: 40px; border-radius: var(--radius); color: var(--ink); text-decoration: none; }
nav.primary a:hover { background: var(--info-bg); }
nav.primary a[aria-current="page"] { background: var(--info-bg); font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

main { padding: 16px 20px 32px; max-width: 1500px; margin: 0 auto; min-width: 0; }
h1 { font-size: 1.5rem; margin: 4px 0 12px; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 18px 0 8px; }
h3 { font-size: 1.05rem; margin: 14px 0 6px; }
p { margin: 6px 0; }
.lead { color: var(--muted); max-width: 70ch; }

.panel { background: var(--panel); border: 1px solid var(--soft-line); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; min-width: 0; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.notice { border-left: 5px solid var(--accent); background: var(--info-bg); padding: 10px 14px; border-radius: 4px; margin: 10px 0; }
.notice.ok { border-color: var(--ok); background: var(--ok-bg); }
.notice.warn { border-color: var(--warn); background: var(--warn-bg); }
.notice.bad { border-color: var(--bad); background: var(--bad-bg); }
.notice > h2, .notice > h3 { margin-top: 0; }

/* buttons, links as buttons, form controls */
button, .button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 40px; min-width: 40px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; text-align: left; }
button:hover, .button:hover { background: var(--info-bg); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--brand); color: #ffffff; }
button.danger { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
button[aria-disabled="true"], button:disabled { background: var(--bg); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
label, .label { font-weight: 600; display: block; margin: 10px 0 4px; }
.hint { font-size: .9rem; color: var(--muted); margin: 2px 0 6px; }
.error-text { color: var(--bad); font-weight: 600; margin: 4px 0; }
input[type="text"], input[type="search"], input[type="url"], input[type="email"], select, textarea { font: inherit; width: 100%; max-width: 70ch; padding: 8px 10px; min-height: 40px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); }
textarea { min-height: 9em; resize: vertical; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border: 2px solid var(--bad); }
input[type="checkbox"] { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; margin: 10px 0; }
.check label { margin: 0; }
.counter { font-size: .85rem; color: var(--muted); }

/* owner flows: add, publish, unpublish, retire */
.flow-form { max-width: 80ch; }
.field { margin: 0 0 14px; }
.optional { font-weight: 400; color: var(--muted); }
.subform { border-left: 4px solid var(--soft-line); padding-left: 14px; margin: 0 0 14px; }
input[type="file"] { font: inherit; display: block; width: 100%; max-width: 70ch; min-height: 40px; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); }
input[type="file"][aria-invalid="true"] { border: 2px solid var(--bad); }
fieldset.radios { border: 1px solid var(--soft-line); border-radius: var(--radius); padding: 8px 14px 6px; margin: 0 0 14px; min-width: 0; }
fieldset.radios[aria-invalid="true"] { border: 2px solid var(--bad); }
fieldset.radios legend { font-weight: 600; padding: 0 6px; }
input[type="radio"] { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--accent); }
.check.radio { font-weight: 400; margin: 8px 0; }
.check.radio label { font-weight: 600; }
.check.radio .hint { margin: 2px 0 0; }
.route-preview { margin: 0 0 14px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--panel); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions .button { min-height: 32px; padding: 4px 10px; }
button.linklike { background: none; border: 0; padding: 2px 0; min-height: 24px; min-width: 24px; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-weight: 600; text-align: left; }
button.linklike:hover { background: none; text-decoration-thickness: 2px; }
.notice.bad ul { margin: 6px 0 0; padding-left: 20px; }
header.top button.signout { background: transparent; color: var(--brand-ink); border-color: currentColor; min-height: 32px; padding: 4px 12px; }
header.top button.signout:hover { background: rgba(255, 255, 255, .15); }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; font-weight: 600; border: 1px solid var(--line); background: var(--bg); color: var(--ink); white-space: nowrap; }
.badge.scope-shared { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.badge.scope-own { background: var(--info-bg); color: var(--ink); border-color: var(--accent); }
.badge.test-only { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.badge.changed { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }

/* choose */
.choices { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); list-style: none; padding: 0; margin: 10px 0; }
.choices a { display: block; padding: 12px 14px; background: var(--panel); border: 1px solid var(--soft-line); border-radius: var(--radius); color: var(--ink); text-decoration: none; min-height: 44px; }
.choices a:hover { border-color: var(--accent); background: var(--info-bg); }
.choices .t { font-weight: 700; display: block; color: var(--accent); }
.choices .d { font-size: .9rem; color: var(--muted); }
.list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
.list li { background: var(--panel); border: 1px solid var(--soft-line); border-radius: var(--radius); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.list .grow { flex: 1 1 220px; min-width: 0; }
.list .route { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; color: var(--muted); display: block; }

/* editor */
.editor { display: grid; gap: 16px; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); align-items: start; }
.identity { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0 0 12px; }
.identity div { display: flex; gap: 6px; flex-wrap: wrap; }
.identity dt { font-weight: 600; }
.identity dd { margin: 0; }
.sections h2 { margin-top: 0; }
.sections h3 { font-size: .95rem; margin: 12px 0 4px; }
.sections ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sections button { width: 100%; justify-content: space-between; flex-wrap: wrap; text-align: left; }
.sections button[aria-current="true"] { border: 2px solid var(--accent); background: var(--info-bg); font-weight: 700; }
.field-panel { margin-bottom: 16px; }
.field-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0; }
.affected { margin: 4px 0; padding-left: 20px; }

/* preview */
.preview .toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.preview .toolbar button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.unsaved { display: inline-block; background: var(--warn-bg); color: var(--warn); border: 2px dashed var(--warn); border-radius: var(--radius); padding: 4px 10px; font-weight: 600; }
.frame-outer { width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #ffffff; }
.frame-scaler { position: relative; overflow: hidden; margin: 0 auto; }
.frame-scaler iframe { display: block; border: 0; background: #ffffff; transform-origin: 0 0; width: 1280px; height: 1000px; }

/* tables (stacked on narrow screens, see the media query below) */
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
caption { text-align: left; font-weight: 600; padding: 4px 0; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--soft-line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); }
td.old { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }

/* progress */
ol.steps { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
ol.steps li { padding: 6px 10px; border: 1px solid var(--soft-line); border-radius: 4px; background: var(--panel); }
ol.steps li[data-state="done"] { border-color: var(--ok); }
ol.steps li[data-state="running"] { border-color: var(--accent); background: var(--info-bg); font-weight: 600; }
ol.steps li[data-state="stopped"] { border-color: var(--bad); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); max-width: min(640px, calc(100vw - 32px)); width: 100%; padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin-top: 0; }

footer.help { border-top: 1px solid var(--soft-line); background: var(--panel); padding: 12px 20px; margin-top: 24px; }
footer.help details { max-width: 80ch; }
footer.help summary { cursor: pointer; font-weight: 600; min-height: 32px; padding: 4px 0; }

@media (max-width: 900px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  main { padding: 12px; }
  .user { margin: 0; }
}
@media (max-width: 640px) {
  table, thead, tbody, tr, th, td, caption { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tr { border: 1px solid var(--soft-line); border-radius: 4px; margin: 0 0 8px; padding: 4px 0; }
  td { border: 0; padding: 4px 8px; }
  td[data-label]::before { content: attr(data-label) ": "; font-weight: 600; color: var(--muted); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
