@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=JetBrains+Mono:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root,
[data-theme="light"] {
  color-scheme: light;
  --bg-canvas: #f7f6f2;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f0ec;
  --bg-elevated: #ffffff;
  --bg-sidebar: #fbfaf8;
  --bg-input: #ffffff;
  --border-hairline: #e4e2dd;
  --border-strong: #cbc8c0;
  --text-primary: #111315;
  --text-secondary: #4b525d;
  --text-muted: #78808c;
  --accent-ink: #111315;
  --accent-ink-fg: #ffffff;
  --accent-brand: #0284c7;
  --accent-brand-soft: rgba(2, 132, 199, 0.09);
  --status-active-bg: #ecfdf5;
  --status-active-fg: #047857;
  --status-active-border: #a7f3d0;
  --status-warn-bg: #fffbeb;
  --status-warn-fg: #b45309;
  --status-warn-border: #fde68a;
  --status-error-bg: #fef2f2;
  --status-error-fg: #be123c;
  --status-error-border: #fecdd3;
  --status-info-bg: #eef2ff;
  --status-info-fg: #4338ca;
  --status-info-border: #c7d2fe;
  --shadow-card: 0 1px 3px rgba(17, 19, 21, 0.04), 0 1px 2px rgba(17, 19, 21, 0.02);
  --shadow-hover: 0 8px 24px rgba(17, 19, 21, 0.06);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --font-serif: "Instrument Serif", Georgia, serif;
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg-canvas: #090a0d;
  --bg-surface: #111319;
  --bg-subtle: #171a22;
  --bg-elevated: #1b1f2a;
  --bg-sidebar: #0d0f14;
  --bg-input: #0d0f14;
  --border-hairline: #232734;
  --border-strong: #343a4d;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-ink: #f3f4f6;
  --accent-ink-fg: #090a0d;
  --accent-brand: #38bdf8;
  --accent-brand-soft: rgba(56, 189, 248, 0.12);
  --status-active-bg: rgba(16, 185, 129, 0.14);
  --status-active-fg: #34d399;
  --status-active-border: rgba(16, 185, 129, 0.35);
  --status-warn-bg: rgba(245, 158, 11, 0.14);
  --status-warn-fg: #fbbf24;
  --status-warn-border: rgba(245, 158, 11, 0.35);
  --status-error-bg: rgba(244, 63, 94, 0.15);
  --status-error-fg: #fb7185;
  --status-error-border: rgba(244, 63, 94, 0.38);
  --status-info-bg: rgba(99, 102, 241, 0.16);
  --status-info-fg: #a5b4fc;
  --status-info-border: rgba(99, 102, 241, 0.4);
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.28);
  --shadow-hover: 0 10px 28px rgba(0, 0, 0, 0.45);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.18s ease, color 0.18s ease;
}

a {
  color: var(--text-primary);
  text-decoration: none;
}

a:hover {
  color: var(--accent-brand);
}

/* App Shell: Left Sidebar + Header + Main Workspace */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-hairline);
  padding: 1.35rem 1.1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.4rem 1.15rem;
  border-bottom: 1px solid var(--border-hairline);
  margin-bottom: 1.15rem;
}

.brand:hover {
  color: var(--text-primary);
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-ink);
  color: var(--accent-ink-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 400;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.sidebar-section-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 0.6rem;
  margin: 0.85rem 0 0.4rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.86rem;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.nav-item:hover,
.nav-item.active {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-item.active {
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent-brand);
}

.sidebar-footer {
  border-top: 1px solid var(--border-hairline);
  padding-top: 1rem;
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.system-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-active-fg);
  box-shadow: 0 0 0 3px var(--status-active-bg);
}

/* Main Workspace & Top Header Bar */
.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.workspace-topbar {
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-hairline);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.container {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}

/* Editorial Page Header */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid var(--border-hairline);
  flex-wrap: wrap;
}

.editorial-eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--accent-brand);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.page-title-serif {
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: italic;
  font-size: 2rem;
  margin-left: 0.2rem;
}

.page-subtitle {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Bento KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  box-shadow: var(--shadow-hover);
}

.kpi-label {
  color: var(--text-secondary);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.kpi-value {
  margin-top: 0.45rem;
  font-size: 1.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
}

.kpi-sub {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Cards & Bento Panels */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-card);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-hairline);
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Visual 7-Stage State Machine Pipeline Bar */
.pipeline-track {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.pipeline-stage {
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  position: relative;
}

.pipeline-stage.stage-active {
  background: var(--accent-brand-soft);
  border-color: var(--accent-brand);
}

.pipeline-stage-num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.pipeline-stage-name {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 0.15rem;
  color: var(--text-primary);
}

.pipeline-stage-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

/* Alert Banners */
.alert {
  padding: 0.9rem 1.15rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.1rem;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.86rem;
}

.alert-success {
  background: var(--status-active-bg);
  border-color: var(--status-active-border);
  color: var(--status-active-fg);
}

.alert-error {
  background: var(--status-error-bg);
  border-color: var(--status-error-border);
  color: var(--status-error-fg);
}

.alert-warn {
  background: var(--status-warn-bg);
  border-color: var(--status-warn-border);
  color: var(--status-warn-fg);
}

.alert-info {
  background: var(--status-info-bg);
  border-color: var(--status-info-border);
  color: var(--status-info-fg);
}

/* Semantic Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.58rem;
  border-radius: 999px;
  font-size: 0.71rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.badge-active,
.badge-published {
  background: var(--status-active-bg);
  color: var(--status-active-fg);
  border: 1px solid var(--status-active-border);
}

.badge-paused,
.badge-draft,
.badge-deferred_quota {
  background: var(--status-warn-bg);
  color: var(--status-warn-fg);
  border: 1px solid var(--status-warn-border);
}

.badge-auth_error,
.badge-failed {
  background: var(--status-error-bg);
  color: var(--status-error-fg);
  border: 1px solid var(--status-error-border);
}

.badge-test_mode,
.badge-processing,
.badge-publishing,
.badge-publish_uncertain,
.badge-retry_pending,
.badge-claimed,
.badge-downloading,
.badge-uploading,
.badge-queued {
  background: var(--status-info-bg);
  color: var(--status-info-fg);
  border: 1px solid var(--status-info-border);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.52rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: all 0.14s ease;
  text-decoration: none;
  font-family: var(--font-sans);
}

.btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: var(--accent-ink-fg);
}

.btn-primary:hover {
  opacity: 0.9;
  background: var(--accent-ink);
  color: var(--accent-ink-fg);
}

.btn-success {
  background: var(--status-active-bg);
  border-color: var(--status-active-border);
  color: var(--status-active-fg);
}

.btn-danger {
  background: var(--status-error-bg);
  border-color: var(--status-error-border);
  color: var(--status-error-fg);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.76rem;
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Forms & Drag-and-Drop Zone */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 1.15rem;
}

.form-group {
  margin-bottom: 1.05rem;
}

.form-label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-primary);
}

.form-hint {
  display: block;
  margin-top: 0.28rem;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 0.56rem 0.78rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.87rem;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-brand);
  box-shadow: 0 0 0 3px var(--accent-brand-soft);
}

textarea.form-control {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  min-height: 105px;
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 1.1rem;
  text-align: center;
  cursor: pointer;
  margin-bottom: 0.65rem;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent-brand);
  background: var(--accent-brand-soft);
}

.schedule-slots-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.slot-pill {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  color: var(--text-primary);
}

/* Tables with Right-Aligned Numeric Columns */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border-hairline);
  vertical-align: middle;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-subtle);
}

th.num-col,
td.num-col {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

tr:hover td {
  background: var(--bg-subtle);
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.79rem;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.35rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent-brand);
}

/* 5-Step Workflow Stepper */
.workflow-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.step-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-card);
}

.step-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent-brand);
  font-weight: 700;
}

.step-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

/* Login Shell */
.login-shell {
  min-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-hover);
}

.pacing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.pacing-tile {
  background: var(--bg-subtle);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  padding: 1rem 1.15rem;
}

.pacing-tile-label {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pacing-tile-value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0.35rem 0 0.2rem;
  letter-spacing: -0.02em;
}

.pacing-tile-sub {
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
}

[data-theme="dark"] .lock-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #FCD34D;
  border-color: rgba(245, 158, 11, 0.35);
}

.pacing-slot-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.6rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.73rem;
  border: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.pacing-slot-chip.slot-completed {
  background: var(--status-active-bg);
  border-color: var(--status-active-border);
  color: var(--status-active-fg);
}

.pacing-slot-chip.slot-next {
  background: rgba(2, 132, 199, 0.1);
  border-color: var(--accent-brand);
  color: var(--accent-brand);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--accent-brand);
}

.pacing-slots-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.6rem;
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-hairline);
  }
  .pipeline-track {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
  .container {
    padding: 1.25rem 1rem 3rem;
  }
}
