/* ----- Editor (pages + cells) -------------------------------------- */

.editor-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--t-space-4);
}

/* Fluid panel-shaped preview. The frame fills its column width up to
   a sensible cap, height tracks via aspect-ratio (set inline from the
   panel dims). The inner iframe/img is sized to the panel's native
   pixels so the composer renders unscaled; static/components.js
   (fitPreview) sets a `transform: scale(...)` to fit.

   Flat surface, no checkerboard, no inset glass. The placeholder
   carries the empty state on its own. */
.preview-frame {
  position: relative;
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-md);
  background: var(--t-surface-soft);
  overflow: hidden;
  aspect-ratio: 4 / 3; /* fallback; inline style overrides */
}

.preview-frame > iframe {
  position: absolute;
  top: 0;
  left: 0;
  border: 0;
  display: block;
  /* The composed panel content sets its own bleed colour and paints
     over this; we only see this background while the iframe loads.
     Use the themed surface so dark mode doesn't flash bright white. */
  background: var(--t-surface-soft);
  transform-origin: 0 0;
}
.preview-frame > img.preview-image {
  /* Raster previews fit the frame with letterboxing; the source is
     panel-content already so we don't need the iframe's transform
     trick. The letterbox bars use the themed surface. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--t-surface-soft);
  object-fit: contain;
}
.preview-frame > .preview-placeholder {
  position: absolute;
  inset: 0;
}
.preview-placeholder[hidden] { display: none !important; }

/* Live-preview throbber (v0.69.8). Sits on top of the faded iframe
   while the composer server-renders the page (waiting on each
   widget's fetch() to return), so the wait doesn't read as a dead
   pane. Reveals when reloadPreview() sets iframe.src; hidden again
   on the iframe's ``load`` event. */
.preview-throbber {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  animation: preview-throbber-fade-in 180ms ease 100ms both;
}
.preview-throbber[hidden] { display: none; }
.preview-throbber > i {
  font-size: 40px;
  color: var(--t-accent);
  filter: drop-shadow(0 1px 2px rgba(20, 20, 15, 0.28));
  animation: preview-throbber-spin 0.9s linear infinite;
}
@keyframes preview-throbber-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes preview-throbber-fade-in {
  /* Small delay + fade so a fast render (cached widget data, no
     network hit) doesn't flash the throbber. Anything under ~280 ms
     stays invisible; longer waits get the spinner. */
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ----- Dashboards index (mirrors inky-dash) ----------------------- */

/* Inline create card: plus glyph · name input (grows) · primary button. */
.dashboard-create {
  display: flex;
  align-items: center;
  gap: var(--t-space-3);
  padding: var(--t-space-3) var(--t-space-4);
  margin-bottom: var(--t-space-5);
}
.dashboard-create-icon {
  flex: 0 0 auto;
  font-size: 22px;
  color: var(--t-muted);
  display: inline-grid;
  place-items: center;
}
.dashboard-create-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  background: var(--t-surface-soft);
  padding: var(--t-space-3);
  font: inherit;
  color: var(--t-fg);
}
.dashboard-create-input:focus-visible {
  outline: none;
  border-color: var(--t-accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--t-accent) 20%, transparent);
}
.dashboard-create-btn { flex: 0 0 auto; }

.dashboard-count {
  font-size: var(--t-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--t-muted);
  margin: 0 0 var(--t-space-2);
}

.pages-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--t-space-2);
}

/* icon-tile | name+meta (grows) | actions */
.page-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--t-space-3);
  align-items: center;
  padding: var(--t-space-3) var(--t-space-4);
  background: var(--t-surface);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-md);
  box-shadow: var(--t-shadow-xs);
  transition:
    border-color var(--t-trans),
    box-shadow var(--t-trans),
    transform var(--t-trans);
}
.page-row:hover {
  border-color: var(--t-border-strong);
  box-shadow: var(--t-shadow-sm);
  transform: translateY(-1px);
}
.page-row:hover .page-name { color: var(--t-accent); }

.page-icon-tile {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--t-radius-md);
  background: var(--t-accent-soft);
  color: var(--t-accent);
  font-size: 19px;
}

.page-row-main {
  text-decoration: none;
  color: var(--t-fg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.page-row .page-name {
  display: block;
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-row .page-meta {
  font-size: 12px;
  color: var(--t-fg-soft);
  font-variant-numeric: tabular-nums;
}
.page-row .page-meta .ph {
  font-size: 13px;
  vertical-align: -1px;
  opacity: 0.75;
}

.page-actions { display: flex; gap: var(--t-space-2); align-items: center; }

/* Outlined pill actions (Edit / Push / Delete). */
.page-action {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
  padding: var(--t-space-2) var(--t-space-3);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  background: var(--t-surface);
  color: var(--t-fg-soft);
  font: inherit;
  font-size: var(--t-size-md);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--t-trans-fast), color var(--t-trans-fast),
              background var(--t-trans-fast);
}
.page-action .ph { font-size: 15px; }
.page-action:hover {
  border-color: var(--t-accent);
  color: var(--t-accent);
}
.page-action-danger { color: var(--t-danger); }
.page-action-danger:hover {
  border-color: var(--t-danger);
  color: var(--t-danger);
  background: color-mix(in oklab, var(--t-danger) 8%, transparent);
}

@media (max-width: 640px) {
  /* Collapse action labels to icons on narrow screens. */
  .page-action span { display: none; }
  .page-action { padding: var(--t-space-2) var(--t-space-3); }
}

.cell-list {
  list-style: none;
  margin: 0 0 var(--t-space-4);
  padding: 0;
  display: grid;
  gap: var(--t-space-2);
}

.cell-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--t-space-3);
  align-items: center;
  padding: var(--t-space-2) var(--t-space-3);
  background: var(--t-surface-soft);
  border: 1px solid transparent;
  border-radius: var(--t-radius-sm);
  transition: background var(--t-trans-fast), border-color var(--t-trans-fast);
}
.cell-row:hover {
  background: var(--t-surface);
  border-color: var(--t-border);
}

.cell-row-link {
  text-decoration: none;
  color: var(--t-fg);
  min-width: 0;
}

.cell-row-name { font-weight: 600; font-size: 14px; }
.cell-row-meta { font-size: 12px; }

.add-cell { padding-top: var(--t-space-1); border-top: 1px dashed var(--t-border); margin-top: var(--t-space-1); }

.form-group {
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  padding: var(--t-space-3) var(--t-space-4);
  margin: 0 0 var(--t-space-4);
}
.form-group > legend {
  font-size: var(--t-size-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--t-fg-soft);
  padding: 0 var(--t-space-2);
}
.form-group summary {
  cursor: pointer;
  font-size: var(--t-size-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--t-fg-soft);
  padding: var(--t-space-1) 0;
}
.form-group[open] summary { margin-bottom: var(--t-space-3); }

.header-action {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
  margin-left: var(--t-space-4);
  padding: var(--t-space-2) var(--t-space-4) var(--t-space-2) var(--t-space-3);
  background: var(--t-accent);
  color: var(--t-accent-fg, #fff);
  border: 1px solid color-mix(in oklab, var(--t-accent) 70%, black);
  border-radius: var(--t-radius-sm);
  text-decoration: none;
  font-size: var(--t-size-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  cursor: pointer;
  vertical-align: middle;
  box-shadow:
    0 1px 0 color-mix(in oklab, white 35%, transparent) inset,
    0 1px 2px color-mix(in oklab, var(--t-accent) 35%, transparent),
    0 0 0 0 color-mix(in oklab, var(--t-accent) 0%, transparent);
  transition:
    background var(--t-trans-fast),
    box-shadow var(--t-trans-fast),
    transform var(--t-trans-fast);
}
.header-action .ph,
.header-action [class*="ph-"] {
  font-size: 18px;
  color: var(--t-accent-fg) !important;
  font-weight: bold;
}
.header-action:hover {
  background: var(--t-accent-hover);
  color: var(--t-accent-fg, #fff);
  box-shadow:
    0 1px 0 color-mix(in oklab, white 35%, transparent) inset,
    0 3px 8px color-mix(in oklab, var(--t-accent) 35%, transparent),
    0 0 0 4px color-mix(in oklab, var(--t-accent) 18%, transparent);
  transform: translateY(-1px);
}
.header-action:active { transform: translateY(0); }
.header-action:focus-visible {
  outline: none;
  box-shadow:
    0 1px 0 color-mix(in oklab, white 35%, transparent) inset,
    0 0 0 4px color-mix(in oklab, var(--t-accent) 30%, transparent);
}

.header-back {
  color: var(--t-fg-soft);
  text-decoration: none;
}
.header-back:hover { color: var(--t-accent); }

.page-id-tag {
  font-size: 13px;
  color: var(--t-muted);
  font-weight: 400;
  margin-left: 8px;
  vertical-align: middle;
}

/* ----- Editor header (page name + save status) --------------------- */

.editor-header {
  display: flex;
  align-items: center;
  gap: var(--t-space-3);
  padding: var(--t-space-3) 0 var(--t-space-4);
  margin: calc(-1 * var(--t-space-5)) 0 var(--t-space-3);
  border-bottom: 1px solid var(--t-border);
  position: sticky;
  top: 64px; /* below the topbar */
  background: color-mix(in oklab, var(--t-bg) 80%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 40;
  padding-left: var(--t-space-1);
  padding-right: var(--t-space-1);
  margin-left: calc(-1 * var(--t-space-1));
  margin-right: calc(-1 * var(--t-space-1));
}
@supports not (backdrop-filter: blur(1px)) {
  .editor-header { background: var(--t-bg); }
}

.editor-header .header-back {
  font-size: 22px;
  text-decoration: none;
  padding: var(--t-space-1) var(--t-space-3);
  border-radius: var(--t-radius-sm);
  color: var(--t-fg-soft);
}
.editor-header .header-back:hover { background: var(--t-surface-soft); color: var(--t-accent); }

.editor-name-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--t-radius-sm);
  background: var(--t-accent-soft);
  color: var(--t-accent);
  font-size: 18px;
  flex-shrink: 0;
}
.editor-name-icon:empty { display: none; }

.inline-name-form { flex: 1; max-width: 480px; }
.inline-name-input {
  font: 700 18px/1.2 system-ui, sans-serif;
  padding: var(--t-space-2) var(--t-space-3);
  border: 1px solid transparent;
  border-radius: var(--t-radius-sm);
  background: transparent;
  width: 100%;
  color: var(--t-fg);
}
.inline-name-input:hover { background: var(--t-surface-soft); }
.inline-name-input:focus { background: var(--t-surface); border-color: var(--t-border-strong); outline: none; }

.save-status {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
  font-size: var(--t-size-sm);
  font-weight: 600;
  padding: var(--t-space-1) var(--t-space-3);
  border-radius: var(--t-radius-pill);
  background: var(--t-ok-bg);
  color: var(--t-ok);
  border: 1px solid color-mix(in oklab, var(--t-ok) 25%, transparent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.005em;
  transition: background var(--t-trans), color var(--t-trans),
              border-color var(--t-trans);
}
.save-status .ph, .save-status [class^="ph-"] { font-size: 13px; }
.save-status[data-state="saving"] {
  background: var(--t-surface-sunk);
  color: var(--t-fg-soft);
  border-color: var(--t-border);
}
.save-status[data-state="saving"] .ph { animation: ts-spin 0.9s linear infinite; }
.save-status[data-state="dirty"] {
  background: color-mix(in oklab, var(--t-warn) 14%, transparent);
  color: var(--t-warn);
  border-color: color-mix(in oklab, var(--t-warn) 30%, transparent);
}
.save-status[data-state="error"] {
  background: var(--t-danger-bg);
  color: var(--t-danger);
  border-color: color-mix(in oklab, var(--t-danger) 30%, transparent);
}

@keyframes ts-spin {
  to { transform: rotate(360deg); }
}

.editor-spacer { flex: 1; }

.editor-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
}
.editor-actions button { padding: var(--t-space-2) var(--t-space-3); font-size: var(--t-size-md); }
.editor-actions button[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ----- Editor grid: options on the left, preview pinned on the right - */

@media (min-width: 1100px) {
  /* Bumps the shared page-column variable so .page and the topbar's
     padding-inline both pick up the wider column. */
  :root { --t-page-max: 1440px; }
  .editor-grid {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 620px);
    grid-template-areas: "column preview";
    gap: var(--t-space-6);
    align-items: start;
  }
  .editor-column {
    grid-area: column;
    display: grid;
    gap: var(--t-space-4);
    min-width: 0;
  }
  .preview-card {
    grid-area: preview;
    position: sticky;
    /* Stick just below the editor-header (which is itself sticky at
       top:64px and ~68px tall — name input, save status, dims tag,
       save/push/delete row). 64 + 68 + 8 (gap) = 140px. */
    top: 140px;
    margin: 0;
    align-self: start;
  }
  /* Cap the preview frame's width so the whole card fits within the
     viewport when stuck — otherwise a portrait panel (e.g. 800×1200)
     makes the card taller than the viewport and sticky pins only the
     top portion, leaving the actual preview content half-visible
     while the user scrolls the cell editors. ``--panel-ar`` is set
     inline as ``calc(w / h)``; multiplying available vertical space
     by that ratio gives the width that produces a card that fits.
     The ``min()`` keeps the existing 720px cap on landscape panels
     where height isn't the constraint. The 220px subtracts the sticky
     top offset (~108px), card head + dims line (~80px), and a
     comfortable bottom gap (~32px). 140 + 80 + 32 = 252. */
  .preview-card .preview-frame {
    max-width: min(720px, calc((100vh - 252px) * var(--panel-ar, 1.333)));
  }
}

@media (max-width: 1099px) {
  .editor-grid { gap: var(--t-space-4); }
  /* Mobile: editor header is NOT sticky, scrolls away naturally so
     the save/send/delete row only exists at the top of the page.
     Preview card scrolls with the rest of the content; the
     back-to-top FAB (see below) reappears once it leaves the
     viewport. */
  :root {
    --mobile-preview-h: 36vh;
  }
  /* Override the base rule (lines ~334) that makes the editor header
     sticky at top:64px on desktop. Mobile: header is in normal flow
     so it scrolls away with the rest of the page. Background + blur
     stay so the visual style is preserved. */
  .editor-header {
    position: static;
    top: auto;
    z-index: auto;
  }
  .preview-card {
    text-align: center;
    margin: 0;
    background: var(--t-surface);
    padding: var(--t-space-3);
  }
  /* Centred, aspect-preserved preview frame. --panel-ar is set
     inline (w/h) so width = min(100%, max-height × --panel-ar);
     height comes from the existing aspect-ratio rule. */
  .preview-frame {
    display: inline-block;
    width: min(100%, calc(var(--mobile-preview-h) * var(--panel-ar, 1)));
    max-height: var(--mobile-preview-h);
  }
}

/* Phone-portrait: tighten everything. Header collapses to two rows;
   action buttons go icon-only to fit. */
@media (max-width: 600px) {
  /* Shorter cap on phone-portrait so the cell editors get most of the
     viewport. The sticky preview at the top is meant for live-eyeing
     edits, not dominating the screen. */
  :root { --mobile-preview-h: 30vh; }
  .editor-grid { gap: var(--t-space-3); }
  .preview-dims { font-size: var(--t-size-xs); margin-top: var(--t-space-2); text-align: center; }

  /* Two-row header. Row 1: back · icon · name input (takes the rest).
     Row 2: save-status (left) · actions (right). page-id-tag and the
     flex spacer drop out, the row layout supplies the spacing. */
  .editor-header {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: var(--t-space-2);
    padding: var(--t-space-2) var(--t-space-1);
  }
  .editor-header .header-back { grid-row: 1; grid-column: 1; }
  .editor-name-icon            { grid-row: 1; grid-column: 2; }
  .inline-name-form            { grid-row: 1; grid-column: 3 / span 2; max-width: none; }
  .save-status                 { grid-row: 2; grid-column: 1 / span 2; justify-self: start; }
  .editor-spacer               { display: none; }
  .page-id-tag                 { display: none; }
  .editor-actions {
    grid-row: 2;
    grid-column: 3 / span 2;
    justify-self: end;
    flex-wrap: nowrap;
  }
  /* Action button labels collapse, icons only at this width. */
  .editor-actions button > span:not(.icon) { display: none; }
  .editor-actions button {
    padding: var(--t-space-2) var(--t-space-3);
    min-width: 40px;
    justify-content: center;
  }
}

.preview-card .preview-frame { margin: 0 auto; }
.preview-dims {
  text-align: right;
  font-size: var(--t-size-sm);
  margin: var(--t-space-2) var(--t-space-1) 0;
}

/* Floating "back to top" FAB, only meaningful on the reactive
   (mobile) layout where the preview card is stacked at the top and a
   long cell list pushes it off-screen. Hidden on desktop where the
   preview is already a sticky sidebar. Side preference lives on the
   button as data-side="left|right" so a left-handed user can drag it
   once and the choice persists via localStorage.

   Visibility is class-driven (`is-visible`) so the entry/exit
   animations actually run. Default state is fade-and-slide-out below
   the viewport with pointer-events off; adding `is-visible` lifts the
   FAB up + fades it in. */
.scroll-to-preview {
  position: fixed;
  /* Inset further from the edges than the default --t-space-4 so the
     FAB lands in the thumb's natural arc instead of the screen corner.
     Bottom + inline use a slightly larger gap so a one-handed grip can
     reach it without stretching. */
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--t-space-6));
  left: calc(env(safe-area-inset-left, 0px) + var(--t-space-6));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: var(--t-accent);
  color: var(--t-accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: var(--t-shadow-xl);
  cursor: pointer;
  /* touch-action: none keeps the browser from claiming the gesture for
     scrolling once the user starts dragging the FAB horizontally. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 1000;
  /* Hidden by default: dropped below its anchor + transparent + inert.
     The is-visible class lifts it back into place. */
  opacity: 0;
  transform: translateY(140%);
  pointer-events: none;
  will-change: transform, opacity;
  transition:
    transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.22s ease,
    background 0.15s ease,
    box-shadow 0.2s ease;
}
.scroll-to-preview[data-side="right"] {
  left: auto;
  right: calc(env(safe-area-inset-right, 0px) + var(--t-space-6));
}
.scroll-to-preview.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.scroll-to-preview:hover,
.scroll-to-preview:focus-visible {
  background: var(--t-accent-hover);
  outline: none;
}
.scroll-to-preview:focus-visible {
  box-shadow:
    var(--t-shadow-xl),
    var(--t-ring);
}
/* Hover lift on desktop pointers, the icon nudges up to telegraph the
   "back to top" action. Skipped on touch (`hover: none`) so a finger
   release doesn't strand the icon in the lifted state. */
@media (hover: hover) {
  .scroll-to-preview.is-visible:hover .ph-bold {
    transform: translateY(-2px);
  }
  .scroll-to-preview .ph-bold {
    transition: transform 0.18s ease;
  }
}
/* Tap feedback: brief inset push on press. The drag override below
   wins via class precedence so the active state can't interfere with
   a real drag-to-flip gesture. */
.scroll-to-preview.is-visible:active {
  transform: translateY(0) scale(0.9);
  box-shadow: var(--t-shadow-lg);
  transition:
    transform 0.08s ease,
    box-shadow 0.08s ease;
}
/* Drag in progress: kill the transform transition so the button tracks
   the finger 1:1 instead of lagging. JS sets translateX inline; that
   inline transform wins over the :active scale because inline styles
   beat any class-driven rule. */
.scroll-to-preview.is-dragging {
  transition: none !important;
  cursor: grabbing;
  box-shadow: var(--t-shadow-xl);
}
/* Reduced-motion: drop the bouncy entry + lift transitions to a quick
   fade so the user gets the same affordance without the animation. */
@media (prefers-reduced-motion: reduce) {
  .scroll-to-preview,
  .scroll-to-preview.is-visible,
  .scroll-to-preview.is-visible:active {
    transition:
      opacity 0.15s ease,
      background 0.15s ease;
    transform: none;
  }
  .scroll-to-preview:not(.is-visible) {
    transform: none;
  }
}
/* Desktop: the preview is sticky in the right column, so the FAB has
   no job. Use !important to win against an in-flight is-visible class
   left over from a narrow→wide viewport resize. */
@media (min-width: 1100px) {
  .scroll-to-preview {
    display: none !important;
  }
}

/* Multi-device: stacked preview groups (one per distinct aspect). The
   first sits flush under the card head; subsequent ones get a divider
   so the shapes read as separate displays. */
.preview-group + .preview-group {
  margin-top: var(--t-space-4);
  padding-top: var(--t-space-4);
  border-top: 1px solid var(--t-border);
}
.preview-group-label {
  font-size: var(--t-size-sm);
  font-weight: 600;
  color: var(--t-fg-soft);
  margin: 0 0 var(--t-space-2);
  text-align: center;
}

.cell-card {
  scroll-margin-top: var(--t-space-4);
  transition:
    outline 200ms ease,
    box-shadow var(--t-trans),
    border-color var(--t-trans);
}
.cell-card.is-focused {
  outline: 3px solid var(--t-accent);
  outline-offset: 2px;
  border-color: var(--t-accent);
  box-shadow:
    var(--t-shadow-md),
    var(--t-shadow-inset),
    0 0 0 8px color-mix(in oklab, var(--t-accent) 8%, transparent);
}
/* Cell cards inherit .card-head + .card-head h2 verbatim from
   shell.css, no overrides needed. The plugin tag inside the title
   reads as secondary. */
.cell-card-plugin { font-weight: 500; color: var(--t-fg-soft); }

/* ----- Layout editor (interactive grid) --------------------------- */

.layout-editor {
  position: relative;
  margin-bottom: var(--t-space-4);
  --panel-aspect: 4 / 3;
}

.layout-editor-board {
  position: relative;
  width: 100%;
  aspect-ratio: var(--panel-aspect);
  background: var(--t-surface-soft);
  border: 1px solid var(--t-border-strong);
  border-radius: var(--t-radius-sm);
  user-select: none;
  /* Containing block for absolutely-positioned cells + handles. */
}
.layout-editor-board.is-dragging .le-insert,
.layout-editor-board.is-dragging .le-cell-delete {
  /* Avoid stray hovers triggering during a resize drag. */
  pointer-events: none;
  opacity: 0;
}

.layout-editor-hint {
  margin: var(--t-space-2) 0 0;
  font-size: var(--t-size-sm);
  color: var(--t-fg-soft);
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
}
.layout-editor-hint .ph { font-size: 14px; color: var(--t-accent); }

/* Snap-to-grid controls live below the board + hint. The dashed
   gridline overlay is painted by the JS directly on
   .layout-editor-board via repeating linear gradients. The inputs
   themselves reuse the standard ``.field`` styling, they should look
   identical to every other form input in the editor. */
.layout-snap {
  margin-top: var(--t-space-3);
  display: flex;
  flex-direction: column;
  gap: var(--t-space-2);
}
.layout-snap-dims[hidden] { display: none; }

.le-cell {
  position: absolute;
  box-sizing: border-box;
  background: color-mix(in oklab, var(--t-accent) 8%, var(--t-surface));
  border: 1px solid var(--t-accent);
  border-radius: 4px;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: background 80ms ease;
}
.le-cell:hover {
  background: color-mix(in oklab, var(--t-accent) 14%, var(--t-surface));
}

/* Long-press to delete, the cell fills with the danger colour over
   the long-press window (~600ms). When it completes, the press
   handler fires the delete confirm. Cancels (move / lift) drop the
   class and remove the fill. */
.le-cell.is-pressing {
  background: var(--t-danger);
  border-color: var(--t-danger);
  color: var(--t-bg, #fff);
  transition: background 600ms linear, border-color 600ms linear, color 200ms ease;
}
.le-cell.is-pressing .le-cell-label,
.le-cell.is-pressing .le-cell-delete {
  color: inherit;
}
.le-cell-label {
  font: 600 12px/1.2 var(--t-font-mono);
  color: var(--t-fg);
  padding: 2px 6px;
  background: color-mix(in oklab, var(--t-surface) 80%, transparent);
  border-radius: 3px;
  pointer-events: none;
  max-width: 90%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Delete X, top-right corner, only visible on hover. */
.le-cell-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--t-surface);
  border: 1px solid var(--t-border);
  border-radius: 4px;
  color: var(--t-fg-soft);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease, border-color 120ms ease;
}
.le-cell:hover .le-cell-delete { opacity: 1; }
.le-cell-delete:hover {
  color: var(--t-danger);
  border-color: var(--t-danger);
}
.le-cell-delete .ph { font-size: 13px; }

/* Insert affordances, thin invisible strips on each side that show a
   "+ insert here" hint on hover. Click splits the cell along the
   perpendicular axis. */
.le-insert {
  position: absolute;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background 120ms ease;
  display: grid;
  place-items: center;
}
.le-insert::before {
  content: "+";
  font: 700 18px/1 var(--t-font-mono);
  color: var(--t-accent-fg, #fff);
  background: var(--t-accent);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 120ms ease, transform 120ms ease;
}
.le-insert:hover {
  background: color-mix(in oklab, var(--t-accent) 18%, transparent);
}
.le-insert:hover::before {
  opacity: 1;
  transform: scale(1.05);
}
.le-insert--top    { top: 0;    left: 0; right: 0; height: 14px; }
.le-insert--bottom { bottom: 0; left: 0; right: 0; height: 14px; }
.le-insert--left   { left: 0;   top: 0; bottom: 0; width: 14px; }
.le-insert--right  { right: 0;  top: 0; bottom: 0; width: 14px; }

/* Resize handles for shared edges. Sit ON TOP of the cells with a
   generous hit-target (24px) for touch; the visible bar inside is
   only 2px wide. touch-action: none stops the browser from scrolling
   when the user starts a drag on a phone / tablet. */
.le-edge {
  position: absolute;
  background: transparent;
  z-index: 2;
  touch-action: none;
}
.le-edge::after {
  content: "";
  position: absolute;
  background: var(--t-accent);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 120ms ease;
}
.le-edge:hover::after,
.layout-editor-board.is-dragging .le-edge::after { opacity: 0.7; }

.le-edge--h {
  height: 24px;
  margin-top: -12px;
  cursor: ns-resize;
}
.le-edge--h::after {
  left: 0; right: 0;
  top: 11px;
  height: 2px;
}
.le-edge--v {
  width: 24px;
  margin-left: -12px;
  cursor: ew-resize;
}
.le-edge--v::after {
  top: 0; bottom: 0;
  left: 11px;
  width: 2px;
}

/* Custom layout editor, collapsed under the preset grid by default. */
.custom-layout {
  margin-top: var(--t-space-4);
  border-top: 1px solid var(--t-border);
  padding-top: var(--t-space-3);
}
.custom-layout summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--t-fg-soft);
  padding: var(--t-space-2) 0;
}
.custom-layout[open] summary { color: var(--t-fg); margin-bottom: var(--t-space-2); }

/* ----- Layout picker (thumbnails) --------------------------------- */

.layout-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--t-space-3);
  /* Each card centres a fixed-height thumbnail in the panel aspect.
     The aspect is set inline from the current panel so portrait flips
     show portrait thumbnails. */
  --panel-aspect: 4 / 3;
  --thumb-h: 96px;
}

.layout-form { margin: 0; }

.layout-card {
  display: grid;
  grid-template-rows: var(--thumb-h) auto;
  justify-items: center;
  gap: var(--t-space-2);
  padding: var(--t-space-3);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  background: var(--t-surface);
  cursor: pointer;
  width: 100%;
  text-align: center;
  font: var(--t-size-sm)/1.2 system-ui, sans-serif;
  color: var(--t-fg);
  transition: border-color 80ms ease, transform 80ms ease;
  /* Reset the global button inline-flex so the grid-rows take effect. */
  white-space: normal;
}
.layout-card:hover {
  border-color: var(--t-accent);
  transform: translateY(-2px);
  box-shadow: var(--t-shadow-sm);
}
.layout-card.is-active {
  border-color: var(--t-accent);
  background: color-mix(in oklab, var(--t-accent) 8%, var(--t-surface));
  box-shadow:
    0 0 0 2px var(--t-accent),
    var(--t-shadow-sm);
}

.layout-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.layout-thumb {
  position: relative;
  display: block;
  height: var(--thumb-h);
  /* Preset thumbnails are schematic hints of the split pattern, not a
     scale model of the panel, so they use a fixed aspect rather than the
     panel's. Matching the real aspect turned the hints into unreadable
     strips on extreme panels (e.g. a 296x128 Magtag), issue #156. The
     interactive custom-layout board still uses --panel-aspect. */
  aspect-ratio: 4 / 3;
  background: var(--t-surface-soft);
  border: 1px solid var(--t-border);
  border-radius: 4px;
  overflow: hidden;
}

.layout-thumb-cell {
  position: absolute;
  background: color-mix(in oklab, var(--t-accent) 45%, white);
  outline: 1px solid var(--t-surface);
  outline-offset: -1px;
}

.layout-name {
  font-weight: 600;
  color: var(--t-fg);
}

.add-cell-card .full-width {
  width: 100%;
  padding: var(--t-space-3);
  font-weight: 600;
  border-style: dashed;
}


/* ----- Schedules card on the page editor --------------------------- */
/* Compact list of schedules pinned to this dashboard, surfaced under
   the live preview so the composer can see "what fires this" at a
   glance and one-click into the schedules page to add or edit. */
.schedules-card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--t-space-2);
}
.schedules-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--t-space-3);
  padding: var(--t-space-2) var(--t-space-3);
  border-radius: 8px;
  background: color-mix(in srgb, var(--t-fg-soft, #9aa0aa) 6%, transparent);
}
.schedules-card-row.is-disabled .schedules-card-row-name { color: var(--t-fg-soft); }
.schedules-card-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.schedules-card-row-name {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-1);
  font-size: var(--t-size-md);
  color: var(--t-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.schedules-card-row-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--t-space-2);
  font-size: var(--t-size-sm);
}
.schedules-card-empty {
  margin: 0 0 var(--t-space-3);
}
.schedules-card-actions {
  display: flex;
  align-items: center;
  gap: var(--t-space-3);
  margin-top: var(--t-space-3);
}
