:root {
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-primary: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-surface: #F3F2EF;
  --bg-nav: #0F0F0F;
  --bg-input: #FFFFFF;

  --text-primary: #1A1A1A;
  --text-secondary: #6B6B6B;
  --text-tertiary: #9B9B9B;
  --text-inverse: #FFFFFF;

  --border: #E4E3DF;
  --border-light: #EEEDEA;
  --border-focus: #1A1A1A;

  --accent: #2B6CB0;
  --accent-light: #EBF4FF;
  --success: #1A7A42;
  --success-light: #E8F5E9;
  --warning: #B87514;
  --warning-light: #FFF8E1;
  --danger: #C62828;
  --danger-light: #FFEBEE;
  --processing: #5C6BC0;
  --processing-light: #E8EAF6;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ── */
#nav {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-nav);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-left { flex: 0 0 200px; }
.nav-center { display: flex; gap: 2px; justify-content: center; flex: 1; }
.nav-right { flex: 0 0 200px; display: flex; justify-content: flex-end; }

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-inverse);
  font-size: 0.93rem;
  letter-spacing: -0.01em;
}

.nav-logo-img {
  height: 70px;
  width: auto;
}

.brand-mark {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text-inverse);
}

.brand-text { font-weight: 400; opacity: 0.7; }

/* ── Auth Screen ── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}
.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 28px;
}
.auth-logo-img {
  width: 100%;
  height: auto;
  background: var(--bg-nav);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}
.auth-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  background: var(--bg-nav);
  margin-bottom: 16px;
}
.auth-title {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.auth-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}
.auth-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 14px;
}
.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.auth-toggle a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.auth-toggle a:hover { text-decoration: underline; }

/* ── Nav User ── */
.nav-user {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.6);
  margin-right: 10px;
}
.nav-logout {
  color: rgba(255,255,255,0.5) !important;
  border-color: rgba(255,255,255,0.15) !important;
  background: transparent !important;
  font-size: 0.78rem !important;
}
.nav-logout:hover {
  color: rgba(255,255,255,0.9) !important;
  background: rgba(255,255,255,0.08) !important;
}

.nav-link {
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 400;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  letter-spacing: 0.01em;
}
.nav-link:hover { color: rgba(255,255,255,0.85); background: rgba(255,255,255,0.06); }
.nav-link.active { color: #FFFFFF; background: rgba(255,255,255,0.1); font-weight: 500; }

.api-indicator { display: flex; align-items: center; gap: 6px; }
.api-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px rgba(26,122,66,0.4);
  transition: background 0.3s;
}
.api-dot.error { background: var(--danger); box-shadow: 0 0 6px rgba(198,40,40,0.4); }

/* ── Status Bar ── */
.status-bar {
  display: flex;
  gap: 0;
  padding: 0 24px;
  height: 48px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  align-items: center;
}
.stat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.82rem;
}
.stat-num { font-weight: 600; font-size: 1.05rem; font-family: var(--font-mono); }
.stat-label { color: var(--text-secondary); font-weight: 400; }
.stat-processing { color: var(--processing); }
.stat-review { color: var(--warning); }
.stat-published { color: var(--success); }
.stat-failed { color: var(--danger); }

/* ── Main Container ── */
#view-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ── Section Layout ── */
.section { margin-bottom: 32px; }
.section-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* ── Form Controls ── */
.input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.93rem;
  font-family: var(--font-body);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--border-focus); }
.input::placeholder { color: var(--text-tertiary); }

/* ── Dealer Search Dropdown ── */
.search-wrap { position: relative; }
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  display: none;
  box-shadow: var(--shadow-md);
}
.dropdown.open { display: block; }
.dd-item {
  padding: 10px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s;
}
.dd-item:hover { background: var(--bg-surface); }
.dd-item + .dd-item { border-top: 1px solid var(--border-light); }

.brand-pill {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* ── Brand Preview Bar ── */
.brand-bar {
  display: none;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-top: 12px;
  background: var(--bg-card);
}
.brand-bar.visible { display: flex; }
.brand-swatch {
  width: 40px; height: 120px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.brand-info-name { font-size: 0.93rem; font-weight: 500; }
.brand-info-tone { font-size: 0.8rem; color: var(--text-secondary); margin-top: 1px; }

/* ── Options Grid (radio cards) ── */
.opts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-card {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-card);
}
.opt-card:hover { border-color: var(--text-secondary); }
.opt-card.selected { border-color: var(--accent); background: var(--accent-light); }
.opt-header { display: flex; align-items: center; gap: 10px; }
.opt-radio {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.opt-card.selected .opt-radio { border-color: var(--accent); }
.opt-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
}
.opt-card.selected .opt-dot { display: block; }
.opt-title { font-size: 0.88rem; font-weight: 500; }
.opt-desc { font-size: 0.78rem; color: var(--text-secondary); margin-top: 3px; margin-left: 28px; }

/* ── Toggle Rows ── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-text-title { font-size: 0.9rem; font-weight: 400; }
.toggle-text-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 1px; }
.toggle-track {
  position: relative;
  width: 44px; height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-track.on .toggle-thumb { transform: translateX(20px); }

/* ── Keyword Input Row ── */
.kw-row { display: flex; gap: 8px; }
.kw-row .input { flex: 1; }

/* ── Buttons ── */
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.12s;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg-surface); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--text-primary);
  color: var(--text-inverse);
  border-color: var(--text-primary);
}
.btn-primary:hover { background: #333; }

.btn-sm { padding: 5px 12px; font-size: 0.78rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); }

/* ── Keyword Tags ── */
.kw-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.kw-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-surface);
  font-size: 0.82rem;
}
.kw-tag-source {
  font-size: 0.68rem;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kw-tag-remove {
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 0.9rem;
  line-height: 1;
  transition: color 0.1s;
}
.kw-tag-remove:hover { color: var(--danger); }

/* ── Generate Bar ── */
.gen-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 8px;
}
.gen-bar .btn-primary { padding: 12px 32px; font-size: 0.95rem; }
.gen-mode { font-size: 0.82rem; color: var(--text-secondary); }

/* ── Post Cards (Review Queue) ── */
.filters { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-btn {
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-secondary);
  transition: all 0.12s;
}
.filter-btn:hover { background: var(--bg-surface); }
.filter-btn.active {
  background: var(--text-primary);
  color: var(--text-inverse);
  border-color: var(--text-primary);
}

.sort-btn.active,
.chart-metric-btn.active {
  background: var(--text-primary);
  color: var(--text-inverse);
  border-color: var(--text-primary);
}
.filter-count {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  margin-left: 4px;
  opacity: 0.7;
}

.post-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  margin-bottom: 12px;
  background: var(--bg-card);
  transition: border-color 0.15s;
}
.post-card:hover { border-color: var(--text-secondary); }
.post-card.dimmed { opacity: 0.5; }

.post-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.post-title { font-size: 0.95rem; font-weight: 500; line-height: 1.4; }
.post-meta {
  display: flex;
  gap: 10px;
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
  align-items: center;
}

.badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.badge-queued { background: var(--bg-surface); color: var(--text-secondary); }
.badge-processing { background: var(--processing-light); color: var(--processing); }
.badge-review { background: var(--warning-light); color: var(--warning); }
.badge-published { background: var(--success-light); color: var(--success); }
.badge-failed { background: var(--danger-light); color: var(--danger); }
.badge-approved { background: var(--accent-light); color: var(--accent); }

/* ── Pipeline Progress ── */
.pipeline { display: flex; gap: 4px; margin-top: 14px; }
.pip-step {
  flex: 1; height: 4px;
  border-radius: 2px;
  background: var(--border-light);
  transition: background 0.3s;
}
.pip-step.done { background: var(--success); }
.pip-step.active { background: var(--processing); animation: pulse 1.5s ease infinite; }
.pip-step.error { background: var(--danger); }
.pip-labels { display: flex; gap: 4px; margin-top: 5px; }
.pip-label {
  flex: 1;
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.post-actions { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Metrics Grid (Reports) ── */
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
.metric-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 18px;
}
.metric-label { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 4px; }
.metric-val { font-size: 1.4rem; font-weight: 600; font-family: var(--font-mono); }
.metric-delta { font-size: 0.78rem; margin-top: 3px; }
.metric-delta.up { color: var(--success); }
.metric-delta.down { color: var(--danger); }

/* ── Chart Container ── */
.chart-wrap {
  height: 220px;
  margin-bottom: 28px;
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  padding: 16px;
}

/* ── Data Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.data-table tr:hover td { background: var(--bg-surface); }

.sparkline { display: flex; align-items: flex-end; gap: 2px; height: 24px; }
.spark-bar { width: 4px; border-radius: 2px; background: var(--accent); opacity: 0.6; }

/* ── Automation View ── */
.auto-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 16px;
}
.auto-card-title { font-size: 0.95rem; font-weight: 500; margin-bottom: 12px; }
.auto-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}
.auto-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
}
.auto-dot.running { background: var(--success); box-shadow: 0 0 8px rgba(26,122,66,0.3); }
.auto-dot.stopped { background: var(--danger); }

.rate-limits {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}
.rl-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 14px;
}
.rl-provider { font-size: 0.82rem; font-weight: 500; margin-bottom: 4px; }
.rl-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--border-light);
  margin-top: 8px;
  overflow: hidden;
}
.rl-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.5s; }
.rl-text { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-tertiary);
}

/* ── Field Error ── */
.field-error {
  font-size: 0.82rem;
  color: var(--danger);
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--danger-light);
  border-radius: var(--radius-md);
  line-height: 1.4;
}
.empty-state-icon { font-size: 2rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state-text { font-size: 0.9rem; }

/* ── Loading Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */

/* ── Guide View ── */
.guide-section {
  margin-bottom: 32px;
}
.guide-section-title {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}
.guide-step {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}
.guide-step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.guide-step-content {
  flex: 1;
}
.guide-step-title {
  font-size: 0.93rem;
  font-weight: 500;
  margin-bottom: 4px;
}
.guide-step-body {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.guide-tip {
  background: var(--accent-light);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 0.85rem;
  color: var(--accent);
  margin-top: 8px;
  line-height: 1.5;
}
.guide-tip-label {
  font-weight: 500;
  margin-right: 4px;
}

@media (max-width: 680px) {
  #nav { padding: 0 12px; }
  .nav-left { flex: 0 0 auto; }
  .nav-center { gap: 0; }
  .nav-link { padding: 6px 10px; font-size: 0.78rem; }
  .nav-right { display: none; }
  #view-container { padding: 20px 14px 60px; }
  .opts-grid { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .rate-limits { grid-template-columns: 1fr; }
  .status-bar { padding: 0 12px; height: auto; flex-wrap: wrap; padding: 8px 12px; }
  .stat { min-width: 0; }
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-weight: 600;
  font-size: 1rem;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}
.modal-body {
  padding: 20px;
}
.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
