/* Tasklab admin. Palette: phase 2.5 blue. No inline styles anywhere: CSP is default-src 'self'.
   Worker page themes (amber, cobalt, emerald, rose) are worker-facing and live in the worker template, not here. */
:root {
  --bg: #0E1116;
  --surface: #161B22;
  --surface-alt: #1C232D;
  --border: #263040;
  --border-focus: #6C8CFF;
  --accent: #6C8CFF;
  --accent-dim: rgba(108,140,255,0.14);
  --accent-border: rgba(108,140,255,0.45);
  --accent-text: #A9BCFF;
  --text: #E6EAF0;
  --text-dim: #AAB4C3;
  --text-faint: #8593A4; /* raised from #7B8797 so it passes 4.5:1 on surface-alt */
  --success: #3DD68C;
  --success-dim: rgba(61,214,140,0.14);
  --danger: #F0616D;
  --danger-dim: rgba(240,97,109,0.14);
  --attention: #B48CFF;
  --attention-dim: rgba(180,140,255,0.16);
  --radius: 10px;
  --radius-sm: 6px;
  --mono: "SF Mono", "Fira Code", ui-monospace, monospace;
  --sidebar-w: 232px;
  --topbar-h: 52px;
  --pad: 24px;
  --card-pad: 16px;
  --gap: 8px;
  --row-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; font-size: 14px; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.boot { padding: 40px; color: var(--text-dim); text-align: center; }
.sr-only { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ---- Shell: sidebar on wide screens, top bar plus drawer below 960 px ---- */
.app-root { min-height: 100vh; }
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.topbar { display: none; }
.drawer-back { display: none; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; padding: 4px 10px 14px; white-space: nowrap; }
.brand span.mark { color: var(--accent); }
.brand .sub { display: block; font-size: 11px; font-weight: 400; color: var(--text-dim); margin-top: 1px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--text-dim); font-weight: 500; font-size: 13px; min-height: 36px; }
.nav a:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-dim); color: var(--accent-text); }
.nav-section { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); padding: 12px 10px 4px; }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--gap); font-size: 12px; color: var(--text-dim); }
.sidebar-foot strong { color: var(--text); font-weight: 600; }
.main { padding: var(--pad) var(--pad) 60px; min-width: 0; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.page-head .sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.page-actions { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; }

@media (max-width: 959px) {
  .layout { display: block; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 120; height: var(--topbar-h); padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
  .topbar .brand { padding: 0; font-size: 16px; }
  .topbar .brand .sub { display: none; }
  .topbar-title { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; }
  .hamburger { width: 40px; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-alt); color: var(--text); font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: min(300px, 85vw); z-index: 140; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 0 40px rgba(0,0,0,0.5); height: 100vh; }
  .drawer-open .sidebar { transform: translateX(0); }
  .drawer-back { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 130; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .drawer-open .drawer-back { opacity: 1; pointer-events: auto; }
  .nav a { min-height: 44px; font-size: 14px; }
  .sidebar-foot .btn { min-height: 40px; }
}

/* ---- Auth screens ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--pad); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px 26px 22px; }
.auth-card .brand { padding: 0 0 16px; }
.auth-card h2 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.auth-card p.hint { font-size: 12px; color: var(--text-dim); margin-bottom: 16px; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.auth-foot { margin-top: 14px; font-size: 12px; color: var(--text-dim); text-align: center; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 8px 14px; min-height: 36px; border-radius: var(--radius-sm); border: 1px solid transparent; font-weight: 600; font-size: 13px; font-family: inherit; cursor: pointer; transition: opacity 0.15s, transform 0.1s, border-color 0.15s; white-space: nowrap; color: var(--text); background: var(--surface-alt); border-color: var(--border); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover { opacity: 0.92; }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }
.btn-danger { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.btn-accent-ghost { background: var(--accent-dim); color: var(--accent-text); border: 1px dashed var(--accent-border); }
.btn-accent-ghost:hover { border-style: solid; }
.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 32px; }
.btn-icon { padding: 0; width: 34px; height: 34px; background: transparent; border: 1px solid var(--border); color: var(--text-dim); font-size: 15px; line-height: 1; border-radius: var(--radius-sm); cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { border-color: var(--text-dim); color: var(--text); }
.btn-icon:disabled { opacity: 0.4; cursor: default; }
.link-btn { background: none; border: none; color: var(--accent-text); cursor: pointer; font: inherit; padding: 0; text-align: left; }
.link-btn:hover { text-decoration: underline; }

/* tooltip: one body-level element (ui.js installTooltips), fixed so it never widens the page */
.tip { position: fixed; top: 0; left: 0; background: var(--surface-alt); border: 1px solid var(--border); color: var(--text); padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 500; white-space: nowrap; z-index: 90; pointer-events: none; max-width: min(320px, calc(100vw - 8px)); box-shadow: 0 6px 20px rgba(0,0,0,0.4); }
.tip[hidden] { display: none; }

/* inline svg icons (icons.js) */
.icon { width: 16px; height: 16px; flex: 0 0 auto; vertical-align: -3px; }
.btn .icon { margin-right: 2px; }
.btn-icon .icon { margin: 0; }

/* row actions: icons at 1280+, a menu between 768 and 1279, labeled buttons in card mode */
.act { display: flex; justify-content: flex-end; gap: 4px; align-items: center; }
.act-labels { display: none; flex-wrap: wrap; gap: var(--gap); }
.act-labels .btn { min-height: 40px; }
.act-menu { display: none; position: relative; }
.act-menu .menu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 170px; z-index: 70; box-shadow: 0 10px 30px rgba(0,0,0,0.5); padding: 4px; display: none; }
.act-menu.open .menu { display: block; }
.act-menu .menu button { display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text); font: inherit; font-size: 13px; padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.act-menu .menu button:hover { background: var(--accent-dim); color: var(--accent-text); }
.act-menu .menu button:disabled { color: var(--text-faint); cursor: default; background: none; }
.act-menu .menu button.danger { color: var(--danger); }
@media (max-width: 1279px) { .act-icons { display: none; } .act-menu { display: block; } }
@media (max-width: 767px) { .act-menu { display: none; } .act-labels { display: flex; } }

/* ---- Forms ---- */
.field { margin-bottom: 12px; min-width: 0; }
.field-label { display: block; font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.field-input, .field-textarea, .field-select { width: 100%; padding: 9px 11px; min-height: 36px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 13px; font-family: inherit; outline: none; transition: border-color 0.15s; }
.field-input:focus, .field-textarea:focus, .field-select:focus { border-color: var(--border-focus); }
.field-input:disabled, .field-select:disabled { color: var(--text-dim); }
.field-input::placeholder, .field-textarea::placeholder { color: var(--text-faint); }
.field-input[readonly] { color: var(--text-dim); background: var(--surface-alt); }
.field-textarea { resize: vertical; min-height: 40px; line-height: 1.5; }
.field-hint { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.field-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.field-input-sm { width: 110px; }
.field-inline { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; } .ml { margin-left: 8px; }
.row { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--gap); flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.toggle-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.toggle-row label:not(.toggle) { font-size: 13px; color: var(--text); cursor: pointer; flex: 1; }
.toggle { position: relative; display: block; width: 40px; height: 22px; flex: 0 0 40px; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle .slider { position: absolute; inset: 0; background: var(--border); border-radius: 22px; cursor: pointer; transition: background 0.2s; }
.toggle .slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(18px); }
.toggle input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle input:disabled + .slider { opacity: 0.5; }
.check { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
@media (max-width: 719px) {
  .field-row, .field-row-2, .field-row-4 { grid-template-columns: 1fr; }
  .field-input-sm { width: 100%; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters > * { width: 100% !important; min-width: 0 !important; }
}
@media (max-width: 767px) {
  .btn, .btn-icon, .field-input, .field-select, .tab, .hamburger { min-height: 40px; }
  .btn-icon { width: 40px; height: 40px; }
  .btn-sm { min-height: 40px; }
  .check { width: 22px; height: 22px; }
}

/* ---- Cards, badges, status ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px var(--card-pad); border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; flex-wrap: wrap; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head .badge { margin-left: 6px; }
.card-body { padding: var(--card-pad); }
.status-bar { padding: 9px 12px; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm); margin-bottom: 12px; }
.status-bar.success { background: var(--success-dim); color: var(--success); }
.status-bar.error { background: var(--danger-dim); color: var(--danger); }
.status-bar.warn { background: var(--attention-dim); color: var(--attention); }
.empty { padding: 40px 20px; text-align: center; color: var(--text-dim); font-size: 13px; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 6px; }
.empty-action { margin-top: 12px; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--surface-alt); color: var(--text-dim); border: 1px solid transparent; white-space: nowrap; }
.badge.accent { background: var(--accent-dim); color: var(--accent-text); }
.badge.success { background: var(--success-dim); color: var(--success); }
.badge.attention { background: var(--attention-dim); color: var(--attention); }
.badge.danger { background: var(--danger-dim); color: var(--danger); }
.badge.faint { color: var(--text-faint); border-color: var(--border); background: transparent; }
.mono { font-family: var(--mono); font-size: 12px; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px var(--card-pad); }
.stat .n { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat .l { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--text-faint); vertical-align: middle; border: 1px solid transparent; }
.status-dot.active { background: var(--success); } .status-dot.paused { background: var(--attention); }
.status-dot.draft { background: var(--text-faint); } .status-dot.archived { background: transparent; border-color: var(--text-faint); }
.toasts { position: fixed; bottom: 18px; right: 18px; left: 18px; display: flex; flex-direction: column; gap: var(--gap); z-index: 200; align-items: flex-end; pointer-events: none; }
.toast { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; font-weight: 500; min-width: 200px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); pointer-events: auto; }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; }
.spinner-wrap { display: inline-flex; align-items: center; gap: var(--gap); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Filter bar ---- */
.filters { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters .field-input, .filters .field-select { width: auto; min-width: 130px; padding: 7px 10px; }
.filters .field-input[data-search] { min-width: 220px; flex: 1; }
.filters .toggle-row { padding: 0; }
.bulk-bar { display: flex; gap: var(--gap); align-items: center; flex-wrap: wrap; padding: 8px 12px; background: var(--accent-dim); border: 1px solid var(--accent-border); border-radius: var(--radius-sm); margin-bottom: 10px; font-size: 13px; }

/* ---- Tables: real table from 768 px, stacked cards below ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
.table th { text-align: left; padding: 0 12px; height: 40px; font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 6px 12px; height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-alt); }
.table tr.selected { background: var(--accent-dim); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.th-sort { background: none; border: none; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; min-height: 0; }
.th-sort.active { color: var(--accent-text); }
.th-sort.active.asc::after { content: ' \2191'; }
.th-sort.active.desc::after { content: ' \2193'; }
.cell-title { font-weight: 600; color: var(--text); }
.cell-title a { color: inherit; }
.cell-sub { font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.cell-clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* low-priority columns need about 250 px; with the 232 px sidebar they only fit from 1440 px */
@media (max-width: 1439px) { .table .col-low { display: none; } .cell-clip { max-width: 220px; } }
@media (min-width: 1280px) and (max-width: 1439px) { .act-icons .btn-icon { width: 30px; height: 30px; font-size: 13px; } .act-icons { gap: 2px; } .table td, .table th { padding-left: 8px; padding-right: 8px; } }
@media (max-width: 767px) {
  .table-wrap { background: transparent; border: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  .table tr.selected { background: var(--accent-dim); }
  .table tbody tr:hover { background: var(--surface); }
  .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; height: auto; min-height: 40px; padding: 6px var(--card-pad); border-bottom: 1px solid var(--border); text-align: left !important; white-space: normal; }
  .table td:last-child { border-bottom: none; }
  .table td::before { content: attr(data-label); font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; flex: 0 0 auto; }
  .table td[data-label=""]::before { display: none; }
  .table td[data-label=""] { justify-content: flex-start; }
  .table td.actions { display: block; }
  .table td.actions .act { justify-content: flex-start; }
  .table .col-low { display: flex; }
  .cell-clip { max-width: none; white-space: normal; }
}

/* ---- Modal: centered dialog, full-screen sheet below 768 px ---- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 150; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.5); min-width: 0; }
.modal-sm { max-width: 420px; } .modal-md { max-width: 640px; } .modal-lg { max-width: 960px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.modal-head h2 { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.modal-body { padding: var(--card-pad) 18px; overflow: auto; flex: 1 1 auto; min-height: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--gap); padding: 12px 18px; border-top: 1px solid var(--border); flex: 0 0 auto; flex-wrap: wrap; }
@media (max-width: 767px) {
  .modal-back { padding: 0; align-items: stretch; }
  .modal { max-width: none; max-height: none; height: 100%; border-radius: 0; border: none; }
  .modal-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
  .modal-actions { position: sticky; bottom: 0; background: var(--surface); }
  .modal-actions .btn { flex: 1; }
}

/* ---- Chips ---- */
.chips-root { width: 100%; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); min-height: 40px; align-items: center; }
.chips:focus-within { border-color: var(--border-focus); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; background: var(--accent-dim); color: var(--accent-text); font-size: 12px; font-weight: 500; border: 1px solid var(--accent-border); max-width: 100%; }
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { background: none; border: none; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.chip-suggest { background: var(--surface-alt); color: var(--text-dim); border-color: var(--border); cursor: pointer; }
.chip-suggest:hover { color: var(--text); border-color: var(--text-dim); }
.chips-input { flex: 1; min-width: 120px; background: transparent; border: none; color: var(--text); font: inherit; font-size: 13px; outline: none; min-height: 26px; }
.chips-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; align-items: center; }
.chips-suggest-label { font-size: 11px; }

/* ---- Cascade ---- */
.cascade { display: flex; flex-direction: column; }
.cascade-row { display: grid; grid-template-columns: 1.3fr 1.2fr auto auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cascade-row:last-child { border-bottom: none; }
.cascade-row:not(.overridden) .cascade-control { opacity: 0.6; }
.cascade-label { display: flex; flex-direction: column; font-size: 13px; min-width: 0; }
.cascade-key { font-size: 10px; }
.cascade-control { min-width: 0; }
.cascade-switch { display: flex; align-items: center; gap: 6px; }
.cascade-switch-label { font-size: 11px; }
@media (max-width: 719px) {
  .cascade-row { grid-template-columns: 1fr; gap: 6px; padding: 10px 0; }
  .cascade-row .cascade-prov, .cascade-row .cascade-switch { justify-self: start; }
  .cascade-control .field-input-sm { width: 100%; }
}

/* ---- Tabs ---- */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 9px 16px; font-size: 13px; font-weight: 600; font-family: inherit; background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--text-dim); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }

/* ---- Video grid and cards ---- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.video-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; cursor: pointer; min-width: 0; }
.video-card:hover { border-color: var(--text-dim); }
.video-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.video-card.disabled { opacity: 0.6; cursor: default; }
.video-card .thumb { aspect-ratio: 16 / 9; background: var(--surface-alt); display: block; width: 100%; object-fit: cover; }
.video-card .thumb-ph { aspect-ratio: 16 / 9; background: var(--surface-alt); display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: 12px; }
.video-card .body { padding: 8px 10px 10px; }
.video-card .title { font-size: 12px; font-weight: 600; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.video-card .meta { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.video-card .check { position: absolute; top: 8px; left: 8px; }
.video-card .dur { position: absolute; top: 8px; right: 8px; background: rgba(14,17,22,0.8); color: var(--text); font-size: 11px; padding: 1px 6px; border-radius: 4px; font-family: var(--mono); }
.thumb-sm { width: 96px; flex: 0 0 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; background: var(--surface-alt); display: block; }
.thumb-md { width: 200px; max-width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: var(--surface-alt); display: block; }
.pager { display: flex; gap: var(--gap); align-items: center; justify-content: center; margin-top: 14px; font-size: 13px; color: var(--text-dim); flex-wrap: wrap; }
@media (max-width: 479px) { .video-grid { grid-template-columns: 1fr 1fr; gap: 8px; } .video-card .body { padding: 6px 8px 8px; } }

/* ---- Campaign editor ---- */
.cv-list { display: flex; flex-direction: column; gap: var(--gap); }
.cv-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cv-row.dragging { opacity: 0.4; }
.cv-row.drop-before { box-shadow: 0 -3px 0 0 var(--accent); }
.cv-row.drop-after { box-shadow: 0 3px 0 0 var(--accent); }
.cv-row.disabled .cv-head { opacity: 0.55; }
.cv-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; min-height: var(--row-h); }
.cv-head:hover { background: var(--surface-alt); }
.cv-handle { cursor: grab; color: var(--text-faint); font-size: 16px; padding: 0 2px; user-select: none; display: inline-flex; align-items: center; }
.cv-handle:active { cursor: grabbing; }
.cv-pos { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--bg); font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cv-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; }
.cv-title .cv-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-title .cell-sub { font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--text-dim); justify-content: flex-end; }
.cv-body { padding: 12px var(--card-pad) 14px; border-top: 1px solid var(--border); display: none; }
.cv-row.open .cv-body { display: block; }
.cv-video-card { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.cv-video-card .info { font-size: 12px; color: var(--text-dim); min-width: 200px; }
.cv-video-card .info strong { color: var(--text); display: block; font-size: 13px; margin-bottom: 2px; }
.tagline { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tagline .badge { font-weight: 500; }
.section-title { font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin: 14px 0 6px; }
.slug-check { font-size: 11px; margin-top: 3px; }
.slug-check.ok { color: var(--success); } .slug-check.bad { color: var(--danger); }
.url-box { display: flex; gap: 6px; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 6px 6px 10px; font-family: var(--mono); font-size: 12px; min-width: 0; }
.url-box span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
@media (max-width: 719px) {
  .cv-head { flex-wrap: wrap; }
  .cv-meta { width: 100%; justify-content: flex-start; padding-left: 32px; }
  .thumb-sm { width: 72px; flex-basis: 72px; }
}

/* ---- Templates ---- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
@media (max-width: 419px) { .tpl-grid { grid-template-columns: 1fr; } }
.tpl-card .card-head { flex-wrap: nowrap; }
.tpl-card .card-head .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; margin-bottom: 10px; }
.tpl-facts dt { color: var(--text-dim); }
.tpl-facts dd { color: var(--text); }
.tpl-steps { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.tpl-steps li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; padding: 4px 0; }
.tpl-steps li .n { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--bg); font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.tpl-steps li.off { color: var(--text-faint); }
.tpl-steps li.off .n { background: var(--border); color: var(--text-faint); }
.step-row { display: grid; grid-template-columns: 28px 1fr 200px; gap: 10px; align-items: start; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: var(--gap); }
.step-row.system { border-color: var(--accent-border); background: var(--accent-dim); }
.step-row.off { opacity: 0.7; }
.step-row .step-num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--bg); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 4px; }
.step-row.off .step-num { background: var(--border); color: var(--text-faint); }
.step-fields { min-width: 0; }
.step-fields .field { margin-bottom: 8px; }
.step-fields .field-row-2 { gap: 8px; }
.step-controls { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.step-controls .row { gap: 4px; }
@media (max-width: 719px) { .step-row { grid-template-columns: 28px 1fr; } .step-controls { grid-column: 2; } }
.preview-box { border-radius: 12px; padding: 16px; border: 1px solid var(--border); background: #111; color: #e8e8e8; }
.preview-box .label { display: inline-block; background: #f59e0b; color: #000; font-weight: 700; font-size: 11px; padding: 3px 9px; border-radius: 3px; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em; }
.preview-box ol { counter-reset: step; list-style: none; padding: 0; }
.preview-box li { counter-increment: step; position: relative; padding: 8px 0 8px 36px; border-bottom: 1px solid #222; font-size: 13px; }
.preview-box li::before { content: counter(step); position: absolute; left: 0; top: 8px; width: 24px; height: 24px; background: #f59e0b; color: #000; font-weight: 700; font-size: 11px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.preview-box .val { display: inline-block; background: rgba(245,158,11,0.13); border: 1px solid rgba(245,158,11,0.4); color: #f59e0b; font-weight: 700; padding: 1px 8px; border-radius: 4px; font-family: var(--mono); }
.preview-note { font-size: 11px; color: var(--text-dim); margin-top: 6px; }
.placeholder-help { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.placeholder-help .badge { cursor: pointer; }

/* ---- Channels ---- */
.sync-progress { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: var(--gap); flex-wrap: wrap; }
.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; width: 140px; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.3s; }

/* ---- Niches ---- */
.niche-row { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; flex-wrap: wrap; }
.niche-row.dragging { opacity: 0.4; }
.niche-row .grow { font-weight: 600; font-size: 13px; }
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 800px) { .editor-grid { grid-template-columns: 1fr; } }

/* ---- Phase 3: preview and QR ---- */
.url-row { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.qr-box { background: #fff; padding: 6px; border-radius: var(--radius-sm); line-height: 0; flex: 0 0 auto; }
.qr-box canvas { display: block; width: 140px; height: 140px; image-rendering: pixelated; }
.preview-frame { background: #111; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 0 auto; }
.preview-frame.desktop { width: 100%; height: 720px; }
.preview-frame.phone { width: 390px; max-width: 100%; height: 720px; border-radius: 24px; border-width: 6px; border-color: var(--surface-alt); }
.preview-iframe { display: block; width: 100%; height: 100%; border: none; background: #111; }
@media (max-width: 767px) { .preview-frame.desktop, .preview-frame.phone { height: 70vh; } }

/* ---- Phase 4: dynamic rules, change review, import, stats, logs, settings tabs ---- */
.dyn-status .dyn-last { font-size: 12px; }
.dyn-list { display: flex; flex-direction: column; gap: var(--gap); }
.dyn-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); min-height: var(--row-h); }
.dyn-row.disabled { opacity: 0.6; }
@media (max-width: 719px) { .dyn-row { flex-wrap: wrap; } .dyn-row .cv-meta { width: 100%; justify-content: flex-start; padding-left: 32px; } }
.badge-btn { cursor: pointer; font-family: inherit; }
.badge-btn:hover { border-color: var(--attention); }
.review-grid { display: grid; grid-template-columns: 160px 1fr 1fr; gap: 8px 12px; align-items: start; }
.review-head { font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.review-field { font-size: 13px; padding-top: 6px; }
.review-cell { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; min-width: 0; word-break: break-word; }
.review-cell.new { border-color: var(--accent-border); }
.review-thumb { width: 100%; max-width: 320px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 4px; background: var(--surface-alt); }
@media (max-width: 719px) { .review-grid { grid-template-columns: 1fr; } .review-head { display: none; } }
.drop-zone { border: 2px dashed var(--accent-border); border-radius: var(--radius); padding: 36px 20px; text-align: center; display: flex; flex-direction: column; gap: 4px; cursor: pointer; background: var(--accent-dim); color: var(--text); }
.drop-zone:hover, .drop-zone.over, .drop-zone:focus-visible { border-style: solid; border-color: var(--accent); }
.drop-zone strong { font-size: 15px; }
.chart-wrap { overflow: hidden; }
.chart { display: block; width: 100%; height: 260px; }
.log-list { display: flex; flex-direction: column; font-size: 12px; }
.log-line { display: grid; grid-template-columns: 140px 64px 1fr; gap: 10px; align-items: start; padding: 6px var(--card-pad); border-bottom: 1px solid var(--border); }
.log-line:last-child { border-bottom: none; }
.log-line.error { background: var(--danger-dim); }
.log-line.warn { background: var(--attention-dim); }
.log-ts { color: var(--text-dim); white-space: nowrap; }
.log-msg { color: var(--text); word-break: break-word; }
.log-ctx { color: var(--text-dim); grid-column: 3; word-break: break-all; }
@media (max-width: 719px) { .log-line { grid-template-columns: 1fr; gap: 4px; } .log-ctx { grid-column: 1; } }
.code-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; margin-top: 8px; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.theme-swatches { display: flex; gap: 8px; margin-top: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--border); }
.stat-link { color: inherit; display: block; }
.stat-link:hover { text-decoration: none; border-color: var(--accent-border); }
.stat .n.attention { color: var(--attention); }

/* ---- Duration input: value plus the other form live ---- */
.dur-input { display: flex; align-items: center; gap: 8px; min-width: 0; }
.dur-input .field-input { flex: 1; min-width: 0; }
.dur-hint { font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dur-hint.bad { color: var(--danger); }
.field-input.invalid { border-color: var(--danger); }

/* ---- Thumbnail upload zone (manual rows and row overrides) ---- */
.drop-zone { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; min-height: 44px; }
.drop-zone:hover, .drop-zone.over { border-color: var(--accent-border); background: var(--accent-dim); }
.drop-zone .thumb-sm { flex: 0 0 auto; }
.drop-zone .dz-text { font-size: 12px; color: var(--text-dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Save state in the editor head ---- */
.save-state { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.save-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--attention); display: inline-block; }
.btn.dirty::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--attention); display: inline-block; margin-right: 6px; }

/* ---- Overview health sections ---- */
.health { display: grid; gap: 12px; }
.health details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.health summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px var(--card-pad); font-weight: 600; font-size: 13px; user-select: none; }
.health summary::-webkit-details-marker { display: none; }
.health summary .icon-chevron-down { transition: transform 0.15s; color: var(--text-dim); }
.health details[open] summary .icon-chevron-down { transform: rotate(180deg); }
.health summary .grow { flex: 1; }
.health .h-body { padding: 0 var(--card-pad) var(--card-pad); }
.health .table-wrap { border-left: none; border-right: none; border-bottom: none; border-radius: 0; }
.meter { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; width: 100%; max-width: 360px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.meter > span.hot { background: var(--danger); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 13px; align-items: baseline; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.problem { display: grid; grid-template-columns: 150px 52px 1fr; gap: 8px; font-size: 12px; padding: 4px 0; border-bottom: 1px solid var(--border); font-family: "SF Mono", "Fira Code", monospace; }
.problem:last-child { border-bottom: none; }
.problem .lvl.error { color: var(--danger); }
.problem .lvl.warn { color: var(--attention); }
.problem .msg { overflow-wrap: anywhere; }
