/* Ticker Content Studio hub — shared styles.
   Token values mirror cards/shared/tokens.css (dark theme, brand.json v2.0.0).
   Keep the variable block in sync with that file. */

/* The views toggle visibility via the `hidden` attribute; any class with an
   explicit `display:` silently defeats it (bit us twice: auth gate, preview
   empty state). This guard makes `hidden` always win. */
[hidden] {
  display: none !important;
}

:root {
  /* Base — dark */
  --bg: #000000;
  --surface: #1a1a1a;
  --surface-2: #292929;
  --rule: #434343;
  --rule-subtle: #2e2e2e;
  --ink-1: #f5f5f5;
  --ink-2: #a5a5a5;
  --ink-3: #767676;

  /* Brand */
  --flatty-yellow: #fce300;
  --deep-sapphire: #002663;
  --green: #00be4a;
  --periwinkle: #b6cdff;
  --ecru-white: #f5f2eb;

  /* Accents (dark) */
  --accent-yellow: #fce300;
  --accent-green: #00be4a;
  --accent-periwinkle: #b6cdff;
  --accent-carbon: #a5a5a5;

  /* Semantic (dark) */
  --up-text: #00be4a;
  --down-text: #e86060;

  /* Type */
  --font-display: "Lexend", sans-serif;
  --font-body: "Inter", sans-serif;
  --font-editorial: "Urbanist", sans-serif;
  --font-mono: "DM Mono", monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink-1);
  font-family: var(--font-body);
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: 100vh;
}

/* ——— Sidebar ——— */

#sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--rule);
  padding: 18px 14px 14px;
  min-height: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  padding: 2px 8px 18px;
  border-bottom: 1px solid var(--rule-subtle);
  margin-bottom: 14px;
}

.brand img {
  height: 18px;
  width: auto;
  align-self: flex-start;
}

.brand .sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

#nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
}

#nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--ink-2);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  border: 1px solid transparent;
}

#nav a:hover {
  color: var(--ink-1);
  background: var(--surface);
}

#nav a.active {
  color: var(--ink-1);
  background: var(--surface);
  border-color: var(--rule-subtle);
  font-weight: 500;
}

/* ——— Token settings (sidebar bottom) ——— */

#settings {
  border-top: 1px solid var(--rule-subtle);
  padding-top: 12px;
}

#token-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 10px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  text-align: left;
}

#token-toggle:hover {
  color: var(--ink-1);
  background: var(--surface);
}

#token-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 4px 2px;
}

#token-form[hidden] {
  display: none;
}

.token-actions {
  display: flex;
  gap: 8px;
}

.token-actions .action {
  flex: 1;
}

/* ——— Status dots ——— */

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  flex: none;
}

[data-state="ok"] .dot {
  background: var(--accent-green);
}

[data-state="unauthorised"] .dot {
  background: var(--accent-yellow);
}

[data-state="error"] .dot {
  background: var(--down-text);
}

/* ——— Main column ——— */

#main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}

#topbar h1 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 18px;
  letter-spacing: -0.01em;
}

#topbar .spacer {
  flex: 1;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

.conn[data-state="ok"] {
  color: var(--accent-green);
}

.conn[data-state="unauthorised"] {
  color: var(--accent-yellow);
}

.conn[data-state="error"] {
  color: var(--down-text);
}

#view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  min-height: 0;
}

/* ——— Shared bits (studio aesthetic) ——— */

.section-label {
  font-family: var(--font-editorial);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 22px 0 10px;
}

.section-label:first-child {
  margin-top: 0;
}

input,
textarea,
select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink-1);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 8px 10px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent-periwinkle);
  outline-offset: 1px;
}

button.action {
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--ink-1);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12.5px;
  padding: 9px 14px;
  cursor: pointer;
  min-height: 36px;
}

button.action:hover {
  border-color: var(--ink-3);
}

button.action.primary {
  background: var(--flatty-yellow);
  border-color: var(--flatty-yellow);
  color: #000;
}

button.action.primary:hover {
  background: #caaa00;
}

button.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.action:disabled:hover {
  border-color: var(--rule);
}

button.action.primary:disabled:hover {
  background: var(--flatty-yellow);
}

/* ——— Empty states ——— */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 60vh;
  text-align: center;
  padding: 24px;
}

.empty h2 {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.empty p {
  color: var(--ink-3);
  max-width: 46ch;
  line-height: 1.6;
}

.empty .hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

/* ——— Create view tabs ——— */

.seg {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}

.seg button {
  background: none;
  border: none;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 16px;
  cursor: pointer;
}

.seg button:hover {
  color: var(--ink-1);
}

.seg button.active {
  background: var(--surface-2);
  color: var(--ink-1);
}

.tab-panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 28px;
  margin-top: 16px;
}

.tab-panel h3 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 15px;
  margin-bottom: 8px;
}

.tab-panel p {
  color: var(--ink-3);
  line-height: 1.6;
  max-width: 60ch;
}

.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 3px 9px;
  margin-top: 14px;
}

/* ——— Shared text utilities ——— */

.muted {
  color: var(--ink-3);
}

.mono {
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ——— Editions list ——— */

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.pager {
  display: flex;
  gap: 8px;
}

.editions-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
}

.editions-table th {
  font-family: var(--font-editorial);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
}

.editions-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule-subtle);
  font-size: 13px;
}

.editions-table tbody tr {
  cursor: pointer;
}

.editions-table tbody tr:hover {
  background: var(--surface-2);
}

.pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  border-radius: 999px;
  padding: 2px 9px;
  border: 1px solid var(--rule);
  color: var(--ink-2);
}

.pill-edited {
  color: var(--accent-yellow);
  border-color: var(--rule-yellow, #4a3c00);
}

.pill-auto {
  color: var(--accent-green);
  border-color: var(--rule-green, #003818);
}

/* ——— Edition editor (parity with cards/studio) ——— */

.editor-grid {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 0;
  min-height: 0;
  margin: -24px; /* reclaim the #view padding for a full-bleed editor */
  height: calc(100% + 48px); /* …and its height (24px top + bottom) */
}

.editor-col {
  overflow-y: auto;
  border-right: 1px solid var(--rule);
  padding: 18px 20px 80px;
  min-height: 0;
}

.editor-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.editor-toolbar .gap {
  flex: 1;
}

.editor-toolbar a.action {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

.status.saving {
  color: var(--accent-yellow);
}

.row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.row > * {
  flex: 1;
  min-width: 0;
}

.row.checks {
  margin-top: 4px;
}

label.field {
  display: block;
}

label.field span {
  display: block;
  font-size: 10px;
  color: var(--ink-3);
  margin-bottom: 3px;
  font-family: var(--font-editorial);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-2);
}

.check input[type='checkbox'] {
  width: auto;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.item {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.item input,
.item textarea,
.item select {
  background: var(--bg);
}

.item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.item-head .n {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  width: 20px;
}

.item-head .ticker {
  width: 86px;
  flex: none;
  font-family: var(--font-mono);
}

.item-head .name {
  flex: 1;
}

.icon-btn {
  background: none;
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink-2);
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 12px;
  flex: none;
}

.icon-btn:hover {
  color: var(--ink-1);
  border-color: var(--ink-3);
}

.card-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-nav select {
  width: auto;
}

.preview-area {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background: #0d0d0d;
  min-height: 0;
}

#frame-wrap {
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  flex: none;
  background: var(--surface);
}

#frame-wrap iframe {
  border: 0;
  display: block;
  transform-origin: top left;
  pointer-events: none;
}

/* ——— Conflict banner (409 reload prompt) ——— */

.conflict {
  margin: 12px 20px 0;
  padding: 12px 14px;
  border: 1px solid var(--rule-yellow, #4a3c00);
  border-radius: 8px;
  background: var(--tint-yellow, #1a1800);
  color: var(--ink-1);
  font-size: 12.5px;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.conflict[hidden] {
  display: none;
}

.conflict b {
  color: var(--accent-yellow);
}

/* ——— Export job panel ——— */

.job-panel {
  border-top: 1px solid var(--rule);
  padding: 12px 20px;
  flex-shrink: 0;
  max-height: 220px;
  overflow-y: auto;
}

.job-state {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  margin-bottom: 8px;
}

.job-state.ok {
  color: var(--accent-green);
}

.job-state.warn {
  color: var(--accent-yellow);
}

.chunks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 2px 14px;
  margin-bottom: 8px;
}

.chunk {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

.chunk b {
  font-weight: 500;
  display: inline-block;
  width: 14px;
}

.chunk-done b {
  color: var(--accent-green);
}

.chunk-failed {
  color: var(--down-text);
}

.chunk-failed b {
  color: var(--down-text);
}

.job-error {
  color: var(--down-text);
  margin-bottom: 8px;
  word-break: break-word;
}

.spinner {
  width: 11px;
  height: 11px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent-yellow);
  border-radius: 50%;
  flex: none;
  animation: studio-spin 0.9s linear infinite;
}

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

/* ——— Archive view ——— */

.archive-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 8px;
}

.archive-filters label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.archive-filters input,
.archive-filters select {
  width: auto;
  min-width: 110px;
}

.archive-note {
  color: var(--ink-3);
  padding: 18px 2px;
}

.error {
  color: var(--down-text);
}

.archive-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.archive-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--rule-subtle);
  border-radius: 10px;
  padding: 12px 14px;
}

.archive-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  flex: none;
}

.archive-thumb.placeholder {
  display: block;
}

.archive-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.archive-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.archive-head .badge {
  margin-top: 0;
}

.badge.kind {
  color: var(--accent-periwinkle);
  border-color: var(--rule);
  text-transform: uppercase;
}

.archive-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 400;
}

.archive-title a {
  color: var(--ink-1);
}

.archive-tidm {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-yellow);
}

.archive-template {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
}

.archive-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--ink-2);
  text-decoration: none;
}

.chip.status-published,
.chip.status-sent {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.chip.status-exported,
.chip.status-test_sent {
  color: var(--accent-periwinkle);
}

.chip.publish {
  color: var(--ink-1);
  background: var(--surface-2);
}

.chip.warn {
  color: #000;
  background: var(--accent-yellow);
  border-color: var(--accent-yellow);
}

.archive-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  flex: none;
}

.archive-actions .action {
  font-size: 11.5px;
  padding: 6px 10px;
  min-height: 0;
}

.archive-readonly {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
  align-self: center;
  padding: 6px 0;
}

.archive-downloads summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  padding: 4px 0;
}

.archive-downloads div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

.archive-dl {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-periwinkle);
}

.archive-publish-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 8px;
}

.archive-publish-form[hidden] {
  display: none;
}

.archive-publish-form select,
.archive-publish-form input {
  width: auto;
}

.archive-publish-form input[name="url"] {
  flex: 1;
  min-width: 180px;
}

.archive-pager {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
}

.archive-page-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

/* ——— Templates view ——— */

.tpl-retired-toggle {
  font-size: 12px;
  color: var(--ink-2);
}

.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.tpl-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px;
}

.tpl-card.retired {
  opacity: 0.6;
}

.tpl-thumb {
  border: 1px solid var(--rule-subtle);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  width: 230px;
  align-self: center;
}

.tpl-thumb iframe {
  border: 0;
  display: block;
  transform-origin: top left;
  pointer-events: none;
  background: var(--bg);
}

.tpl-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tpl-thumb-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  text-align: center;
  padding: 0 14px;
  line-height: 1.6;
}

.tpl-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 2px;
}

.tpl-name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tpl-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink-1);
}

.tpl-name-row .badge {
  margin-top: 0;
  flex: none;
}

.badge.class-html {
  color: var(--accent-periwinkle);
  border-color: var(--accent-periwinkle);
}

.badge.class-remotion {
  color: var(--accent-yellow);
  border-color: var(--rule-yellow, #4a3c00);
}

.badge.class-email {
  color: var(--accent-green);
  border-color: var(--rule-green, #003818);
}

.tpl-pills {
  display: flex;
  gap: 6px;
}

.pill-active {
  color: var(--accent-green);
  border-color: var(--rule-green, #003818);
}

.pill-candidate {
  color: var(--accent-yellow);
  border-color: var(--rule-yellow, #4a3c00);
}

.pill-retired {
  color: var(--ink-3);
}

.tpl-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
}

.tpl-actions .action {
  font-size: 11.5px;
  padding: 6px 10px;
  min-height: 0;
  flex: 1;
}

/* —— In-view source editor (copy-on-write) —— */

.tpl-editor {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
  margin-top: 14px;
  min-height: 0;
}

.tpl-source {
  width: 100%;
  min-height: 60vh;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  color: var(--ink-1);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  padding: 12px;
}

.tpl-history {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tpl-versions {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tpl-version {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--rule-subtle);
  border-radius: 8px;
  font-size: 11px;
}

.tpl-history .hint {
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-3);
}

.tpl-editor-error[hidden] {
  display: none;
}

/* ——— Create view ——— */

#source-panel {
  margin: 12px 0 18px;
}

.picker-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.picker-bar .field.date {
  flex: none;
}

.picker-bar .field.grow {
  flex: 1;
  min-width: 160px;
}

.picker-bar .action {
  flex: none;
}

.picker-list {
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--surface);
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}

.picker-list > p {
  padding: 14px;
}

.picker-list .empty {
  padding: 24px 16px;
}

.picker-row {
  display: grid;
  grid-template-columns: 42px 64px 1fr;
  grid-template-areas:
    'time tidm co'
    'time tidm hl';
  column-gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--ink-2);
}

.picker-row:hover {
  background: var(--surface-2);
  color: var(--ink-1);
}

.picker-row.selected {
  border-color: var(--accent-yellow);
  background: var(--surface-2);
  color: var(--ink-1);
}

.picker-row .time {
  grid-area: time;
  color: var(--ink-3);
  align-self: start;
}

.picker-row .tidm {
  grid-area: tidm;
  color: var(--accent-periwinkle);
  align-self: start;
}

.picker-row .co {
  grid-area: co;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--ink-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.picker-row .hl {
  grid-area: hl;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Loading skeleton — the picker's loading state is designed, not blank. */
.picker-skeleton {
  padding: 6px;
}

.skel-row {
  display: flex;
  gap: 10px;
  padding: 9px 6px;
}

.skel {
  display: block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--rule) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.2s ease-in-out infinite;
}

.skel-time {
  width: 38px;
}

.skel-tidm {
  width: 56px;
}

.skel-line {
  flex: 1;
}

@keyframes skel-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Template thumbnails — chosen BEFORE drafting so the prompt is aware. */
.tpl-row {
  display: flex;
  gap: 10px;
  margin: 10px 0 18px;
}

.tpl-thumb {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tpl-thumb:hover {
  border-color: var(--ink-3);
  color: var(--ink-1);
}

.tpl-thumb.active {
  border-color: var(--accent-yellow);
  color: var(--ink-1);
}

.tpl-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-height: 110px;
  border-radius: 6px;
  background: #0d0d0d;
  border: 1px solid var(--rule-subtle);
}

.tpl-art i {
  font-style: normal;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  color: var(--ink-3);
}

.tpl-thumb.active .tpl-art {
  border-color: var(--rule);
}

.tpl-thumb.active .tpl-art i {
  color: var(--accent-yellow);
}

.tpl-name {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
}

.tpl-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-3);
}

.tpl-class {
  font-weight: 400;
}

.tpl-class-html {
  color: var(--accent-periwinkle);
}

.tpl-class-video {
  color: var(--accent-green);
}

/* AI drafting bar */
.copy-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.copy-note {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
}

.copy-note.ok {
  color: var(--accent-green);
}

.copy-note.warn {
  color: var(--accent-yellow);
}

.char-count {
  display: inline;
  margin-left: 6px;
  color: var(--ink-3);
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-mono);
}

.char-count.over {
  color: var(--down-text);
}

/* Create preview column: empty state, frame and the tiktok note stack. */
.preview-area.create-preview {
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.preview-area.create-preview .empty {
  margin: auto;
}

#preview-note {
  max-width: 460px;
  text-align: center;
}

/* ——— Prompt-to-template creation flow (U11) ——— */

.tpl-gen {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.tpl-gen-form {
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 0;
}

.tpl-gen-form textarea {
  resize: vertical;
  min-height: 110px;
}

.tpl-gen-form .hint {
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-3);
}

.tpl-gen-error[hidden] {
  display: none;
}

/* Candidates sit side-by-side; iterating appends rather than replaces. */
.cand-row {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  min-width: 0;
}

.cand-row .empty {
  flex: 1;
}

.cand-card {
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cand-thumb {
  margin: 0;
}

.cand-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

/* AE1: the named-reason rejection list — rule ids verbatim. */
.cand-violations {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-2);
}

.cand-violations li {
  padding: 6px 8px;
  background: var(--down-tint);
  border: 1px solid var(--down-rule);
  border-radius: 6px;
}

.cand-rule {
  font-family: var(--font-mono);
  color: var(--down-text);
  margin-right: 6px;
}

.cand-card .hint {
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-3);
}

.cand-error[hidden] {
  display: none;
}

/* ——— Emails view (U12): generate panel, list, preview + test-send ——— */

.emails .email-generate {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.emails .email-generate .field {
  min-width: 320px;
  margin: 0;
}

.email-warning {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-yellow);
  border: 1px solid var(--rule-yellow, #4a3c00);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 0 0 12px;
  max-width: 560px;
}

.email-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.email-preview-area {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 24px;
  display: flex;
  justify-content: center;
  overflow: auto;
}

.email-preview-area iframe {
  border: 0;
  background: #f5f2eb; /* the email's own body colour */
  height: 75vh;
  max-width: 100%;
}

.email-side .field {
  margin-bottom: 10px;
}

.email-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.email-send-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.email-send-ok {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-green);
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.chip.status-draft {
  color: var(--accent-yellow);
  border-color: var(--rule-yellow, #4a3c00);
}

/* ——— Auth (U16) ——— */

/* Clerk active → the manual token affordance is demoted (hidden). */
body.clerk-active #settings {
  display: none;
}

.conn[data-state="forbidden"] {
  color: var(--down-text);
}

[data-state="forbidden"] .dot {
  background: var(--down-text);
}

/* Full-screen gate: sign-in panel or the no-admin-access state. */
#auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow-y: auto;
  padding: 24px;
}

#auth-gate[hidden] {
  display: none;
}

.auth-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.auth-brand img {
  height: 22px;
  width: auto;
}

.auth-brand .sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

.auth-forbidden[hidden] {
  display: none;
}

.auth-forbidden {
  max-width: 420px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.auth-forbidden h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 16px;
  color: var(--ink-1);
}

.auth-forbidden p {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-2);
}

.auth-forbidden strong {
  color: var(--ink-1);
  font-weight: 600;
}

/* Top-bar identity chip (Clerk signed-in admin). */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.user-chip[hidden] {
  display: none;
}

.user-chip .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  color: var(--ink-1);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.user-chip .email {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ——— Video (U14) ——— */

/* The video render panel sits below the export panel and reuses .job-panel /
   .job-state styling; only the separation and the inline runner hint differ. */
.video-panel {
  margin-top: 12px;
}

.video-panel #video-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.video-panel code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2, rgba(0, 0, 0, 0.06));
}
