/* Octave admin: shell and components. The admin invents no colour, font or size: it reads
   the tokens of the "studio" site theme (/_octave/site/themes/studio.css: --c-* colours,
   --s-* spacing, --t-* type scale, --r-* radii, --shadow). The font stack and .o-vh come
   from /_octave/common.css. No colour literal anywhere (admin-tests/unit/lint.test.js).

   Colour scheme without script (no flash before main.js runs): index.html puts the dark
   palette on <html> (palette-graphite) and the light one on <body> (palette-fresh); under
   a dark system scheme body stops overriding and inherits html's palette. Every admin
   element lives in body, dialogs included. */
:root {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  body.palette-fresh {
    color-scheme: dark;
    --c-bg: inherit;
    --c-bg-alt: inherit;
    --c-text: inherit;
    --c-muted: inherit;
    --c-primary: inherit;
    --c-on-primary: inherit;
    --c-accent: inherit;
    --c-on-accent: inherit;
    --c-border: inherit;
    --c-focus: inherit;
  }
}

/* ---------- Document ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: var(--t-base);
  line-height: 1.5;
  overflow-wrap: break-word;
}

/* Component rules set display; the hidden attribute must still win. */
[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  margin: 0 0 var(--s-3);
  font-weight: var(--fw-heading);
  line-height: var(--lh-heading);
}

h1 {
  font-size: var(--t-xl);
}

h2 {
  font-size: var(--t-lg);
}

h3 {
  font-size: var(--t-base);
}

p {
  margin: 0 0 var(--s-3);
}

a {
  color: inherit;
  text-decoration-color: var(--c-primary);
  text-underline-offset: 0.18em;
}

/* ---------- App frame ---------- */

.o-skip {
  position: absolute;
  left: var(--s-2);
  top: var(--s-2);
  z-index: 10;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--c-primary);
  color: var(--c-on-primary);
  transform: translateY(-200%);
}

.o-skip:focus {
  transform: none;
}

.o-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
}

.o-brand {
  font-weight: var(--fw-heading);
  font-size: var(--t-lg);
}

.o-topbar-end {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
}

.o-account-email {
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The frame fills the viewport whatever the top bar's height (it wraps onto two lines
   at phone width): the body area takes the rest, so a short screen never scrolls. */
.o-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.o-body {
  display: grid;
  flex: 1 0 auto;
  grid-template-columns: 15rem minmax(0, 1fr);
}

.o-sidenav {
  padding: var(--s-4) var(--s-2);
  border-right: 1px solid var(--c-border);
  background: var(--c-bg-alt);
}

.o-nav-list {
  display: grid;
  gap: var(--s-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.o-nav-link {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  text-decoration: none;
}

.o-nav-link:hover {
  background: var(--c-bg);
}

.o-nav-link[aria-current="page"] {
  background: var(--c-primary);
  color: var(--c-on-primary);
}

.o-main {
  min-width: 0;
  padding: var(--s-5) var(--s-4);
}

.o-main:focus {
  outline: none;
}

.o-main-bare {
  max-width: var(--w-narrow);
  margin-inline: auto;
  padding-top: var(--s-7);
}

/* .o-topbar raises specificity over .o-btn's display. */
.o-topbar .o-nav-toggle {
  display: none;
}

/* Under 900 px the side navigation is a drawer under the top bar. */
@media (max-width: 899.98px) {
  .o-topbar .o-nav-toggle {
    display: inline-flex;
  }

  .o-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .o-sidenav {
    display: none;
    border-right: 0;
    border-bottom: 1px solid var(--c-border);
  }

  .o-nav-open .o-sidenav {
    display: block;
  }
}

/* The page editor needs the width (three panes around a 1280 px preview): from 900 px
   too, its side navigation folds into the drawer the top bar toggle opens. */
@media (min-width: 900px) {
  [data-o-route="page_edit"] .o-topbar .o-nav-toggle {
    display: inline-flex;
  }

  [data-o-route="page_edit"] .o-body {
    grid-template-columns: minmax(0, 1fr);
  }

  [data-o-route="page_edit"] .o-sidenav {
    display: none;
    border-right: 0;
    border-bottom: 1px solid var(--c-border);
  }

  [data-o-route="page_edit"] .o-nav-open .o-sidenav {
    display: block;
  }
}

/* ---------- Buttons ---------- */

.o-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-4);
  border: 2px solid var(--c-primary);
  border-radius: var(--r-btn);
  background: var(--c-primary);
  color: var(--c-on-primary);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.o-btn-secondary {
  background: transparent;
  color: var(--c-text);
}

/* Only where a pointer really hovers (a phone keeps :hover on the last tapped button),
   and never on a pressed toggle, which keeps its filled look (filters, ranges). */
@media (hover: hover) {
  .o-btn:not([aria-pressed="true"]):hover {
    background: var(--c-bg-alt);
    color: var(--c-text);
  }
}

.o-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Fields ---------- */

.o-field {
  display: grid;
  gap: var(--s-1);
  margin-bottom: var(--s-4);
}

.o-field-label {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-weight: 600;
  font-size: var(--t-sm);
}

.o-field-check {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: var(--s-2);
}

.o-field-check .o-field-error {
  grid-column: 1 / -1;
}

.o-input {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--c-muted);
  border-radius: var(--r-sm);
  background: var(--c-bg);
  color: var(--c-text);
  font: inherit;
}

textarea.o-input {
  resize: vertical;
}

.o-input[aria-invalid="true"] {
  border-width: 2px;
  border-color: var(--c-text);
}

.o-check {
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  accent-color: var(--c-primary);
}

.o-field-error {
  margin: 0;
  padding-left: var(--s-2);
  border-left: 3px solid var(--c-text);
  font-size: var(--t-sm);
  font-weight: 600;
}

.o-badge {
  display: inline-block;
  padding: 0 var(--s-2);
  border-radius: var(--r-sm);
  background: var(--c-accent);
  color: var(--c-on-accent);
  font-size: var(--t-sm);
  font-weight: 600;
  line-height: 1.5;
}

/* A row of form buttons (the dialog's own row is end-aligned with a top margin). */
.o-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

/* A row of buttons above the content it acts on (the state filters above the member
   list): unlike a form's last row it is followed by content, so it keeps it apart. */
.o-toolbar {
  margin-bottom: var(--s-3);
}

/* ---------- Dialog ---------- */

.o-dialog {
  width: min(32rem, calc(100vw - 2 * var(--s-4)));
  max-height: calc(100vh - 2 * var(--s-4));
  padding: var(--s-5);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
  color: var(--c-text);
  box-shadow: var(--shadow);
}

.o-dialog::backdrop {
  background: color-mix(in srgb, var(--c-text) 45%, transparent);
}

/* On a dark palette the text colour is light: darken with the background instead. */
@media (prefers-color-scheme: dark) {
  .o-dialog::backdrop {
    background: color-mix(in srgb, var(--c-bg) 75%, transparent);
  }
}

.o-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-5);
}

/* ---------- Toasts ---------- */

.o-toasts {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  left: var(--s-4);
  z-index: 20;
  display: grid;
  justify-items: end;
  gap: var(--s-2);
  pointer-events: none;
}

.o-toast {
  max-width: 28rem;
  margin: 0;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
  box-shadow: var(--shadow);
}

/* The toast stack lets the pointer through; a link in a toast (the published site's
   address) takes it. */
.o-toast a {
  pointer-events: auto;
}

.o-toast-error {
  border-width: 2px;
  border-color: var(--c-text);
  font-weight: 600;
}

/* ---------- Tabs ---------- */

.o-tablist {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--c-border);
}

.o-tab {
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-4);
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--c-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.o-tab[aria-selected="true"] {
  border-bottom-color: var(--c-primary);
  color: var(--c-text);
}

.o-tabpanel {
  padding-top: var(--s-4);
}

/* ---------- Menu button ---------- */

.o-menu-wrap {
  position: relative;
}

.o-menu {
  position: absolute;
  right: 0;
  top: calc(100% + var(--s-1));
  z-index: 15;
  min-width: 12rem;
  margin: 0;
  padding: var(--s-1);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
  box-shadow: var(--shadow);
  list-style: none;
}

.o-menu-item {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-3);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--c-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.o-menu-item:hover,
.o-menu-item:focus {
  background: var(--c-bg-alt);
}

/* A radio item shows its state, not only to assistive technology. */
.o-menu-item[aria-checked="true"] {
  font-weight: 600;
}

.o-menu-item[aria-checked="true"]::before {
  content: "✓ ";
}

.o-menu-sep {
  margin: var(--s-1) 0;
  border-top: 1px solid var(--c-border);
}

/* ---------- Second-factor setup ---------- */

/* The QR code of the TOTP secret: modules are SVG rects filled with the text colour on
   the ground colour (screens/totp.js puts palette-fresh on it: dark on light always). */
.o-qr {
  display: block;
  width: 14rem;
  max-width: 100%;
  height: auto;
  margin: 0 0 var(--s-4);
  border-radius: var(--r-sm);
  background: var(--c-bg);
  fill: var(--c-text);
}

/* ---------- Cards and lists ---------- */

/* Lists drawn as rows or cards carry no bullet or indent. */
.o-cards,
.o-plain-list {
  display: grid;
  gap: var(--s-3);
  margin: 0 0 var(--s-4);
  padding: 0;
  list-style: none;
}

/* Site cards side by side when there is room; .o-cards-list keeps one per row. */
.o-cards {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
}

.o-cards-list {
  grid-template-columns: minmax(0, 1fr);
}

.o-card {
  padding: var(--s-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
}

.o-card > :last-child {
  margin-bottom: 0;
}

/* A spaced list that keeps its bullets (the problems of a domain check): .o-plain-list
   alone drops them, which read as loose paragraphs. */
.o-plain-list.o-bullets {
  padding-inline-start: var(--s-5);
  list-style: disc;
}

/* The parts of a long form (site settings) stand apart from each other. */
.o-section {
  margin-bottom: var(--s-6);
}

/* ---------- Theme picker ---------- */

.o-theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.o-theme-card {
  display: grid;
  gap: var(--s-2);
  min-height: 2.75rem;
  padding: var(--s-2);
  border: 2px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
  color: var(--c-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.o-theme-card[aria-pressed="true"] {
  border-color: var(--c-primary);
  font-weight: 600;
}

.o-theme-card[aria-pressed="true"] > :last-child::before {
  content: "✓ ";
}

/* The swatch reads the --c-* and --f-* tokens of its own theme and palette classes
   (the site theme files), so its colours are the site's, never restated here. */
.o-swatch {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--f-heading);
  font-weight: var(--fw-heading);
}

.o-swatch-type {
  margin-right: auto;
  font-size: var(--t-lg);
}

.o-swatch-dot {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
}

.o-swatch-primary {
  background: var(--c-primary);
}

.o-swatch-accent {
  background: var(--c-accent);
}

/* ---------- Preview ---------- */

/* An iframe defaults to 300 x 150 px: give the home page preview the column's width. */
.o-preview-frame {
  display: block;
  width: 100%;
  height: 32rem;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-bg);
}

/* ---------- Page tree ---------- */

/* A nested level is indented along a rule, so the hierarchy shows without the tree's
   aria-level (.o-plain-list alone gives no indent and its bottom margin). */
.o-tree-group {
  margin: var(--s-3) 0 0;
  padding-left: var(--s-4);
  border-left: 1px solid var(--c-border);
}

/* The title takes the free width of its row, pushing path, badges and actions to the end. */
.o-tree-title {
  flex: 1 1 12rem;
}

/* A treeitem wraps its whole subtree: draw its focus ring on its own row only. */
.o-tree-item:focus-visible {
  outline: none;
}

.o-tree-item:focus-visible > .o-tree-row {
  outline: 3px solid var(--c-focus);
  outline-offset: 2px;
}

/* A menu item that is off (its label says why) does not look choosable. */
.o-menu-item[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Media library ---------- */

/* Thumbnails are 480 px derivatives of any aspect: a square crop keeps the tile grid
   (.o-theme-grid / .o-theme-card) even. */
.o-media-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-sm);
}

/* Media tiles sit in list items (the theme cards are grid items themselves): the item
   is a grid too, so each tile fills its cell and the columns stay even whatever the
   tile holds (a thumbnail, or only an icon and a name). */
.o-theme-grid > li {
  display: grid;
}

/* The upload drop target: a dashed frame that shows where files may be dropped, and
   the primary colour while they are dragged over it. */
.o-dropzone {
  margin-bottom: var(--s-4);
  padding: var(--s-4);
  border: 2px dashed var(--c-border);
  border-radius: var(--r-md);
}

.o-dropzone.o-drag-over {
  border-color: var(--c-primary);
}

/* ---------- Record tables (Domains) ---------- */

/* A table of DNS records. Wide: a table, in a frame that scrolls rather than widening
   the page. Relative: the visually hidden header text (.o-vh, absolute) stays inside
   the frame instead of widening the document from its place in the last column. The
   frame is a size container: narrow, the rows stack (below). */
.o-table-scroll {
  position: relative;
  container-type: inline-size;
  max-width: 100%;
  margin-bottom: var(--s-3);
  overflow-x: auto;
}

.o-table {
  width: 100%;
  border-collapse: collapse;
}

.o-table th,
.o-table td {
  padding: var(--s-2);
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: middle;
}

.o-table code {
  white-space: nowrap;
}

/* Narrow frame (a phone): one block per record, type and name on the first line, the
   value on its own wrapping line, then Copy, so value and button are always in view.
   The column headers are hidden visually as .o-vh does (a media rule cannot add the
   class); the caption and the explicit table roles stay for screen readers. */
@container (max-width: 40rem) {
  .o-table,
  .o-table tbody {
    display: block;
  }

  .o-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .o-table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: var(--s-1) var(--s-2);
    padding: var(--s-2) 0;
    border-bottom: 1px solid var(--c-border);
  }

  .o-table td {
    padding: 0;
    border-bottom: 0;
  }

  .o-table td:nth-child(n + 3) {
    grid-column: 1 / -1;
  }

  .o-table code {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

/* ---------- Bar chart (Statistics) ---------- */

/* The SVG of ui/barchart.js (bars filled with currentColor, no colour here): as wide as
   its .o-table-scroll frame and at least half a rem per day (--o-days), so a 90-day range
   scrolls in the frame on a phone instead of squeezing its bars or widening the page. */
.o-barchart {
  display: block;
  width: 100%;
  min-width: calc(var(--o-days, 1) * 0.5rem);
  height: 10rem;
}

/* The bar of the day still in progress is faded, as an off control is (.o-btn:disabled):
   a state, no colour; its label and the per-day table say "in progress" in words. */
.o-barchart .o-bar-partial {
  opacity: 0.5;
}

/* The chart's per-day figures (a <details>): spaced from what follows like the
   paragraphs around it, which a <details> is not by default. */
.o-barchart-details {
  margin-bottom: var(--s-4);
}

/* Stacked record tables (above) only reset their td cells: a row header (the day in the
   chart's per-day table) is reset the same way, so the row keeps one rule, not two. */
@container (max-width: 40rem) {
  .o-table th[scope="row"] {
    padding: 0;
    border-bottom: 0;
  }

  /* The chart's per-day rows: the day may wrap, the count keeps the width it needs (the
     record tables' auto / 1fr split let a long day squeeze the count to nothing). */
  .o-barchart-details .o-table tr {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}
