/* ============ 1. Design tokens ============ */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeeea;
  --border: #e2ded6;
  --border-strong: #cfc9bc;
  --text: #1c1917;
  --text-2: #57534e;
  --muted: #8a8478;
  --accent: #1c1917;
  --accent-text: #fafaf9;
  --accent-soft: #e7e5e0;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --warning: #b45309;
  --warning-soft: #fdf3e3;
  --success: #15803d;
  --success-soft: #e9f7ee;
  --focus: #2563eb;
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgb(28 25 23 / 0.05);
  --shadow: 0 4px 16px rgb(28 25 23 / 0.1);
  --sidebar-w: 232px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: Charter, Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-title: 1.375rem;
  --fs-section: 1.05rem;
  --fs-card: 0.95rem;
  --fs-body: 0.875rem;
  --fs-meta: 0.75rem;
}

html[data-theme="dark"] {
  --bg: #121110;
  --surface: #1c1a18;
  --surface-2: #262320;
  --border: #2e2a26;
  --border-strong: #453f37;
  --text: #ece7df;
  --text-2: #c9c2b6;
  --muted: #8f877a;
  --accent: #ece7df;
  --accent-text: #1c1a18;
  --accent-soft: #2e2a26;
  --danger: #f87171;
  --danger-soft: #2a1a1a;
  --warning: #fbbf24;
  --warning-soft: #2a2113;
  --success: #4ade80;
  --success-soft: #14261a;
  --focus: #60a5fa;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow: 0 8px 28px rgb(0 0 0 / 0.45);
  color-scheme: dark;
}

/* ============ 2. Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 0.35em; line-height: 1.25; }
h1 { font-size: var(--fs-title); letter-spacing: -0.01em; }
h1.display { font-family: var(--font-display); font-size: 1.6rem; }
h2 { font-size: var(--fs-section); }
a { color: inherit; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button { cursor: pointer; font: inherit; }

/* ============ 3. Layout ============ */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 1rem 1.1rem 0.6rem; font-family: var(--font-display); font-size: 1.15rem; }
.brand small { display: block; font-family: var(--font); font-size: var(--fs-meta); color: var(--muted); margin-top: 2px; }
.nav { padding: 0.4rem 0.6rem; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; flex: 1; }
.nav h4 { margin: 0.9rem 0.5rem 0.3rem; font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.nav a {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text-2);
  text-decoration: none;
  font-size: 0.875rem;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.side-foot { border-top: 1px solid var(--border); padding: 0.7rem 1rem; font-size: var(--fs-meta); color: var(--muted); }
.side-foot .row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 30;
}
.topbar .crumb { font-size: var(--fs-meta); color: var(--muted); }
.topbar .spacer { flex: 1; }
.content { padding: 1.25rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head p.sub { margin: 0.15rem 0 0; color: var(--text-2); }
.menu-btn { display: none; }
body.side-collapsed .sidebar { display: none; }

/* ============ 4. Components ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}
.card h2 { font-size: var(--fs-section); margin-bottom: 0.6rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  height: 2.25rem; padding: 0 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem; font-weight: 500; text-decoration: none;
  transition: transform 80ms ease, background 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.12); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { height: 1.9rem; padding: 0 0.6rem; font-size: 0.8rem; }
.btn-link { background: none; border: none; padding: 0; height: auto; color: var(--text-2); text-decoration: underline; font-size: 0.8rem; }
.field { margin-bottom: 0.8rem; }
.field > label { display: block; font-size: var(--fs-meta); font-weight: 600; color: var(--text-2); margin-bottom: 0.3rem; }
.field .req { color: var(--danger); }
.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 0.875rem;
  padding: 0.5rem 0.65rem;
}
.input:focus { border-color: var(--focus); outline: 2px solid var(--focus); outline-offset: 0; }
textarea.input { min-height: 7rem; resize: vertical; font-family: var(--font-mono); font-size: 0.82rem; }
.field .hint { font-size: var(--fs-meta); color: var(--muted); margin-top: 0.25rem; }
.field .error { font-size: var(--fs-meta); color: var(--danger); margin-top: 0.25rem; font-weight: 600; }
.field.invalid .input { border-color: var(--danger); }
.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  font-size: var(--fs-meta);
  font-weight: 600;
  white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip.st-draft .dot { background: var(--muted); }
.chip.st-in_progress .dot { background: var(--warning); }
.chip.st-ready .dot, .chip.st-published .dot { background: var(--success); }
.chip.st-archived { color: var(--muted); }
.chip.warn { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.chip.ok { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.chip.bad { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.mono { font-family: var(--font-mono); font-size: 0.78em; }
.muted { color: var(--muted); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.tbl th {
  text-align: left; font-size: var(--fs-meta); text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600;
  padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .row-actions { visibility: hidden; white-space: nowrap; }
.tbl tbody tr:hover .row-actions, .tbl tbody tr:focus-within .row-actions { visibility: visible; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end; margin-bottom: 1rem; }
.toolbar .field { margin-bottom: 0; min-width: 150px; }
.fchip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.2rem 0.3rem 0.2rem 0.65rem; font-size: 0.8rem;
}
.fchip button { border: none; background: none; color: var(--muted); font-size: 0.9rem; line-height: 1; padding: 0 0.3rem; }
.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.75rem; font-size: 0.85rem; color: var(--text-2); }
.alert { border-radius: var(--radius); padding: 0.65rem 0.85rem; margin-bottom: 1rem; font-size: 0.875rem; }
.alert.ok { background: var(--success-soft); border: 1px solid var(--success); color: var(--success); }
.alert.err { background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-2); }
.empty h3 { font-family: var(--font-display); font-size: 1.1rem; color: var(--text); }
.skel { border-radius: var(--radius-sm); background: var(--surface-2); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } * { transition: none !important; } }

/* modal */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; }
.overlay[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); width: 100%; max-width: 32rem; }
.modal.wide { max-width: 44rem; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: var(--fs-card); }
.modal-body { padding: 1.1rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.9rem 1.1rem; border-top: 1px solid var(--border); }
.x { background: none; border: none; font-size: 1.1rem; color: var(--muted); padding: 0.2rem 0.5rem; border-radius: var(--radius-sm); }
.x:hover { background: var(--surface-2); color: var(--text); }

/* toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 80; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--success); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.6rem 0.85rem; font-size: 0.85rem; max-width: 22rem; }
.toast.err { border-left-color: var(--danger); }

/* ============ 5. Pages ============ */
/* stepper */
.stepper { list-style: none; margin: 0; padding: 0; }
.stepper li { display: flex; gap: 0.7rem; }
.stepper .rail { display: flex; flex-direction: column; align-items: center; }
.stepper .mk {
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  border: 2px solid var(--border-strong); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; background: var(--surface); flex-shrink: 0;
}
.stepper li.done .mk { background: var(--success); border-color: var(--success); color: #fff; }
.stepper li.now .mk { border-color: var(--accent); color: var(--text); font-weight: 700; box-shadow: 0 0 0 3px var(--accent-soft); }
.stepper .ln { width: 2px; flex: 1; min-height: 0.9rem; background: var(--border); margin: 2px 0; }
.stepper li.done .ln { background: var(--success); }
.stepper .tx { padding-bottom: 1rem; }
.stepper .tx b { display: block; }
.stepper li.future .tx b { color: var(--muted); font-weight: 500; }
.stepper li.now .tx b { font-size: 1rem; }
/* kanban */
.board { display: flex; gap: 0.75rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; }
.col { width: 270px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.col header { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--surface); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.col header .n { font-size: var(--fs-meta); color: var(--muted); font-weight: 500; }
.col .cards { padding: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; min-height: 4rem; }
.ccard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.55rem 0.65rem; cursor: grab; }
.ccard:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.ccard h4 { margin: 0 0 0.2rem; font-size: 0.85rem; }
.ccard .meta { font-size: var(--fs-meta); color: var(--muted); }
.col.dragover { border-color: var(--accent); background: var(--surface-2); }
.ccard.dragging { opacity: 0.5; }
/* calendar */
.cal { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.cal th { font-size: var(--fs-meta); text-transform: uppercase; color: var(--muted); padding: 0.5rem; border-bottom: 1px solid var(--border); width: 14.28%; }
.cal td { border: 1px solid var(--border); vertical-align: top; height: 6.5rem; padding: 0.3rem; width: 14.28%; }
.cal td.dim { background: var(--surface-2); color: var(--muted); }
.cal td.today { background: var(--accent-soft); }
.cal .dnum { font-size: var(--fs-meta); font-weight: 600; }
.cal .ev {
  display: block; font-size: 0.75rem; text-decoration: none;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 0.1rem 0.35rem; margin-top: 0.2rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal .ev:hover { border-color: var(--accent); }
.cal .ev .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); margin-right: 0.3rem; }
.cal .ev.s-in_progress .dot, .cal .ev.s-ready .dot { background: var(--warning); }
.cal .ev.s-published .dot { background: var(--success); }
.calnav { display: flex; align-items: center; gap: 0.5rem; }
.calnav h2 { margin: 0 0.5rem; min-width: 10rem; text-align: center; }
/* workflow editor */
.flow { display: flex; flex-direction: column; gap: 0; }
.fnode { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.8rem 1rem; }
.fnode .arrow { text-align: center; color: var(--muted); font-size: 1.1rem; line-height: 1; margin-top: 0.6rem; }
.fnode-head { display: flex; align-items: center; gap: 0.6rem; }
.fnode-head .idx { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }
.fnode-head h3 { margin: 0; }
.fnode-head .acts { margin-left: auto; display: flex; gap: 0.25rem; }
/* detail header */
.dhead { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0.4rem 0 0; }
.hist summary { cursor: pointer; padding: 0.55rem 0; font-weight: 600; }
.hist .body { border-left: 2px solid var(--border); margin-left: 0.3rem; padding: 0.2rem 0 0.8rem 0.9rem; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 0.3rem 0.8rem; font-size: 0.875rem; }
.kv dt { color: var(--muted); }

/* ============ 6. Responsive ============ */
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; transform: translateX(-100%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 0.9rem; }
  .tbl-wrap { overflow-x: auto; }
  .scrim { position: fixed; inset: 0; background: rgb(0 0 0 / 0.4); z-index: 55; }
}
@media (min-width: 901px) { .scrim { display: none; } }

/* Touch devices have no hover: Edit/Duplicate/Archive must always show. */
@media (hover: none) {
  .tbl .row-actions { visibility: visible; }
}

/* File picker matches text inputs; button part reads as a small button. */
input[type="file"].input { padding: 0.35rem 0.5rem; font-size: 0.82rem; }
input[type="file"].input::file-selector-button {
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 0.8rem; font-weight: 600;
  padding: 0.35rem 0.7rem; margin-right: 0.6rem; cursor: pointer;
}

/* Workflow editor header: Modify + version controls share one row. */
.wf-actions { display: flex; gap: 0.5rem; align-items: end; flex-wrap: nowrap; overflow-x: auto; }
.wf-actions .btn { white-space: nowrap; flex-shrink: 0; }

/* Delete preview list. */
.del-list { list-style: none; margin: 0.6rem 0 0; padding: 0; }
.del-list li {
  display: flex; gap: 0.5rem; align-items: baseline;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem; margin-bottom: 0.35rem; font-size: 0.875rem;
}
#delAckWrap { margin-top: 0.7rem; }
#delAckWrap[hidden] { display: none; }

/* ============ 8. Small phones: stack filters, sticky actions, bottom-sheet modals ============ */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; row-gap: 0.4rem; }
  .topbar .crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .page-head { flex-direction: column; align-items: stretch; }
  .wf-actions { flex-wrap: wrap; overflow: visible; }
  .toolbar .field { flex: 1 1 100%; min-width: 0; }
  .tbl-wrap { overflow-x: visible; }
  .tbl { font-size: 0.85rem; }
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; }
  .tbl tr { border-bottom: 2px solid var(--border); padding: 0.55rem 0.8rem; }
  .tbl tbody tr:hover { background: none; }
  .tbl td { border: 0; padding: 0.18rem 0; text-align: left !important; white-space: normal !important; }
  .tbl td::before {
    content: attr(data-label); display: block;
    font-size: 0.66rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--muted);
  }
  .tbl td.no-label::before { content: none; }
  .tbl td.cell-title { font-size: 0.95rem; padding-bottom: 0.3rem; }
  .tbl td.row-actions { position: static; background: none; box-shadow: none; padding-top: 0.45rem; visibility: visible; }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { max-width: 100%; width: 100%; max-height: 92vh; overflow-y: auto; border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0; }
  .col { width: 240px; }
  .cal td { height: 4.2rem; padding: 0.2rem; }
  .cal .ev { font-size: 0.7rem; }
  .kv { grid-template-columns: 110px 1fr; }
  .dhead .chip { font-size: 0.7rem; }
  .pager, .modal-foot { flex-wrap: wrap; }
  /* Add-item buttons become a single + FAB stuck bottom-right. */
  .topbar .btn.fab {
    position: fixed; right: 1rem; bottom: 1rem; z-index: 40;
    width: 3.4rem; height: 3.4rem; border-radius: 50%;
    padding: 0; overflow: hidden; white-space: nowrap; color: transparent;
    background: var(--accent); border-color: var(--accent); box-shadow: var(--shadow);
  }
  .topbar .btn.fab::after {
    content: "+"; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent-text); font-size: 1.7rem; line-height: 1;
  }
}

/* dynamic field helpers */
.url-row { display: flex; align-items: center; gap: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.35rem 0.5rem; margin-bottom: 0.35rem; background: var(--surface); }
.url-row .url-host { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 1.1rem; text-align: center; color: var(--text-2); font-size: 0.85rem; display: flex; gap: 0.5rem; align-items: center; justify-content: center; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 0.4rem; }
.progress > div { height: 100%; background: var(--accent); width: 0%; transition: width 150ms ease; }
.bars { display: flex; flex-direction: column; gap: 0.45rem; }
.bar-row { display: flex; align-items: center; gap: 0.7rem; font-size: 0.85rem; }
.bar-row .lbl { width: 9rem; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { flex: 1; height: 0.55rem; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0.8rem 0.9rem; text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--border-strong); }
.stat .num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { font-size: var(--fs-meta); color: var(--muted); }

/* ============ 7. Palettes (mode stays on html[data-theme]) ============ */
html[data-palette="slate"] {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e9edf2;
  --border: #dbe1e9;
  --border-strong: #bfc9d6;
  --text: #16191d;
  --text-2: #4b5560;
  --muted: #7d8894;
  --accent: #1f3a5f;
  --accent-text: #f7f9fc;
  --accent-soft: #dfe7f1;
}
html[data-theme="dark"][data-palette="slate"] {
  --bg: #0f1216;
  --surface: #161a20;
  --surface-2: #1d232c;
  --border: #272e39;
  --border-strong: #3a4351;
  --text: #e8ecf1;
  --text-2: #b6bfc9;
  --muted: #7e8a97;
  --accent: #9db9dd;
  --accent-text: #0f1216;
  --accent-soft: #1e2a3a;
}
html[data-palette="moss"] {
  --bg: #f4f6f0;
  --surface: #ffffff;
  --surface-2: #e9eee1;
  --border: #d9dfcb;
  --border-strong: #bcc5a6;
  --text: #1a1e14;
  --text-2: #4c5344;
  --muted: #7f8770;
  --accent: #2f4a1e;
  --accent-text: #f6f8f0;
  --accent-soft: #dde5cd;
}
html[data-theme="dark"][data-palette="moss"] {
  --bg: #101311;
  --surface: #161a15;
  --surface-2: #1e241c;
  --border: #283026;
  --border-strong: #3e4839;
  --text: #e9ece2;
  --text-2: #bcc3ae;
  --muted: #828a75;
  --accent: #a9c48a;
  --accent-text: #101311;
  --accent-soft: #222b1e;
}

/* ============ 8. Choice controls + appearance toggles ============ */
/* Custom dropdown: styled button + menu replace the native popup everywhere.
   The native <select> stays in the form as source of truth (JS syncs both ways). */
.cselect { position: relative; display: block; }
.cselect-auto { display: inline-block; min-width: 9rem; max-width: 100%; vertical-align: bottom; }
.csel-native {
  position: absolute !important; width: 1px; height: 1px; margin: 0; padding: 0;
  opacity: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  pointer-events: none;
}
.csel-btn {
  position: relative; width: 100%; min-height: 2.25rem;
  display: flex; align-items: center;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 0.875rem; line-height: 1.4; text-align: left;
  padding: 0.5rem 2rem 0.5rem 0.65rem; cursor: pointer;
}
.cselect-auto .csel-btn { width: auto; min-width: 9rem; max-width: 100%; }
.csel-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.csel-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.csel-btn .csel-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.csel-btn[data-empty="true"] .csel-label { color: var(--muted); }
.csel-btn .chev {
  position: absolute; right: 0.75rem; top: 50%;
  width: 0.45rem; height: 0.45rem; pointer-events: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 120ms ease;
}
.csel-btn[aria-expanded="true"] .chev { transform: translateY(-30%) rotate(225deg); border-color: var(--focus); }
.csel-menu {
  position: fixed; z-index: 70; /* fixed: never clipped by modal scroll or sticky bars */
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: 16rem; overflow-y: auto; padding: 0.25rem; margin: 0; list-style: none;
}
.csel-menu[hidden] { display: none; }
.csel-opt {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  padding: 0.5rem 0.6rem; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text); font-size: 0.875rem; line-height: 1.4;
  cursor: pointer; text-align: left;
}
.csel-opt:hover, .csel-opt.active { background: var(--surface-2); }
.csel-opt[aria-selected="true"] { font-weight: 600; }
.csel-opt .tick { width: 1rem; flex-shrink: 0; color: var(--accent); visibility: hidden; font-weight: 700; }
.csel-opt[aria-selected="true"] .tick { visibility: visible; }
.csel-opt.is-placeholder { color: var(--muted); }
.csel-opt:disabled, .csel-opt[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; }
.cselect.invalid .csel-btn { border-color: var(--danger); }

/* Checkbox row: <div class="field check"><label>…</label><input type="checkbox"></div> */
.field.check {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.field.check:hover { border-color: var(--accent); background: var(--surface-2); }
.field.check > label {
  margin: 0; flex: 1; min-width: 0;
  font-size: 0.875rem; font-weight: 500; line-height: 1.45; color: var(--text);
  cursor: pointer;
}
.field.check > input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  width: 1.1rem; height: 1.1rem; margin: 0;
  border: 1.5px solid var(--border-strong); border-radius: 5px;
  background: var(--surface); cursor: pointer;
  display: grid; place-content: center;
  transition: background 120ms ease, border-color 120ms ease;
}
.field.check > input[type="checkbox"]:hover { border-color: var(--accent); }
.field.check > input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.field.check > input[type="checkbox"]:checked::before {
  content: ""; width: 0.55rem; height: 0.3rem;
  border-left: 2px solid var(--accent-text); border-bottom: 2px solid var(--accent-text);
  transform: rotate(-45deg) translateY(-1px);
}
.field.check > input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.field.check > .hint, .field.check > .error { flex-basis: 100%; }
.field.invalid.check { border-color: var(--danger); }

/* Sidebar footer: fixed order userbox → theme → palette. */
.side-foot { display: flex; flex-direction: column; gap: 0.65rem; }
.userbox { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.userbox .avatar {
  width: 1.6rem; height: 1.6rem; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
}
.userbox .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; align-items: flex-start; }
.userbox .email {
  display: block; max-width: 100%;
  font-size: 0.75rem; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-link.logout { flex-shrink: 0; text-decoration: none; font-weight: 600; }
.btn-link.logout:hover { color: var(--text); }
.toggle-group { display: flex; flex-direction: column; gap: 0.3rem; }
.toggle-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.seg {
  display: flex; gap: 2px; padding: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
}
.seg button {
  flex: 1; min-height: 1.9rem; padding: 0.3rem 0.2rem;
  border: 1px solid transparent; border-radius: 999px; background: transparent;
  color: var(--text-2); font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong); box-shadow: var(--shadow-sm);
}
.swatches { display: flex; gap: 0.4rem; }
.swatch {
  flex: 1; min-width: 0; min-height: 2rem;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-2);
  font-size: 0.75rem; font-weight: 600; padding: 0.35rem 0.4rem;
}
.swatch:hover { border-color: var(--border-strong); color: var(--text); }
.swatch .dot { width: 0.8rem; height: 0.8rem; border-radius: 50%; border: 1px solid var(--border-strong); flex-shrink: 0; }
.swatch[aria-pressed="true"] { border-color: var(--accent); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============ 9. Design grids (static files / templates / designs) ============ */
.dgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.9rem; }
.dcard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  display: flex; flex-direction: column;
}
.dcard .prev {
  aspect-ratio: 1; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border); overflow: hidden;
}
.dcard .prev img { width: 100%; height: 100%; object-fit: contain; }
.dcard .prev-ext {
  font-family: var(--font-mono); font-size: 1rem; font-weight: 700;
  text-transform: uppercase; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 0.5rem 0.7rem;
}
.dcard .fontprev { font-size: 2rem; }
/* Template/design previews keep the canvas aspect ratio inside the square slot. */
.dcard .tpl-prev .prev-dims {
  width: 86%; aspect-ratio: var(--ar, 1);
  max-height: 86%;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--muted);
  background: var(--surface); text-align: center; padding: 0.3rem;
}
.dcard .body { padding: 0.6rem 0.7rem; flex: 1; min-width: 0; }
.dcard .body h3 {
  font-size: var(--fs-body); font-weight: 650; margin: 0 0 0.2rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dcard .body .meta {
  font-size: var(--fs-meta); color: var(--muted);
  display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap;
}
.dcard .acts {
  display: flex; gap: 0.3rem; flex-wrap: wrap;
  padding: 0.5rem 0.7rem 0.7rem; border-top: 1px solid var(--border);
}
.dcard .acts .btn { flex: 1; justify-content: center; min-width: 0; }

/* Design feature (§9): create-modal template preview (§73) + dashboard thumbs (§60). */
.tpl-preview { margin-top: 0.75rem; }
.tpl-preview:empty { display: none; }
.tpl-preview .prev {
  max-width: 16rem; aspect-ratio: 1; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.tpl-preview .prev img { width: 100%; height: 100%; object-fit: contain; }
.tpl-preview .tpl-prev .prev-dims {
  width: 86%; aspect-ratio: var(--ar, 1); max-height: 86%;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--muted);
  background: var(--surface); text-align: center; padding: 0.3rem;
}
.tpl-preview-name { margin-top: 0.5rem; font-weight: 600; }
.tpl-preview-dims { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.dash-thumb {
  width: 34px; height: 34px; object-fit: cover; vertical-align: middle;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-right: 0.5rem; background: var(--surface-2);
}
