/*
  Preface admin. One stylesheet, no inline styles anywhere.
  Sections: tokens, base, layout, navigation, tables, components (status, chip, stat, creative), forms, landing.
  State is expressed with data attributes: [data-status], [data-channel], [data-format], [data-size].
*/

/* Tokens */
:root {
  --sidebar-width: 240px;
  --content-max: 1400px;
  --border: #e5e7eb;
  --surface: #fff;
  --canvas: #fafafa;
  --ink: #111827;
  --ink-muted: #6b7280;
  --bs-body-font-size: 13px;
  --bs-body-bg: var(--canvas);
}

/* Base */
body { font-size: 13px; background: var(--bs-body-bg); }
h1 { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: inherit; }
.muted { color: var(--ink-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.form-text { font-size: 12px; }
.btn-sm { font-size: 12px; }

/* Layout */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.content { margin-left: var(--sidebar-width); padding: 24px; max-width: calc(var(--content-max) + var(--sidebar-width)); }
.content-narrow { max-width: 960px; }
.page-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 16px; }
.page-header .lede { color: var(--ink-muted); font-size: 12px; }
.topbar { display: none; }
.section { margin-bottom: 28px; }

/* Global pages (dashboard) have no Workspace sidebar. One header bar, full width content. */
.global-header {
  position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 24px;
}
.global-header .brand { font-weight: 600; color: var(--ink); text-decoration: none; }
.global-header .nav-link { padding: 4px 10px; color: var(--ink-muted); border-radius: 6px; font-size: 13px; }
.global-header .nav-link:hover { color: var(--ink); background: #f3f4f6; }
.global-header .nav-link[aria-current="page"] { color: var(--ink); background: #ebebea; }
.global-header .operator { margin: 0 0 0 auto; display: flex; gap: 12px; align-items: center; font-size: 13px; }
body[data-layout="global"] .content { margin-left: 0; max-width: var(--content-max); margin-inline: auto; }

@media (max-width: 991.98px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 16px; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 1020; gap: 12px; align-items: center;
    background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px;
  }
  .page-header .lede { display: none; }
  .modal-dialog { margin: 0; max-width: 100%; }
  .modal-content { border-radius: 0; min-height: 100vh; }
}

/* Navigation (sidebar and offcanvas share markup) */
.nav-shell { display: flex; flex-direction: column; height: 100%; }
.nav-shell .workspace-switcher { padding: 12px; }
.nav-shell .nav { padding: 0 8px; gap: 4px; }
.nav-shell .nav-link { color: #374151; padding: 6px 12px; border-radius: 6px; font-size: 13px; }
.nav-shell .nav-link:hover { background: #f3f4f6; }
.nav-shell .nav-link[aria-current="page"] { background: var(--ink); color: #fff; }
.nav-shell .nav-link .bi { width: 18px; display: inline-block; margin-right: 8px; }
.nav-shell .nav-footer { margin-top: auto; border-top: 1px solid var(--border); padding: 8px; }
.nav-shell .operator { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 0; color: var(--ink-muted); }
.workspace-switcher .btn { text-align: left; display: flex; align-items: center; justify-content: space-between; width: 100%; }
.workspace-switcher .workspace-name { font-weight: 600; line-height: 1.1; }
.workspace-switcher .dropdown-item { display: flex; justify-content: space-between; align-items: center; }
.offcanvas { width: 280px; }

/* Cards */
.card { border: 1px solid var(--border); box-shadow: none; }
.card-header { background: var(--surface); border-bottom: 1px solid var(--border); font-weight: 600; padding: 10px 14px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.card-header .count { color: var(--ink-muted); font-weight: 400; margin-left: 4px; }
.card-footer { background: var(--surface); }
.card-footer.note { color: var(--ink-muted); font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .form-select, .toolbar .form-control { width: auto; }
.toolbar .search { width: 220px; }
.toolbar .end { margin-left: auto; }

/* Tables */
.table { font-size: 13px; margin-bottom: 0; }
.table > thead { background: #f9fafb; }
.table > thead th { font-weight: 500; color: var(--ink-muted); font-size: 12px; white-space: nowrap; }
.table td { vertical-align: middle; }
.table .trunc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .col-toggle { width: 28px; }
.table .col-actions { text-align: right; }
.table .col-detail { min-width: 360px; }
.table .col-actions .btn { padding-top: 0; padding-bottom: 0; }
.table .col-bar { width: 38%; }
.table .col-budget { width: 140px; }
tr.row-toggle { cursor: pointer; }
tr.row-detail > td { background: #f9fafb; padding: 14px 18px; }
tr.row-detail .table { background: var(--surface); }
tr.day-header td { background: #f3f4f6; font-weight: 600; color: #374151; font-size: 12px; }
.error { color: #b91c1c; }
.nested-table { background: var(--surface); }

/* Stat strip */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 24px; }
@media (min-width: 992px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 12px 14px; margin: 0; }
.stat dt { color: var(--ink-muted); font-size: 12px; font-weight: 400; }
.stat dd { font-size: 1.35rem; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.stat[data-alert] dd { color: #b91c1c; }

/* Status badge. Usage: <span class="status" data-status="active">active</span> */
.status {
  display: inline-block; font-weight: 500; font-size: 11px; line-height: 1.2; padding: 3px 7px;
  border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
}
.status[data-status="draft"], .status[data-status="removed"], .status[data-status="excluded"], .status[data-status="rotation"], .status[data-status="done"] { background: #f3f4f6; color: #374151; }
.status[data-status="queued"], .status[data-status="discovering"], .status[data-status="scoring"], .status[data-status="running"], .status[data-status="populating"] { background: #e0f2fe; color: #075985; }
.status[data-status="holding"], .status[data-status="maintenance"] { background: #ede9fe; color: #5b21b6; }
.status[data-status="unpublished"] { background: #fef9c3; color: #854d0e; border-color: #fde047; }
.status[data-status="lead"] { background: #dbeafe; color: #1e40af; }
.status[data-status="pending"] { background: var(--surface); color: var(--ink-muted); border-color: #d1d5db; }
.status[data-status="active"], .status[data-status="live"], .status[data-status="complete"], .status[data-status="synced"], .status[data-status="engaged"], .status[data-status="set"] { background: #dcfce7; color: #166534; }
.status[data-status="paused"] { background: #fef3c7; color: #92400e; }
.status[data-status="warm"] { background: #ffedd5; color: #9a3412; }
.status[data-status="failed"], .status[data-status="not-set"], .status[data-status="rejected"], .status[data-status="underpopulated"] { background: #fee2e2; color: #991b1b; }
.status[data-status="approx"] { background: var(--surface); color: #1d4ed8; border: 1px dashed #93c5fd; }

/* Channel chip. Usage: <abbr class="chip" data-channel="google" data-status="active" title="Google: active">G</abbr> */
.chip {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 5px;
  border-radius: 5px; font-size: 11px; font-weight: 600; border: 1px solid transparent; text-decoration: none; cursor: default;
}
.chip[data-status="active"] { background: #dcfce7; color: #166534; }
.chip[data-status="paused"] { background: #fef3c7; color: #92400e; }
.chip[data-status="failed"], .chip[data-status="underpopulated"], .chip[data-status="rejected"] { background: #fee2e2; color: #991b1b; }
.chip[data-status="pending"], .chip[data-status="draft"] { background: #f3f4f6; color: var(--ink-muted); }

/* Creative preview. Usage:
   <figure class="creative" data-format="meta" data-size="sm">
     <p class="creative-note">message</p>
     <figcaption class="creative-brand">Northwind</figcaption>
   </figure> */
.creative {
  position: relative; margin: 0; background: linear-gradient(135deg, #e9e9e7, #d6d6d3); border-radius: 6px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; container-type: inline-size;
}
.creative-note {
  margin: 0; background: #fbe870; color: #222; width: 60%; aspect-ratio: 1 / 1; transform: rotate(-2.5deg);
  box-shadow: 2px 4px 10px rgba(0, 0, 0, .18); display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: 'Caveat', cursive; line-height: 1.05; padding: 6%; font-size: 8.2cqw; overflow: hidden;
}
.creative-brand { position: absolute; right: 4%; bottom: 3%; font-size: clamp(7px, 3.2cqw, 14px); font-weight: 600; color: #333; letter-spacing: 0.02em; }
.creative[data-format="meta"] { aspect-ratio: 1 / 1; }
.creative[data-format="google"], .creative[data-format="linkedin"] { aspect-ratio: 1.91 / 1; }
.creative[data-format="google"] .creative-note, .creative[data-format="linkedin"] .creative-note { width: 38%; font-size: 5.2cqw; padding: 3%; }
.creative[data-size="sm"] { width: 120px; }
.creative[data-size="sm"][data-format="google"], .creative[data-size="sm"][data-format="linkedin"] { width: 180px; }
.creative[data-size="md"] { width: 220px; max-width: 100%; }
.creative[data-size="lg"] { width: 100%; }
.creative-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Forms */
.dropzone { border: 1px dashed #cbd5e1; border-radius: 8px; padding: 28px; text-align: center; color: var(--ink-muted); background: var(--surface); }
.dropzone .bi { font-size: 1.5rem; display: block; margin-bottom: 4px; }
.tag-input { display: flex; flex-wrap: wrap; gap: 4px; min-height: 38px; }
.tag-input .tag { background: #f8f9fa; border: 1px solid var(--border); color: var(--ink); font-weight: 500; }
.tag-input input { border: 0; outline: 0; flex: 1; min-width: 80px; }
.field-hint { display: flex; justify-content: space-between; }
progress { appearance: none; height: 6px; border: 0; border-radius: 3px; background: #e9ecef; overflow: hidden; }
progress::-webkit-progress-bar { background: #e9ecef; }
progress::-webkit-progress-value { background: var(--ink); }
progress::-moz-progress-bar { background: var(--ink); }
.list-group-item.active { background: var(--ink); border-color: var(--ink); }
.settings-line { display: flex; flex-wrap: wrap; gap: 16px; color: var(--ink-muted); font-size: 12px; margin-bottom: 12px; }
.settings-line .bi { margin-right: 4px; }
.channel-list { display: flex; flex-direction: column; gap: 8px; }
.pause-all { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 6px; padding: 12px; background: var(--surface); }
.definition { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; margin: 0; }
.definition dt { color: var(--ink-muted); font-size: 12px; font-weight: 400; }
.definition dd { font-size: 1.35rem; font-weight: 600; margin: 0; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 100%; max-width: 380px; }
.login .brand { text-align: center; margin-bottom: 24px; }
.login .brand strong { display: block; font-size: 1.2rem; }

/* Landing page (public, no shell) */
.landing { background: var(--surface); font-size: 16px; }
.landing .wrap { max-width: 560px; margin: 0 auto; padding: 24px 20px 48px; }
.landing .eyebrow { text-transform: uppercase; font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--ink-muted); margin-bottom: 4px; }
.landing h1 { font-size: 1.6rem; margin-bottom: 12px; }
.landing #lead { border-color: var(--border); }
.landing .urlbar { background: #f3f4f6; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--ink-muted); margin-bottom: 24px; }
