/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

/* ── Design tokens — light mode ─────────────────────────── */
:root {
  --bg-0:       #ffffff;
  --bg-1:       #f6f7fb;
  --bg-2:       #eeeef5;
  --bg-3:       #e2e3ec;
  --border:     #d8d9e6;
  --text-1:     #18181f;
  --text-2:     #55566a;
  --text-3:     #94949e;
  --accent:     #5a7ac4;
  --accent-h:   #4a6ab4;
  --accent-bg:  #edf1fa;
  --red:        #c43a3a;
  --red-bg:     #fef2f2;
  --green:      #237a50;
  --green-bg:   #edfaf3;
  --amber:      #896200;
  --amber-bg:   #fffbeb;
  --sidebar-w:  220px;
  --r-sm:       4px;
  --r:          8px;
  --r-lg:       12px;
  --sh-sm:      0 1px 2px rgba(0,0,0,.06);
  --sh:         0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.05);
  --sh-lg:      0 8px 32px rgba(0,0,0,.12);
  --t:          150ms ease;
  --font:       system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ── Dark mode — system preference ─────────────────────── */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg-0:      #0e1019;
    --bg-1:      #161923;
    --bg-2:      #1e2130;
    --bg-3:      #272c3d;
    --border:    #2d3248;
    --text-1:    #e4e6f0;
    --text-2:    #9090a8;
    --text-3:    #60607a;
    --accent:    #7a97d4;
    --accent-h:  #8ea4db;
    --accent-bg: #19213e;
    --red:       #e05050;
    --red-bg:    #2a1616;
    --green:     #3ab870;
    --green-bg:  #0d2018;
    --amber:     #d4a820;
    --amber-bg:  #21180a;
    --sh-sm:     0 1px 2px rgba(0,0,0,.25);
    --sh:        0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
    --sh-lg:     0 8px 32px rgba(0,0,0,.4);
  }
}

/* ── Dark mode — manual override ───────────────────────── */
html[data-theme="dark"] {
  --bg-0:      #0e1019;
  --bg-1:      #161923;
  --bg-2:      #1e2130;
  --bg-3:      #272c3d;
  --border:    #2d3248;
  --text-1:    #e4e6f0;
  --text-2:    #9090a8;
  --text-3:    #60607a;
  --accent:    #7a97d4;
  --accent-h:  #8ea4db;
  --accent-bg: #19213e;
  --red:       #e05050;
  --red-bg:    #2a1616;
  --green:     #3ab870;
  --green-bg:  #0d2018;
  --amber:     #d4a820;
  --amber-bg:  #21180a;
  --sh-sm:     0 1px 2px rgba(0,0,0,.25);
  --sh:        0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.2);
  --sh-lg:     0 8px 32px rgba(0,0,0,.4);
}

/* ── Base styles ────────────────────────────────────────── */
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-0);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h2 { font-size: 20px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 15px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; text-transform: uppercase;
     letter-spacing: .04em; color: var(--text-3); }

.hidden { display: none !important; }

/* ── Screens ────────────────────────────────────────────── */
.screen { min-height: 100vh; }
.screen-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-1);
  padding: 32px 16px;
}

/* ── Auth card ──────────────────────────────────────────── */
.auth-card {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}
.auth-card-wide { max-width: 520px; }

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 28px;
}
.brand-wordmark {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--accent);
}
.brand-by { font-size: 12px; color: var(--text-3); }

.auth-card h2 { margin-bottom: 6px; }
.auth-card .text-muted { margin-bottom: 24px; }

.auth-sent { text-align: center; }
.auth-sent-icon { font-size: 40px; margin-bottom: 16px; }
.auth-sent h2 { margin-bottom: 8px; }
.auth-sent .text-muted { margin-bottom: 20px; }

/* ── App layout ─────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-wordmark {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--accent);
}

.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 4px 7px;
  transition: border-color var(--t), color var(--t);
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: block;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--t), color var(--t);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-1); text-decoration: none; }
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-user {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main pane ──────────────────────────────────────────── */
.main-pane {
  min-height: 100vh;
  background: var(--bg-0);
  overflow-y: auto;
}
.main-pane:focus { outline: none; }

/* ── View layout ────────────────────────────────────────── */
.view {
  padding: 32px 40px;
  max-width: 1100px;
}

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.view-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.view-sub {
  color: var(--text-2);
  margin-top: 2px;
  font-size: 13px;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--sh-sm);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Stats grid ─────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text-1);
}
.stat-label {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Quick actions ──────────────────────────────────────── */
.dash-quick h3 { margin-bottom: 12px; }
.quick-btns { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Filter bar ─────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.total-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-3);
}

/* ── Table ──────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  padding: 10px 12px;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-1); }

.cell-title {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.cell-muted { color: var(--text-3); font-size: 12px; }
.cell-center { text-align: center; }
.cell-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}
.empty-cell {
  text-align: center;
  color: var(--text-3);
  padding: 40px 12px !important;
  font-size: 14px;
}
.cut-dot { color: var(--accent); font-size: 10px; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 0;
}
.pg-info { font-size: 13px; color: var(--text-2); }

/* ── Collections list ───────────────────────────────────── */
.col-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.col-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-0);
  transition: background var(--t);
}
.col-row:last-child { border-bottom: none; }
.col-row:hover { background: var(--bg-1); }
.col-name { font-size: 14px; font-weight: 500; }
.col-actions { display: flex; gap: 6px; }
.archived-section { border-top: 2px solid var(--border); }
.archived-label {
  padding: 8px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-3);
}

/* ── The Cut list ───────────────────────────────────────── */
.cut-count-badge {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 100px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 16px;
}
.cut-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
.cut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-0);
}
.cut-item:last-child { border-bottom: none; }
.cut-item:hover { background: var(--bg-1); }
.cut-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.cut-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cut-item-meta { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Info banner ────────────────────────────────────────── */
.info-banner {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  border-radius: var(--r);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Settings ───────────────────────────────────────────── */
.settings-section { margin-bottom: 24px; }
.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.slug-static {
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-2);
}
.slug-static strong { color: var(--text-1); }
.avatar-preview { margin-bottom: 10px; }
.avatar-img {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}
.input-prefix-wrap, .input-suffix-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-0);
}
.input-prefix-wrap input, .input-suffix-wrap input {
  border: none;
  flex: 1;
  min-width: 0;
}
.input-prefix, .input-suffix {
  background: var(--bg-2);
  color: var(--text-3);
  padding: 0 10px;
  font-size: 13px;
  height: 36px;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.input-suffix { border-right: none; border-left: 1px solid var(--border); }

/* ── Forms ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field-checkbox {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0;
  margin-bottom: 0;
}
.field-hint {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 5px;
}
.opt { color: var(--text-3); font-weight: 400; }
.req { color: var(--red); }

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color var(--t), box-shadow var(--t);
  appearance: none;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
input::placeholder,
textarea::placeholder { color: var(--text-3); }
input[disabled] { opacity: .55; cursor: not-allowed; }
textarea { resize: vertical; line-height: 1.6; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394949e'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  cursor: pointer;
}
.file-input {
  padding: 6px;
  cursor: pointer;
  background: var(--bg-1);
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-1);
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.slug-row {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  background: var(--bg-0);
  transition: border-color var(--t);
}
.slug-row:focus-within { border-color: var(--accent); }
.slug-prefix {
  background: var(--bg-2);
  color: var(--text-3);
  padding: 8px 10px;
  font-size: 13px;
  white-space: nowrap;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.slug-row input {
  border: none;
  border-radius: 0;
  flex: 1;
  min-width: 0;
  box-shadow: none !important;
}
.slug-row input:focus { border-color: transparent; box-shadow: none !important; }

.form-error {
  color: var(--red);
  font-size: 13px;
  padding: 8px 12px;
  background: var(--red-bg);
  border-radius: var(--r-sm);
  margin-top: 8px;
}
.modal-error { margin: 0 24px; }
.text-muted { color: var(--text-2); font-size: 13px; }
.empty-msg {
  color: var(--text-3);
  font-size: 14px;
  padding: 32px 0;
  text-align: center;
}
.error-msg {
  color: var(--red);
  padding: 32px 0;
  text-align: center;
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2px 8px;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge-audio   { background: #e8edf8; color: #3a5a9e; }
.badge-text    { background: #f3ede8; color: #8a4a20; }
.badge-image   { background: #ecf3e8; color: #3a6e2a; }
.badge-written { background: #ece8f3; color: #5a3a9e; }
.badge-green   { background: var(--green-bg); color: var(--green); }
.badge-gray    { background: var(--bg-2); color: var(--text-3); }

html[data-theme="dark"] .badge-audio,
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .badge-audio   { background: #1a2540; color: #8aaae8; }
}
html[data-theme="dark"] .badge-text,
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .badge-text    { background: #2a1a10; color: #d0845a; }
}
html[data-theme="dark"] .badge-image,
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .badge-image   { background: #112010; color: #6aae50; }
}
html[data-theme="dark"] .badge-written,
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .badge-written { background: #1e1030; color: #a08ae0; }
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  align-items: center;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  gap: 6px;
  justify-content: center;
  line-height: 1;
  padding: 8px 14px;
  text-decoration: none;
  transition: background var(--t), border-color var(--t),
              color var(--t), opacity var(--t);
  user-select: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-full { width: 100%; }
.btn-sm  { font-size: 12px; padding: 5px 10px; }
.btn-xs  { font-size: 11px; padding: 3px 8px; border-radius: 4px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

.btn-accent {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-accent:hover { background: color-mix(in srgb, var(--accent-bg) 80%, var(--accent)); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text-1); }

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 30%, transparent);
}
.btn-danger-ghost:hover { background: var(--red-bg); }

/* ── Medium selector ─────────────────────────────────────── */
.medium-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.medium-btn {
  background: var(--bg-1);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 6px;
  text-align: center;
  transition: all var(--t);
}
.medium-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}
.medium-btn.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.medium-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-lg);
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
  max-width: 560px;
}
.modal-sm { max-width: 380px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px;
  transition: color var(--t);
}
.modal-close:hover { color: var(--text-1); }

.modal-body { padding: 20px 24px; }
.modal-body .field:last-child { margin-bottom: 0; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── Spinner ─────────────────────────────────────────────── */
.spinner-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--sh);
  color: var(--text-1);
  font-size: 13.5px;
  max-width: 320px;
  opacity: 0;
  padding: 10px 16px;
  pointer-events: auto;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast-visible { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--accent); }
