/* The theme editor of the owner interface (/manage/theme; Pages/Manage/Theme).
   Mobile first, and every color, font, radius and shadow is a custom property from
   site.css, like the rest of manage.css.

   Three parts: the built-in looks (a row of cards), the preview (a miniature of the
   site, drawn in a light box and in a dark box) and the form.

   Phone: the looks, then the preview in a box that can be folded away, then the form,
   with a small "Preview" button fixed in the corner that goes back up to it.
   Desktop (1100 px and up): the form on the left and the preview beside it, staying in
   view as the form scrolls.

   THE PREVIEW BOXES (.te-stage) ARE THE ONLY PLACE THE DRAFT'S COLORS APPLY. Each has a
   fixed color-scheme, so light-dark() picks its half there whatever the owner's device
   is set to, and carries site.css's "theme-scope", which declares every variable again
   so the built ones (shadows, gradients, mixes of the accent) follow the draft. The
   editor's own chrome, outside those boxes, keeps the saved theme.

   The miniature (.te-mini) is made of the site's real classes; the few rules for it
   here only arrange them in a small space (the real rules arrange them by the width of
   the screen, and the miniature is narrow on a wide screen). It is scaled with "zoom"
   so the whole of it fits, and it is inert: nothing in it can be focused or pressed. */

.te-presets, .te-section { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.te-form [hidden], .te-jump[hidden] { display: none; }

/* ---- Built-in looks ---- */
.te-preset-list { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 10px; }
.te-preset {
  position: relative; display: flex; flex-direction: column; gap: 8px; height: 100%; min-height: 44px; padding: 8px;
  border: 1px solid var(--button-line); border-radius: var(--radius-small);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; text-decoration: none; box-shadow: var(--elev-1);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.te-preset:hover { border-color: var(--control-line); box-shadow: var(--elev-2); }
/* The one the form holds now: ringed and ticked, so it is not told by color alone. */
.te-preset[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.te-preset-tick {
  display: none; position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; padding: 3px;
  border: 2px solid var(--surface); border-radius: var(--radius-round); background: var(--accent); color: var(--on-accent);
}
.te-preset[aria-current="true"] .te-preset-tick { display: block; }
.te-preset-name { display: flex; align-items: center; gap: 6px; min-height: 24px; overflow-wrap: anywhere; }
/* A strip of the look's own colors: light page, cards, accent, header, then dark cards and page. */
.te-swatches { display: flex; height: 40px; overflow: hidden; border: 1px solid var(--control-line); border-radius: var(--radius-chip); }
.te-swatches span { flex: 1 1 0; }

/* ---- The preview ---- */
.te-layout { display: flex; flex-direction: column; gap: 14px; }
.te-preview { scroll-margin-top: 12px; }
.te-preview-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; min-height: 48px; padding: 8px 16px; cursor: pointer; }
.te-preview-summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; border-radius: var(--radius); }
.te-preview-note { font-size: 13px; }

/* What is wrong with the draft, or that nothing is. A bar on the left and words; the
   tick or the count says which, not the color. */
.te-problems {
  margin: 0 16px 12px; padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--danger);
  border-radius: var(--radius-small); background: var(--surface-alt); font-size: 14px; overflow-wrap: anywhere;
}
.te-problems.is-fine { border-left-color: var(--accent); }
.te-problems-title { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--danger); font-weight: 700; }
.te-problems.is-fine .te-problems-title { color: var(--ink); font-weight: 600; }
.te-problems-title svg { flex: none; color: var(--accent); }
.te-problems ul { margin: 6px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* The two boxes. On a phone they sit side by side in a strip that slides sideways
   inside itself (the page never does), with the edge of the second one showing. */
.te-stages { display: flex; gap: 12px; padding: 0 16px 16px; overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-left: 16px; overscroll-behavior-x: contain; }
.te-figure { flex: 0 0 86%; min-width: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; scroll-snap-align: start; }
.te-figure figcaption { color: var(--label); font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.te-stage { overflow: hidden; border: 1px solid var(--control-line); border-radius: var(--radius-small); background: var(--ground); color: var(--ink); font-family: var(--font); }
.te-stage-light { color-scheme: light; }
.te-stage-dark { color-scheme: dark; }

/* ---- The miniature: the site's own parts, arranged small ---- */
.te-mini { zoom: 0.7; font-size: 15px; line-height: 1.45; }
.te-mini .site-header { position: static; }
.te-mini-header { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 14px; }
.te-mini .brand { flex: 1 1 0; min-width: 0; }
.te-mini .brand-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.te-mini-nav { flex: 1 1 auto; order: 2; flex-wrap: nowrap; gap: 2px; min-width: 0; }
.te-mini-nav a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 11px; border-radius: var(--radius-small); white-space: nowrap; }
.te-mini-nav .te-mini-current { background: var(--header-current); }
.te-mini-search {
  flex: 0 1 132px; order: 3; display: inline-flex; align-items: center; min-width: 0; height: 36px; padding: 0 12px; overflow: hidden;
  border: 1px solid var(--header-field-line); border-radius: var(--radius-small); background: var(--header-field); color: var(--header-muted);
}
.te-mini .bell { order: 1; }
/* The second row (links and search) starts on a new line under the name and the bell. */
.te-mini-header::after { content: ""; flex: 0 0 100%; order: 1; }

.te-mini-page { display: flex; flex-direction: column; gap: 12px; padding: 14px; background: var(--page-wash) no-repeat, var(--ground); }
.te-mini .category-name { padding: 11px 14px; font-size: 13px; }
.te-mini .board-row { flex-wrap: nowrap; gap: 12px; padding: 11px 14px; }
.te-mini .board-main { flex: 1 1 auto; display: flex; flex-direction: column; }
.te-mini-line { font-size: 13px; }
.te-mini .thread-row { position: relative; flex-wrap: nowrap; padding: 10px 14px 10px 40px; }
.te-mini .thread-row > .unread-dot { left: 14px; top: 16px; transform: none; }
.te-mini .thread-main { flex: 1 1 auto; padding: 0; }
.te-mini .thread-title::after { content: none; }
.te-mini .first-unread { display: inline; min-height: 0; }
.te-mini .post-author { flex: 1 1 100%; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 12px; padding: 10px 14px; }
.te-mini .avatar { width: 40px; height: 40px; font-size: 15px; }
.te-mini .user-card-body { flex: 1 1 0; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0 10px; width: auto; }
.te-mini .user-card-name { min-height: 0; margin-top: 0; }
.te-mini .user-card-stats { flex: 1 1 100%; }
.te-mini .post-main { flex: 1 1 100%; padding: 4px 14px 10px; }
.te-mini .post-meta { min-height: 34px; }
.te-mini .post-body { margin-top: 10px; }
.te-mini .post-actions { padding-top: 8px; }
.te-mini .forum-button { min-height: 38px; }
.te-mini-controls { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.te-mini-controls p { margin: 0; }
.te-mini-controls .buttons { align-items: center; }
.te-mini-controls .tag { margin: 0 0 0 4px; }
.te-mini-field { color: var(--muted); }

/* ---- The form ---- */
.te-form { display: flex; flex-direction: column; gap: 14px; min-width: 0; scroll-margin-top: 12px; }
.te-sides { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.te-side { min-width: 0; margin: 0; padding: 4px 10px 14px; border: 1px solid var(--line); border-radius: var(--radius-small); display: flex; flex-direction: column; gap: 14px; }
.te-side legend { padding: 0 6px; font-size: 16px; font-weight: 700; }

/* One color: what it is, then the picker, the hex value and "Default" in a row. */
.te-color { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.te-color-label { font-weight: 600; }
.te-color-hint { color: var(--muted); font-size: 13px; }
.te-color-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 3px; }
.te-pick { flex: none; width: 44px; height: 44px; padding: 3px; border: 1px solid var(--field-line); border-radius: var(--radius-small); background: var(--surface); cursor: pointer; }
.te-hex { flex: 1 1 86px; width: auto; min-width: 0; max-width: 136px; padding: 10px 8px; font-family: var(--font-mono); }
.te-default { flex: none; padding: 0 10px; }
/* One problem to a line when a color has two. */
.te-error { margin-top: 2px; white-space: pre-line; }

.te-fonts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.te-font-sample { margin: 0; padding: 10px 12px; border-radius: var(--radius-small); background: var(--ground); overflow-wrap: anywhere; }
.te-font-sample-heading { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }

/* Corners: real radio buttons, each drawn as a tile with a small picture of the corner. */
.te-corners { min-width: 0; margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 12px; }
.te-corners legend { padding: 0; }
.te-corner-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.te-corner {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 44px; padding: 12px 8px;
  border: 1px solid var(--button-line); border-radius: var(--radius-small); font-weight: 600; text-align: center; cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease);
}
.te-corner:hover { border-color: var(--control-line); background: var(--surface-alt); }
.te-corner input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
/* The one picked: ringed, and ticked in its name. */
.te-corner:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.te-corner:has(input:checked) .te-corner-name::before { content: "\2713\00a0"; }
.te-corner:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 4px; }
.te-corner-sample { display: flex; align-items: flex-end; justify-content: flex-end; width: 72px; height: 48px; padding: 7px; border: 2px solid var(--ink); background: var(--surface-alt); }
.te-corner-sample span { width: 30px; height: 16px; background: var(--accent); }

/* Save and the rest. The space underneath is for the "Preview" button fixed in the corner. */
.te-actions { display: flex; flex-direction: column; gap: 8px; padding-bottom: 64px; }
.te-status { margin: 0; min-height: 1.45em; font-weight: 600; }
.te-status:empty { display: none; }

/* Back up to the preview, from anywhere in the form. */
.te-jump { position: fixed; right: 16px; bottom: 16px; z-index: 20; gap: 6px; box-shadow: var(--elev-3); }

/* Tablet: the two themes side by side, in the preview and in the form. */
@media (min-width: 700px) {
  .te-presets, .te-section { padding: 20px; }
  .te-stages { overflow-x: visible; }
  .te-figure { flex: 1 1 0; }
  .te-mini { zoom: 0.8; }
  .te-sides, .te-fonts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .te-corner-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Desktop: the form on the left, the preview beside it and always in view, under the
   site's header (which stays at the top of the screen). If the window is too short for
   the whole preview, the preview scrolls inside itself. */
@media (min-width: 1100px) {
  .te-layout { display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 1fr); gap: 20px; align-items: start; }
  .te-form { grid-column: 1; grid-row: 1; }
  .te-preview {
    grid-column: 2; grid-row: 1; position: sticky; top: calc(var(--sticky-top, 0px) + 12px);
    max-height: calc(100vh - var(--sticky-top, 0px) - 24px); overflow-y: auto;
  }
  .te-mini { zoom: 0.66; }
  .te-actions { padding-bottom: 0; }
  .te-jump { display: none; }
}
