:root {
  color-scheme: dark;
  --bg: #0a0e1a;
  --surface: #111827;
  --surface-2: #161f33;
  --surface-elevated: #1e2740;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: rgba(124, 58, 237, 0.16);
  --secondary: #06b6d4;
  --secondary-soft: rgba(6, 182, 212, 0.14);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --border: #1e293b;
  --border-strong: #334155;
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

@font-face {
  font-family: 'Inter';
  src: url('/static/studio.ttf');
  font-weight: 100 900;
  font-display: swap;
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* Reusable Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.62rem 1.1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  transition: transform var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #ffffff;
  border: 1px solid rgba(167, 139, 250, 0.35);
  box-shadow: 0 6px 20px -6px rgba(124, 58, 237, 0.55);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 26px -6px rgba(124, 58, 237, 0.72);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-elevated);
  border-color: rgba(6, 182, 212, 0.45);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: rgba(30, 39, 64, 0.65);
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger-soft);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.24);
}

.btn-sm {
  padding: 0.42rem 0.78rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.26rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
}

.badge-success { background: var(--success-soft); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.35); }
.badge-warning { background: var(--warning-soft); color: #fcd34d; border-color: rgba(245, 158, 11, 0.38); }
.badge-danger  { background: var(--danger-soft); color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
.badge-violet  { background: var(--primary-soft); color: #ddd6fe; border-color: rgba(124, 58, 237, 0.45); }
.badge-cyan    { background: var(--secondary-soft); color: #67e8f9; border-color: rgba(6, 182, 212, 0.38); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-success { background: var(--success); box-shadow: 0 0 8px var(--success); }
.dot-warning { background: var(--warning); box-shadow: 0 0 8px var(--warning); }
.dot-danger  { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.dot-cyan    { background: var(--secondary); box-shadow: 0 0 8px var(--secondary); }

/* Form Fields */
.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.45rem;
}

.input, .textarea, .select {
  width: 100%;
  background: #0c1222;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.68rem 0.9rem;
  font-size: 0.92rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.textarea {
  resize: vertical;
  min-height: 132px;
  line-height: 1.6;
}

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.22);
}

.input::placeholder, .textarea::placeholder {
  color: var(--text-muted);
}

/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
}

.card-subtle {
  background: rgba(17, 24, 39, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

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

/* App Shell Layout */
.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #080c17;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.15rem 0.9rem;
  z-index: 60;
  overflow-y: auto;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.35rem 0.55rem 1.1rem;
  font-weight: 700;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.28), rgba(6, 182, 212, 0.22));
  border: 1px solid rgba(124, 58, 237, 0.5);
  color: var(--secondary);
  flex-shrink: 0;
}

.nav-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  padding: 0.45rem 0.65rem;
  margin-top: 0.4rem;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0.62rem 0.78rem;
  border-radius: 10px;
  font-size: 0.89rem;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  color: var(--text-primary);
  background: rgba(30, 39, 64, 0.52);
}

.nav-item[aria-current="page"] {
  color: #ffffff;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.24), rgba(6, 182, 212, 0.1));
  border-color: rgba(124, 58, 237, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

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

/* Main Workspace Area */
.workspace-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 64px;
  background: rgba(10, 14, 26, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0 clamp(1rem, 3vw, 2rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
}

.mobile-nav-btn {
  display: none;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  align-items: center;
  justify-content: center;
}

.topbar-title {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.workspace-content {
  padding: clamp(1.25rem, 3vw, 2rem);
  max-width: 1320px;
  width: 100%;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Demo Mode Banner */
.demo-banner {
  background: linear-gradient(90deg, rgba(6, 182, 212, 0.14), rgba(124, 58, 237, 0.16));
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: 14px;
  padding: 0.9rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.demo-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.65rem;
}

/* Grids */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.split-desk {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1.35rem;
  align-items: start;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin: 0.25rem 0;
}

/* Progress / Confidence Bars */
.meter-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.meter-track {
  height: 8px;
  border-radius: 999px;
  background: #0c1222;
  border: 1px solid var(--border);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 450ms cubic-bezier(0.22, 1, 0.36, 1);
}

.fill-danger  { background: linear-gradient(90deg, #dc2626, #ef4444); }
.fill-warning { background: linear-gradient(90deg, #d97706, #f59e0b); }
.fill-success { background: linear-gradient(90deg, #059669, #10b981); }
.fill-violet  { background: linear-gradient(90deg, #6d28d9, #7c3aed); }
.fill-cyan    { background: linear-gradient(90deg, #0891b2, #06b6d4); }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

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

th, td {
  padding: 0.78rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: #0d1323;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(30, 39, 64, 0.3); }

/* Upload Dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  background: #0c1222;
  border-radius: 14px;
  padding: 1.75rem 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--secondary);
  background: rgba(6, 182, 212, 0.06);
}

.image-preview-box {
  margin-top: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #070a14;
  max-height: 260px;
  display: grid;
  place-items: center;
}

.image-preview-box img {
  max-width: 100%;
  max-height: 256px;
  object-fit: contain;
}

/* Code / OCR Blocks */
.mono-block {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.6;
  background: #090d18;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #cbd5e1;
}

/* Pipeline Stepper */
.pipeline-steps {
  display: grid;
  gap: 0.65rem;
}

.pipeline-step {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.72rem 0.9rem;
  background: #0c1222;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-soft);
  border: 1px solid rgba(124, 58, 237, 0.45);
  color: #ddd6fe;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Skeleton Loader */
.skeleton {
  background: linear-gradient(90deg, #161f33 25%, #1e2740 50%, #161f33 75%);
  background-size: 200% 100%;
  animation: shimmer 1.35s infinite;
  border-radius: 8px;
  height: 16px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty & Error States */
.empty-state {
  text-align: center;
  padding: 2.2rem 1.25rem;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  color: var(--text-secondary);
}

.error-state {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.38);
  color: #fecaca;
  border-radius: 12px;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Toast Notification Container */
.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-width: 360px;
}

.toast {
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 0.78rem 1rem;
  border-radius: 12px;
  font-size: 0.86rem;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toastIn 180ms ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Public / Secondary Page Container */
.page-nav {
  position: sticky;
  top: 0;
  z-index: 80;
  height: 68px;
  background: rgba(10, 14, 26, 0.86);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.page-container {
  max-width: 1140px;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

.page-nav-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.page-nav-links a {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.page-nav-links a:hover, .page-nav-links a[aria-current="page"] {
  color: var(--text-primary);
}

/* Responsive */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split-desk, .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    width: 260px;
    transition: left 200ms ease;
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.8);
  }
  .sidebar.open {
    left: 0;
  }
  .mobile-nav-btn {
    display: inline-flex;
  }
}

@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .no-print, .toast-stack {
    display: none !important;
  }
  .app-shell {
    display: block;
  }
  body, .card {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
  }
  .muted, .small-muted {
    color: #334155 !important;
  }
}