:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.masked-secret { -webkit-text-security: disc; }

.app-shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 20px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  text-align: left;
}

.nav-item:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary);
  color: #ffffff;
}

.nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text-secondary);
}

.nav-item.active .nav-badge {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  margin-left: auto;
  flex-shrink: 0;
}

.status-dot.connected { background: var(--success); }

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.privacy-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
}

.privacy-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.privacy-card p {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Main Content */
.main-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.pill-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pill-status:hover {
  border-color: var(--border-strong);
  background: var(--bg);
}

.view {
  display: none;
  padding: 24px 28px;
  flex: 1;
}

.view.active { display: block; }

/* Analyze Grid */
.analyze-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr);
  gap: 20px;
  max-width: 1380px;
  margin: 0 auto;
  align-items: start;
}

.analyze-primary, .analyze-secondary {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-subtitle {
  margin: 3px 0 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-grid-2 .field { margin-bottom: 0; }

.field label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.field input[type="text"],
.field input[type="date"],
.field input[type="password"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.transcript-dropzone textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.field-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.transcript-dropzone {
  position: relative;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}

.transcript-dropzone.drag-over {
  outline: 2px dashed var(--accent);
  background: var(--accent-soft);
}

.transcript-dropzone textarea {
  width: 100%;
  min-height: 360px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.6;
  resize: vertical;
  color: var(--text);
  background: var(--bg);
}

.transcript-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.metrics-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.file-badge {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 999px;
}

/* AI Summary Box */
.ai-summary-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ai-summary-box.configured {
  background: var(--success-bg);
  border-color: #a7f3d0;
}

.ai-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  gap: 10px;
}

.ai-summary-label { color: var(--text-muted); }
.ai-summary-value { font-weight: 600; color: var(--text); text-align: right; }

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.reliability-callout {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.callout-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.reliability-callout ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: var(--text-secondary);
}

.reliability-callout li { margin-bottom: 3px; }

.privacy-destination-note {
  margin: 10px 0 0 0;
  font-size: 11.5px;
  color: var(--text-muted);
  text-align: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 16px; font-size: 14px; font-weight: 600; }
.btn-full { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}
.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-bg);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-subtle); color: var(--text); }

/* Stages Progress */
.stages-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.stages-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.stage-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  flex-shrink: 0;
}

.stages-list li.active {
  color: var(--accent);
  font-weight: 600;
}
.stages-list li.active .stage-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.16);
}

.stages-list li.done { color: var(--success); }
.stages-list li.done .stage-dot { background: var(--success); }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Alerts */
.alert-error {
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: #991b1b;
  font-size: 13px;
}
.alert-title { font-weight: 600; margin-bottom: 3px; }
.alert-error p { margin: 0; }

/* Report View & Toolbar */
.report-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.toolbar-left, .toolbar-right, .export-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-tabs {
  display: inline-flex;
  background: var(--surface-subtle);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.mode-tab {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.report-preview-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: calc(100vh - 165px);
  min-height: 600px;
}

#report-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
}

/* Editor Pane */
.editor-sections-container {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.editor-section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.editor-section-card.is-hidden {
  opacity: 0.6;
  background: var(--bg);
}

.editor-sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.editor-sec-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
}

.editor-sec-actions {
  display: flex;
  gap: 8px;
}

.editor-subcard {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
}

.editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.editor-table th {
  text-align: left;
  padding: 8px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.editor-table td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.editor-table input, .editor-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: inherit;
  font-size: 12.5px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.history-info h4 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
}

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.history-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  overflow: hidden;
}

.modal-card.modal-sm { max-width: 440px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 20px 14px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
.modal-header p { margin: 3px 0 0 0; font-size: 12.5px; color: var(--text-muted); }

.modal-body { padding: 18px 20px; }

.input-with-action {
  display: flex;
  gap: 8px;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.modal-footer-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  background: var(--primary);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: fadeUp 0.2s ease;
}

.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

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

.mobile-only { display: none; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -270px;
    z-index: 40;
    width: 256px;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .mobile-only { display: inline-flex; }
  .analyze-grid { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .history-row { flex-direction: column; align-items: flex-start; }
}
