/* ═══════════════════════════════════════════════════════════
   AI Document Intelligence SaaS — Executive Design System
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Design Tokens (Warm Emerald & Rich Slate Palette) ── */
:root {
  /* Surface palette - Warm neutral charcoal & obsidian */
  --bg-root: #0b0d12;
  --bg-surface: #11141d;
  --bg-raised: #171b26;
  --bg-overlay: rgba(17, 20, 29, 0.90);
  --bg-glass: rgba(23, 27, 38, 0.70);

  /* Border - Fine neutral glass borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.11);
  --border-strong: rgba(255, 255, 255, 0.20);
  --border-glow: rgba(16, 185, 129, 0.30);

  /* Text - High contrast warm typography */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Human Handcrafted Accents (Emerald & Warm Gold) */
  --accent-indigo: #10b981; /* Replaced indigo with Emerald */
  --accent-indigo-hover: #059669;
  --accent-blue: #14b8a6; /* Teal */
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-violet: #8b5cf6;

  /* Confidence badges */
  --conf-high: #10b981;
  --conf-medium: #f59e0b;
  --conf-low: #f43f5e;

  /* Status */
  --status-approved: #10b981;
  --status-review: #f59e0b;
  --status-failed: #f43f5e;
  --status-processing: #14b8a6;
  --status-queued: #8b5cf6;

  /* Sizing */
  --sidebar-width: 260px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Transitions & Shadows */
  --transition-fast: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-default: 280ms cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 12px 30px -4px rgba(0, 0, 0, 0.5), 0 0 20px rgba(16, 185, 129, 0.15);
}

/* ── Light Theme Overrides ── */
html[data-theme="light"] {
  --bg-root: #f8fafc;
  --bg-surface: #ffffff;
  --bg-raised: #ffffff;
  --bg-overlay: rgba(255, 255, 255, 0.95);
  --bg-glass: rgba(255, 255, 255, 0.85);

  --border-subtle: #e2e8f0;
  --border-default: #cbd5e1;
  --border-strong: #94a3b8;
  --border-glow: rgba(16, 185, 129, 0.35);

  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --text-dim: #94a3b8;

  --accent-indigo: #059669;
  --accent-indigo-hover: #047857;
  --accent-blue: #0d9488;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-violet: #7c3aed;

  --status-approved: #059669;
  --status-review: #d97706;
  --status-failed: #e11d48;
  --status-processing: #0d9488;
  --status-queued: #7c3aed;

  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.05), 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 0 15px rgba(16, 185, 129, 0.12);
}

/* ── Light Mode Specific Component Rules ── */
html[data-theme="light"] .sidebar-brand-name {
  background: linear-gradient(135deg, #0f172a, #334155);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

html[data-theme="light"] .sidebar-brand-tag {
  color: #059669;
}

html[data-theme="light"] .sidebar-section-label {
  color: #64748b;
  font-weight: 700;
}

html[data-theme="light"] .sidebar-nav-item a {
  color: #475569;
}

html[data-theme="light"] .sidebar-nav-item a:hover {
  background: #f1f5f9;
  color: #0f172a;
}

html[data-theme="light"] .sidebar-nav-item a.active {
  background: #f1f5f9;
  color: #0f172a;
  border-left: 3px solid #059669;
}

html[data-theme="light"] .sidebar-nav-item a.active .nav-icon {
  stroke: #059669;
}

html[data-theme="light"] .card,
html[data-theme="light"] .metric-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.03);
}

html[data-theme="light"] .card:hover,
html[data-theme="light"] .metric-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.08);
}

html[data-theme="light"] .metric-label {
  color: #475569;
}

html[data-theme="light"] .metric-value {
  color: #0f172a;
}

html[data-theme="light"] .metric-change {
  color: #64748b;
}

html[data-theme="light"] .data-table th {
  background: #f8fafc;
  color: #475569;
  border-bottom: 1px solid #e2e8f0;
}

html[data-theme="light"] .data-table td {
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

html[data-theme="light"] .data-table tbody tr:hover {
  background: #f8fafc;
}

html[data-theme="light"] .badge-approved {
  background: #d1fae5;
  color: #047857;
}

html[data-theme="light"] .badge-review {
  background: #fef3c7;
  color: #b45309;
}

html[data-theme="light"] .badge-processing {
  background: #ccfbf1;
  color: #0f766e;
}

html[data-theme="light"] .badge-failed {
  background: #ffe4e6;
  color: #be123c;
}

html[data-theme="light"] .form-input,
html[data-theme="light"] .form-select {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #0f172a;
}

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

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-root);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

code, pre, kbd, .mono { font-family: var(--font-mono); }

a { color: var(--accent-indigo); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-blue); }

img { max-width: 100%; display: block; }

/* ── App Shell ── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #f8fafc, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-brand-tag {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-indigo);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-section {
  padding: 16px 12px 8px;
}

.sidebar-section-label {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 0 8px;
  margin-bottom: 6px;
}

.sidebar-nav { list-style: none; }

.sidebar-nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.87rem;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.sidebar-nav-item a:hover {
  background: rgba(16, 185, 129, 0.08);
  color: var(--text-primary);
  transform: translateX(3px);
}

.sidebar-nav-item a.active {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.16), rgba(16, 185, 129, 0.03));
  color: #34d399;
  font-weight: 600;
  border-left: 3px solid var(--accent-emerald);
  padding-left: 9px;
}

.sidebar-nav-item .nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.sidebar-nav-item a.active .nav-icon { opacity: 1; }

.sidebar-nav-badge {
  margin-left: auto;
  background: rgba(251,113,133,0.15);
  color: var(--accent-rose);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  font-family: var(--font-mono);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-org {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.sidebar-org-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 800; color: #fff;
}

.sidebar-org-name { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); }
.sidebar-org-plan { font-size: 0.68rem; color: var(--text-muted); }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

.page-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 32px;
}

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Cards ── */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: all var(--transition-default);
}

.card:hover {
  border-color: var(--border-default);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card-glass {
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

.card-body { padding: 20px; }

/* ── Metric Cards ── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  transition: border-color var(--transition-fast);
}

.metric-card:hover { border-color: var(--border-strong); }

.metric-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font-mono);
  letter-spacing: -0.5px;
}

.metric-value.indigo { color: var(--accent-indigo); }
.metric-value.blue { color: var(--accent-blue); }
.metric-value.emerald { color: var(--accent-emerald); }
.metric-value.amber { color: var(--accent-amber); }
.metric-value.rose { color: var(--accent-rose); }

.metric-change {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #34d399, #059669);
  box-shadow: 0 6px 22px rgba(16, 185, 129, 0.45);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-success {
  background: rgba(52,211,153,0.12);
  color: var(--accent-emerald);
  border-color: rgba(52,211,153,0.2);
}
.btn-success:hover { background: rgba(52,211,153,0.2); }

.btn-danger {
  background: rgba(251,113,133,0.12);
  color: var(--accent-rose);
  border-color: rgba(251,113,133,0.2);
}
.btn-danger:hover { background: rgba(251,113,133,0.2); }

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 0.92rem; }
.btn-block { width: 100%; }

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  background: var(--bg-raised);
}

.data-table td {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: rgba(99,102,241,0.04); }

/* ── Status Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge-approved { background: rgba(52,211,153,0.12); color: var(--status-approved); }
.badge-review { background: rgba(251,191,36,0.12); color: var(--status-review); }
.badge-failed { background: rgba(251,113,133,0.12); color: var(--status-failed); }
.badge-processing { background: rgba(56,189,248,0.12); color: var(--status-processing); }
.badge-queued { background: rgba(167,139,250,0.12); color: var(--status-queued); }

.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Confidence Indicators ── */
.confidence-bar {
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.confidence-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition-default);
}

.confidence-high .confidence-bar-fill { background: var(--conf-high); }
.confidence-medium .confidence-bar-fill { background: var(--conf-medium); }
.confidence-low .confidence-bar-fill { background: var(--conf-low); }

.confidence-label {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 600;
}
.confidence-label.high { color: var(--conf-high); }
.confidence-label.medium { color: var(--conf-medium); }
.confidence-label.low { color: var(--conf-low); }

/* ── Form Inputs ── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 9px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  transition: border-color var(--transition-fast);
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.form-textarea { min-height: 80px; resize: vertical; }

/* ── Progress Bar ── */
.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-indigo), var(--accent-blue));
  transition: width var(--transition-default);
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  transition: all var(--transition-default);
  cursor: pointer;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent-indigo);
  background: rgba(99,102,241,0.04);
}

.upload-zone-icon {
  width: 48px; height: 48px;
  margin: 0 auto 16px;
  color: var(--text-dim);
}

.upload-zone-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.upload-zone-text {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Review Workspace ── */
.review-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  min-height: calc(100vh - 200px);
}

.review-document {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.review-document img { width: 100%; height: auto; }

.review-bbox {
  position: absolute;
  border: 2px solid var(--accent-blue);
  background: rgba(56,189,248,0.08);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.review-bbox:hover, .review-bbox.active {
  border-color: var(--accent-indigo);
  background: rgba(99,102,241,0.15);
  box-shadow: 0 0 12px rgba(99,102,241,0.3);
}

.review-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review-field-row {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.review-field-row:hover { border-color: var(--border-strong); }
.review-field-row.active { border-color: var(--accent-indigo); }
.review-field-row.flagged { border-color: var(--accent-amber); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 64px 32px;
}

.empty-state-icon {
  width: 56px; height: 56px;
  margin: 0 auto 20px;
  color: var(--text-dim);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 380px;
  margin: 0 auto;
}

/* ── Tabs ── */
.tab-list {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  gap: 0;
  margin-bottom: 20px;
}

.tab-trigger {
  padding: 10px 20px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}

.tab-trigger:hover { color: var(--text-secondary); }
.tab-trigger.active {
  color: var(--accent-indigo);
  border-bottom-color: var(--accent-indigo);
}

/* ── Utilities ── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 0.82rem; }
.text-xs { font-size: 0.72rem; }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .sidebar { width: 220px; }
  .main-content { margin-left: 220px; }
  .review-layout { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .page-container { padding: 16px; }
}
