/* ═══════════════════════════════════════════════════════════
   ThreadClarity — Customer Conversation Intelligence
   Premium dark utility design aligned with threadclarity.kamyab.co.in
   ═══════════════════════════════════════════════════════════ */

/* ─── DESIGN TOKENS ────────────────────────────────────── */
:root {
  /* Core palette — zinc-neutral dark (matches website) */
  --bg-primary: #09090b;
  --bg-secondary: #0e0e10;
  --bg-tertiary: #1c1c1f;
  --bg-card: #151518;
  --bg-hover: #27272a;
  --bg-active: #3f3f46;

  /* Borders */
  --border-default: rgba(255,255,255,0.06);
  --border-muted: rgba(255,255,255,0.04);
  --border-accent: rgba(45, 212, 168, 0.15);
  --border-strong: rgba(255,255,255,0.1);

  /* Text */
  --text-primary: #fafafa;
  --text-secondary: #c4c4cc;
  --text-muted: #a1a1aa;
  --text-link: #2DD4A8;

  /* Accents — teal/navy system matching ThreadClarity logo */
  --accent-blue: #2DD4A8;
  --accent-green: #34d399;
  --accent-orange: #fbbf24;
  --accent-red: #f87171;
  --accent-purple: #2DD4A8;
  --accent-cyan: #1B6B8A;
  --accent-dim: rgba(45, 212, 168, 0.08);
  --accent-glow: rgba(45, 212, 168, 0.25);
  --brand-green: #2DD4A8;
  --brand-blue: #3BA4C8;

  /* Status */
  --status-success: #34d399;
  --status-warning: #fbbf24;
  --status-error: #f87171;
  --status-info: #2DD4A8;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius — rounder like website */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 20px;

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

  /* Shadows — deeper, more premium */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);

  /* Surface — glassmorphism */
  --surface: rgba(255,255,255,0.025);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* ─── LIGHT MODE ───────────────────────────────────────── */
[data-theme="light"] {
  /* Core palette — clean neutral light (matches website light vars) */
  --bg-primary: #fafbfd;
  --bg-secondary: #f3f4f8;
  --bg-tertiary: #ebedf2;
  --bg-card: #ffffff;
  --bg-hover: #e8e9ee;
  --bg-active: #dcdee5;

  /* Borders */
  --border-default: rgba(0,0,0,0.08);
  --border-muted: rgba(0,0,0,0.05);
  --border-accent: rgba(45, 212, 168, 0.2);
  --border-strong: rgba(0,0,0,0.12);

  /* Text */
  --text-primary: #18181b;
  --text-secondary: #3f3f46;
  --text-muted: #52525b;
  --text-link: #0f766e;

  /* Accents — teal/navy system, deeper for light mode contrast */
  --accent-blue: #1B6B8A;
  --accent-green: #059669;
  --accent-orange: #d97706;
  --accent-red: #dc2626;
  --accent-purple: #1B6B8A;
  --accent-cyan: #0891b2;
  --accent-dim: rgba(15, 155, 129, 0.06);
  --accent-glow: rgba(15, 155, 129, 0.15);

  /* Status */
  --status-success: #059669;
  --status-warning: #d97706;
  --status-error: #dc2626;
  --status-info: #1B6B8A;

  /* Shadows — lighter, subtler */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);

  /* Surface */
  --surface: rgba(0,0,0,0.025);
}

/* Light mode: override hardcoded rgba values on elements */
[data-theme="light"] body::after {
  opacity: 0;
}

[data-theme="light"] ::selection {
  background: rgba(15, 155, 129, 0.2);
}

[data-theme="light"] #app-header {
  background: rgba(250, 251, 253, 0.85);
  border-bottom-color: rgba(0,0,0,0.06);
}

[data-theme="light"] .section-card {
  background: var(--bg-card);
  border-color: var(--border-default);
  box-shadow: var(--shadow-sm);
  backdrop-filter: none;
}

[data-theme="light"] .threads-stats-bar {
  background: var(--bg-card);
  border-color: var(--border-default);
  box-shadow: var(--shadow-sm);
  backdrop-filter: none;
}

[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="email"],
[data-theme="light"] input[type="password"],
[data-theme="light"] input[type="number"],
[data-theme="light"] input[type="search"],
[data-theme="light"] input[type="url"],
[data-theme="light"] textarea,
[data-theme="light"] select {
  background: var(--bg-card);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

[data-theme="light"] input[type="text"]:focus,
[data-theme="light"] input[type="email"]:focus,
[data-theme="light"] input[type="password"]:focus,
[data-theme="light"] input[type="number"]:focus,
[data-theme="light"] input[type="search"]:focus,
[data-theme="light"] input[type="url"]:focus,
[data-theme="light"] textarea:focus,
[data-theme="light"] select:focus {
  background: var(--bg-card);
  border-color: rgba(15, 155, 129, 0.5);
  box-shadow: 0 0 0 3px rgba(15, 155, 129, 0.08);
}

[data-theme="light"] .header-nav {
  background: var(--bg-tertiary);
}

[data-theme="light"] .header-brand h1 {
  color: var(--text-primary);
}

[data-theme="light"] .header-subtitle {
  color: var(--text-muted);
}

[data-theme="light"] .thread-item.active {
  background: rgba(15, 155, 129, 0.06);
  border-left-color: var(--accent-blue);
}

[data-theme="light"] .thread-item:hover {
  background: var(--bg-hover);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.2);
}

[data-theme="light"] .preview-msg-sender {
  color: var(--accent-blue);
}

[data-theme="light"] .preview-original-post .preview-msg-sender {
  color: var(--accent-cyan);
}

[data-theme="light"] .op-indicator {
  background: rgba(15, 155, 129, 0.08);
  color: var(--accent-blue);
}

[data-theme="light"] .mode-badge.reply_chain {
  background: rgba(15, 155, 129, 0.06);
  color: var(--accent-blue);
  border-color: rgba(15, 155, 129, 0.15);
}

[data-theme="light"] .mode-badge.orphan {
  background: rgba(217, 119, 6, 0.06);
  color: var(--accent-orange);
  border-color: rgba(217, 119, 6, 0.15);
}

[data-theme="light"] .mode-badge.conversation {
  background: rgba(6, 182, 212, 0.06);
  color: #0891b2;
  border-color: rgba(6, 182, 212, 0.15);
}

[data-theme="light"] .mode-badge.topic {
  background: rgba(16, 185, 129, 0.06);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.15);
}

[data-theme="light"] .pill-count {
  background: var(--bg-tertiary);
}

[data-theme="light"] .admin-pill.active .pill-count {
  background: rgba(15, 155, 129, 0.12);
}

[data-theme="light"] .job-status.ready {
  background: rgba(5, 150, 105, 0.1);
  color: var(--accent-green);
}

[data-theme="light"] .job-status.failed {
  background: rgba(220, 38, 38, 0.08);
  color: var(--accent-red);
}

[data-theme="light"] .job-status.pending,
[data-theme="light"] .job-status.parsing,
[data-theme="light"] .job-status.threading {
  background: rgba(15, 155, 129, 0.08);
  color: var(--accent-blue);
}

[data-theme="light"] .nav-btn {
  color: var(--text-muted);
}

[data-theme="light"] .nav-btn:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

[data-theme="light"] .nav-num {
  background: rgba(0,0,0,0.08);
}

[data-theme="light"] .nav-btn.active .nav-num {
  background: rgba(255,255,255,0.3);
}

[data-theme="light"] .tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

[data-theme="light"] .progress-log {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .admin-filter-bar {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .admin-pill {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .preview-original-post {
  background: var(--bg-secondary);
  border-color: var(--border-default);
}

[data-theme="light"] .preview-msg-reply-context {
  background: var(--bg-secondary);
}

[data-theme="light"] .preview-msg-media {
  background: var(--bg-secondary);
  border-color: var(--border-default);
}

[data-theme="light"] .merge-modal {
  background: rgba(255, 255, 255, 0.97);
  border-color: var(--border-strong);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .modal-content {
  background: rgba(255, 255, 255, 0.97);
  border-color: var(--border-strong);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .folder-picker {
  background: rgba(255, 255, 255, 0.97);
  border-color: var(--border-strong);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .merge-overlay,
[data-theme="light"] .modal-overlay,
[data-theme="light"] .rename-dialog {
  background: rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .picker-breadcrumbs {
  background: var(--bg-secondary);
}

[data-theme="light"] .picker-footer {
  background: var(--bg-secondary);
}

[data-theme="light"] .picker-toolbar {
  background: var(--bg-secondary);
}

[data-theme="light"] .picker-sort-select {
  background: var(--bg-card);
  border-color: var(--border-default);
  color: var(--text-primary);
}

[data-theme="light"] .merge-modal-search input {
  background: var(--bg-secondary);
  border-color: var(--border-default);
}

[data-theme="light"] .rename-dialog-content {
  background: var(--bg-card);
  border-color: var(--border-default);
  box-shadow: var(--shadow-lg);
}

[data-theme="light"] .job-item {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
}

[data-theme="light"] .format-card {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .format-option input:checked + .format-card {
  border-color: var(--accent-blue);
  background: rgba(15, 155, 129, 0.04);
}

[data-theme="light"] .validation-result {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .progress-stat {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
}

[data-theme="light"] .density-toggle {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .stat-chip {
  background: rgba(15, 155, 129, 0.04);
  border-color: rgba(15, 155, 129, 0.12);
}

[data-theme="light"] .participant-chip {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-default);
  color: var(--text-primary);
}

[data-theme="light"] .btn-secondary:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

[data-theme="light"] .btn-load-more {
  background: var(--bg-card);
  border-color: var(--border-default);
}

[data-theme="light"] .btn-load-more:hover {
  background: var(--bg-tertiary);
}

[data-theme="light"] .picker-item.is-telegram-export {
  background: rgba(15, 155, 129, 0.03);
}

[data-theme="light"] .picker-item.is-telegram-export:hover {
  background: rgba(15, 155, 129, 0.07);
}

/* ─── THEME TOGGLE BUTTON ─────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border-default);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.theme-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  display: none;
}

[data-theme="light"] .theme-toggle .icon-moon { display: inline; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }

:root .theme-toggle .icon-sun { display: inline; }
:root .theme-toggle .icon-moon { display: none; }

/* Override when explicitly dark */
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 100vh;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#main-content {
  flex: 1;
}

/* Subtle noise texture overlay (matches website) */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.02'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

::selection { background: rgba(45, 212, 168, 0.3); }

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── APP LEGAL FOOTER ─────────────────────────────────── */
.app-legal-footer {
  border-top: 1px solid var(--border-muted);
  padding: var(--space-md) var(--space-lg);
  margin-top: auto;
}

.app-legal-nav {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-lg);
  justify-content: center;
  align-items: center;
}

.app-legal-nav a {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.app-legal-nav a:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* ─── HEADER ───────────────────────────────────────────── */
#app-header {
  background: rgba(14, 14, 16, 0.7);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-lg);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.back-to-home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  text-decoration: none;
}

.back-to-home:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
  transform: translateX(-2px);
}

.header-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.header-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.header-nav {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  padding: 3px;
  border-radius: var(--radius-lg);
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  white-space: nowrap;
}

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

.nav-btn.active {
  background: var(--brand-green);
  color: #042f2e;
  box-shadow: none;
}

[data-theme="light"] .nav-btn.active {
  background: #0f766e;
  color: #ffffff;
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-num {
  font-size: 0.7rem;
  font-weight: 600;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
}

.nav-btn.active .nav-num {
  background: rgba(4, 47, 46, 0.12);
  color: inherit;
}

[data-theme="light"] .nav-btn.active .nav-num {
  background: rgba(255, 255, 255, 0.2);
}

/* ─── SCREENS ──────────────────────────────────────────── */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

.screen-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
}

.screen-inner.wide {
  max-width: 1400px;
}

.screen-actions {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-muted);
}

/* ─── CARDS ────────────────────────────────────────────── */
.section-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.section-card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: var(--space-xs);
  letter-spacing: -0.01em;
}

.section-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: var(--space-lg);
}

/* ─── BUTTONS ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand-green);
  border-color: transparent;
  color: #042f2e;
  font-weight: 600;
}

[data-theme="light"] .btn-primary {
  background: #0f766e;
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(45, 212, 168, 0.22);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

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

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.btn-lg {
  padding: var(--space-md) var(--space-xl);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-lg);
}

.btn-danger {
  color: var(--accent-red);
  border-color: var(--accent-red);
  background: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 81, 73, 0.15);
}

/* ─── FORM ELEMENTS ────────────────────────────────────── */
.input-group {
  margin-bottom: var(--space-lg);
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.input-row {
  display: flex;
  gap: var(--space-sm);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(45, 212, 168, 0.5);
  box-shadow: 0 0 0 3px rgba(45, 212, 168, 0.1);
  background: rgba(255,255,255,0.06);
}

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

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-tertiary) inset;
  -webkit-text-fill-color: var(--text-primary);
  caret-color: var(--text-primary);
  border-color: var(--border-default);
  transition: background-color 9999s ease-out 0s;
}

select {
  font-family: var(--font-sans);
  cursor: pointer;
}

input.input-sm,
select.input-sm {
  width: 100px;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"],
.checkbox-label input[type="radio"] {
  accent-color: var(--accent-blue);
  width: 16px;
  height: 16px;
}

/* ─── INPUT SCREEN ─────────────────────────────────────── */
.input-mode-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  width: 100%;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 500;
}

.validation-result {
  margin-top: var(--space-lg);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
}

.validation-result.valid {
  border-color: var(--status-success);
}

.validation-result.invalid {
  border-color: var(--status-error);
}

.validation-result h3 {
  font-size: 0.9rem;
  margin-bottom: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.validation-detail {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
  font-size: 0.82rem;
}

.validation-detail .label {
  color: var(--text-muted);
}

.validation-detail .value {
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.hidden { display: none !important; }

/* ─── SETTINGS ─────────────────────────────────────────── */
.settings-grid {
  display: grid;
  gap: var(--space-lg);
}

.setting-group {
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-muted);
}

.setting-group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  display: block;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* ─── PROGRESS ─────────────────────────────────────────── */
.progress-status {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.progress-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1rem;
  font-weight: 600;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border-default);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-bar-container {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: var(--space-lg);
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), #1B6B8A);
  border-radius: 3px;
  transition: width 0.3s ease;
  box-shadow: 0 0 12px var(--accent-glow);
}

.progress-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
}

.progress-stat {
  background: var(--bg-tertiary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-xs);
}

.stat-value {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.progress-log {
  margin-top: var(--space-lg);
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.8;
  background: var(--bg-primary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-muted);
}

.progress-log .log-entry {
  padding: 2px 0;
}

.progress-log .log-entry.error { color: var(--accent-red); }
.progress-log .log-entry.success { color: var(--accent-green); }

/* ─── THREAD REVIEW ─────────────────────────────────────── */
.threads-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  align-items: start;
}

/* ─── STATS SUMMARY BAR ───────────────────────────────── */
.threads-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  border-radius: 100px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-chip strong {
  color: var(--text-primary);
  font-weight: 700;
  font-family: var(--font-mono);
}

.stat-chip .stat-icon {
  font-size: 0.9rem;
}

/* ─── CHANNEL ↔ DISCUSSION LINK ───────────────────────── */
.discussion-link-card {
  margin-bottom: var(--space-lg);
  border-color: rgba(45, 212, 168, 0.22);
  background: linear-gradient(180deg, rgba(45, 212, 168, 0.06), rgba(255, 255, 255, 0.02));
}

.discussion-link-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
}

.discussion-link-header .section-desc {
  margin-bottom: 0;
  max-width: 62ch;
}

.discussion-link-card.collapsed #discussion-link-body {
  display: none;
}

.discussion-link-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.discussion-channel-job {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  word-break: break-word;
}

.discussion-channel-job .job-meta {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
}

.discussion-link-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.discussion-link-result {
  margin-top: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.discussion-link-result.is-preview {
  border-color: rgba(45, 212, 168, 0.35);
}

.discussion-link-result.is-success {
  border-color: rgba(52, 211, 153, 0.45);
  background: rgba(52, 211, 153, 0.08);
}

.discussion-link-result.is-error {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
  color: var(--accent-red);
}

.discussion-link-result .result-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.discussion-link-result .result-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid var(--border-accent);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
}

.discussion-link-result .result-chip.muted {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-default);
  color: var(--text-secondary);
  font-weight: 500;
}

@media (max-width: 900px) {
  .discussion-link-grid {
    grid-template-columns: 1fr;
  }
}

[data-theme="light"] .discussion-link-card {
  background: linear-gradient(180deg, rgba(27, 107, 138, 0.06), #fff);
  border-color: rgba(27, 107, 138, 0.2);
}

[data-theme="light"] .discussion-channel-job {
  background: var(--bg-secondary);
}

.threads-header {
  margin-bottom: var(--space-md);
}

.threads-header h2 {
  margin-bottom: var(--space-md);
}

.badge {
  background: var(--accent-dim);
  color: var(--text-primary);
  border: 1px solid var(--border-accent);
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 100px;
  font-weight: 600;
  vertical-align: middle;
  letter-spacing: 0.02em;
}

.threads-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.search-input {
  flex: 1;
  min-width: 150px;
}

.threads-filters select {
  width: auto;
  min-width: 140px;
}

.threads-list {
  max-height: 600px;
  overflow-y: auto;
}

/* ─── THREAD ITEM CARDS ───────────────────────────────── */
.thread-item {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.thread-item:hover {
  background: var(--bg-hover);
}

.thread-item.active {
  background: var(--bg-active);
  border-left: 3px solid var(--accent-blue);
  padding-left: calc(var(--space-md) - 3px);
}

.thread-item.excluded {
  opacity: 0.5;
}

.thread-item.keyboard-focused {
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}

.thread-title-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  margin-bottom: 4px;
}

.thread-title {
  font-weight: 600;
  font-size: 0.88rem;
  word-break: break-word;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.thread-root-sender {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-blue);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.thread-root-sender::before {
  content: '👤';
  font-size: 0.68rem;
}

.thread-snippet {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
  word-break: break-word;
}

.thread-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-md);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.thread-meta span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.thread-duration {
  font-size: 0.68rem;
  color: var(--accent-purple);
  font-weight: 500;
}

.mode-badge {
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  margin-top: 2px;
}

.mode-badge.reply_chain {
  background: var(--accent-dim);
  color: var(--accent-blue);
  border: 1px solid var(--border-accent);
  border-radius: 100px;
}

.mode-badge.orphan {
  background: rgba(251, 191, 36, 0.08);
  color: var(--accent-orange);
  border: 1px solid rgba(251, 191, 36, 0.15);
  border-radius: 100px;
}

.mode-badge.conversation {
  background: rgba(6, 182, 212, 0.08);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.15);
  border-radius: 100px;
}

.mode-badge.topic {
  background: rgba(16, 185, 129, 0.08);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.15);
  border-radius: 100px;
}

.threads-list-footer {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ─── DENSITY TOGGLE ───────────────────────────────────── */
.density-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 2px;
  border: 1px solid var(--border-muted);
}

.density-btn {
  background: none;
  border: none;
  padding: 4px 6px;
  border-radius: 3px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

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

.density-btn.active {
  background: var(--bg-active);
  color: var(--accent-blue);
}

/* ─── COMPACT MODE ─────────────────────────────────────── */
.threads-list.compact .thread-item {
  padding: var(--space-sm) var(--space-md);
}

.threads-list.compact .thread-root-sender {
  display: none;
}

.threads-list.compact .thread-snippet {
  display: none;
}

.threads-list.compact .thread-title {
  font-size: 0.82rem;
  -webkit-line-clamp: 1;
}

.threads-list.compact .thread-title-row {
  margin-bottom: 2px;
}

.threads-list.compact .thread-meta {
  font-size: 0.68rem;
  gap: var(--space-sm);
}

.threads-list.compact .thread-duration {
  display: none;
}

.threads-list.compact .mode-badge {
  font-size: 0.55rem;
  padding: 0px 4px;
}

/* ─── ADMIN FILTER BAR ─────────────────────────────────── */
.admin-filter-bar {
  margin-bottom: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-muted);
}

.admin-filter-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.admin-filter-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.admin-filter-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.admin-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.admin-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 4px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.admin-pill:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.admin-pill.active {
  background: var(--accent-dim);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  font-weight: 500;
}

.admin-pill .pill-count {
  font-size: 0.68rem;
  background: var(--bg-active);
  padding: 1px 5px;
  border-radius: 8px;
  color: var(--text-muted);
}

.admin-pill.active .pill-count {
  background: rgba(45, 212, 168, 0.2);
  color: var(--accent-blue);
}

.admin-pill-clear {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 4px 10px;
  background: transparent;
  border: 1px dashed var(--border-default);
  border-radius: 999px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.admin-pill-clear:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* ─── THREAD PREVIEW PANEL ─────────────────────────────── */
.thread-preview-panel .section-card {
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.preview-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--text-muted);
  flex-direction: column;
  gap: var(--space-md);
}

.preview-placeholder .placeholder-icon {
  font-size: 2.5rem;
  opacity: 0.3;
}

.preview-placeholder p {
  font-size: 0.85rem;
}

/* ─── PREVIEW HEADER ───────────────────────────────────── */
.preview-header {
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-muted);
  margin-bottom: var(--space-md);
}

.preview-header h3 {
  font-size: 1.05rem;
  margin-bottom: var(--space-sm);
  word-break: break-word;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.preview-header-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm) var(--space-lg);
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.preview-header-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.preview-participants {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.participant-chip {
  font-size: 0.68rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 500;
  border: 1px solid var(--border-muted);
  transition: all var(--transition-fast);
}

.participant-chip:hover {
  background: rgba(45, 212, 168, 0.1);
  color: var(--accent-blue);
  border-color: rgba(45, 212, 168, 0.3);
}

.preview-date-range {
  font-size: 0.75rem;
  color: var(--accent-purple);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.preview-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

/* ─── ORIGINAL POST ────────────────────────────────────── */
.preview-messages {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 320px);
}

.preview-original-post {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-md);
  position: relative;
  overflow: hidden;
}

.preview-original-post::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
}

.op-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-blue);
  padding: 2px 8px;
  background: rgba(45, 212, 168, 0.12);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

.preview-original-post .preview-msg-header {
  margin-bottom: var(--space-sm);
}

.preview-original-post .preview-msg-sender {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.preview-original-post .preview-msg-text {
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.7;
}

/* ─── REPLY MESSAGES ───────────────────────────────────── */
.preview-reply {
  padding: var(--space-md) 0 var(--space-md) var(--space-md);
  border-left: 2px solid var(--border-muted);
  margin-left: 10px;
  transition: border-color var(--transition-fast);
}

.preview-reply:hover {
  border-left-color: var(--accent-blue);
}

.preview-reply + .preview-reply {
  border-top: 1px solid var(--border-muted);
}

.preview-message {
  /* base — overridden by .preview-original-post and .preview-reply */
}

.preview-msg-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-xs);
  gap: var(--space-sm);
}

.preview-msg-sender {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent-cyan);
}

.preview-msg-time {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.preview-msg-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── REPLY CONTEXT BLOCK ──────────────────────────────── */
.preview-msg-reply-context {
  font-size: 0.75rem;
  margin-bottom: var(--space-sm);
  padding: 6px 10px;
  background: var(--bg-primary);
  border-left: 3px solid var(--accent-purple);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reply-sender {
  font-weight: 600;
  color: var(--accent-purple);
  font-size: 0.72rem;
}

.reply-snippet {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── MEDIA ITEMS ──────────────────────────────────────── */
.preview-msg-media {
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  border: 1px solid var(--border-muted);
}

.media-type-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.media-info {
  flex: 1;
  min-width: 0;
}

.media-filename {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-status {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.media-missing {
  color: var(--accent-orange);
  font-size: 0.7rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ─── LOAD MORE BUTTON ─────────────────────────────────── */
.preview-more {
  padding: var(--space-md);
  text-align: center;
}

.btn-load-more {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-load-more:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

/* ─── MERGE MODAL ──────────────────────────────────────── */
.merge-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.merge-modal {
  background: rgba(21, 21, 24, 0.95);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 520px;
  max-width: 94vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.merge-modal-header {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.merge-modal-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}

.merge-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.merge-modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.merge-modal-search {
  padding: var(--space-md) var(--space-xl);
  border-bottom: 1px solid var(--border-muted);
}

.merge-modal-search input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: var(--space-sm) var(--space-md);
}

.merge-modal-search input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(45, 212, 168, 0.15);
}

.merge-modal-list {
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
  padding: var(--space-sm) 0;
}

.merge-thread-item {
  padding: var(--space-sm) var(--space-xl);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-left: 3px solid transparent;
}

.merge-thread-item:hover {
  background: var(--bg-hover);
}

.merge-thread-item.selected {
  background: var(--bg-active);
  border-left-color: var(--accent-blue);
}

.merge-thread-title {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.merge-thread-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  gap: var(--space-sm);
}

.merge-thread-snippet {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.merge-modal-footer {
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
}

.merge-selected-info {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.merge-modal-empty {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ─── EXPORT SCREEN ────────────────────────────────────── */
.export-formats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.export-format-hint {
  font-size: 0.85rem;
  color: var(--status-warning);
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease, margin 0.3s ease;
  margin: 0;
}

.export-format-hint.visible {
  opacity: 1;
  max-height: 40px;
  margin-bottom: var(--space-md);
}

.format-option {
  cursor: pointer;
}

.format-option input[type="checkbox"] {
  display: none;
}

.format-card {
  background: var(--bg-tertiary);
  border: 2px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  transition: all var(--transition-fast);
}

.format-option input:checked + .format-card {
  border-color: var(--accent-blue);
  background: var(--accent-dim);
}

.format-option:hover .format-card {
  border-color: var(--text-muted);
}

.format-option.disabled .format-card {
  opacity: 0.4;
  cursor: not-allowed;
}

.format-icon {
  display: flex;
  justify-content: center;
  color: var(--brand-green);
  margin-bottom: var(--space-sm);
}

[data-theme="light"] .format-icon {
  color: #0f766e;
}

.format-name {
  display: block;
  font-weight: 600;
  margin-bottom: 2px;
}

.format-desc {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.export-scope {
  display: flex;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.export-actions-bar {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.download-card {
  text-align: center;
  padding: var(--space-2xl);
}

.download-icon {
  display: flex;
  justify-content: center;
  color: var(--status-success);
  margin-bottom: var(--space-md);
}

.download-card h3 {
  font-size: 1.3rem;
  margin-bottom: var(--space-sm);
  color: var(--accent-green);
}

.download-card p {
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
}

/* ─── PREVIOUS JOBS ────────────────────────────────────── */
.previous-jobs {
  margin-top: var(--space-xl);
}

.previous-jobs h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

/* ─── PROJECTS PANEL (PROJECTS_ENABLED — dark by default) ── */
.projects-panel {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border-muted);
}

.projects-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xs);
}

.projects-panel-head h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.projects-panel-desc {
  margin: 0 0 var(--space-md);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.clients-panel {
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm, 4px);
  background: var(--surface-subtle, transparent);
}

.clients-panel-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-2xs, 2px);
}

.clients-panel-head h4 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 600;
}

.clients-coming-soon {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
}

.clients-panel-desc {
  margin: 0 0 var(--space-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.clients-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-sm);
  min-height: 0;
}

.client-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm, 4px);
  background: transparent;
}

.clients-create-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
}

.clients-create-row input {
  flex: 1 1 10rem;
  min-width: 8rem;
  font-size: 0.85rem;
}

.projects-next {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin: 0 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-muted);
  background: var(--bg-elevated, rgba(37, 84, 230, 0.06));
}

.projects-next-explanation {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.45;
  flex: 1;
}

.projects-sticky-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-elevated, var(--surface-2, transparent));
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
}

.projects-sticky-banner[hidden],
.projects-sticky-banner.hidden {
  display: none;
}

.projects-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.projects-empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.projects-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.project-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-muted);
}

.project-row:last-child {
  border-bottom: none;
}

.project-row-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.project-row-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.project-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
}

.project-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.project-settings-card {
  max-width: 32rem;
  max-height: min(90vh, 40rem);
  overflow: auto;
}

.project-settings-intro {
  margin: 0 0 var(--space-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.project-settings-honesty {
  margin: 0 0 var(--space-md);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: var(--bg-secondary, rgba(0, 0, 0, 0.04));
  border-radius: var(--radius-sm, 4px);
}

.project-settings-honesty-badge {
  display: inline-block;
  margin-right: 0.35rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border-muted, #ccc);
  border-radius: var(--radius-sm, 4px);
  vertical-align: middle;
}

.project-settings-next {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin: 0 0 var(--space-md);
  padding: var(--space-sm);
  border: 1px solid var(--border-muted, #ddd);
  border-radius: var(--radius-sm, 4px);
  background: var(--bg-secondary, rgba(0, 0, 0, 0.03));
}

.project-settings-next-explanation {
  margin: 0;
  flex: 1 1 12rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-primary);
}

.project-settings-section {
  margin: 0 0 var(--space-lg);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border-muted);
}

.project-settings-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.project-settings-section-title {
  margin: 0 0 0.15rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.project-settings-section-job {
  margin: 0 0 var(--space-sm);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.project-settings-section.is-next-focus {
  outline: 1px solid var(--accent-blue, #2563eb);
  outline-offset: 4px;
  border-radius: var(--radius-sm, 4px);
}

.project-settings-sources-block {
  margin-top: 0;
  padding-top: var(--space-sm);
}

.project-settings-sources-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xs);
}

.project-settings-sources-head h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.project-sources-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.project-source-row {
  padding: var(--space-xs) 0;
  border-bottom: 1px solid var(--border-muted);
}

.project-source-row:last-child {
  border-bottom: none;
}

.project-source-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.project-source-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.projects-success {
  font-size: 0.8rem;
  line-height: 1.4;
  margin: var(--space-sm) 0 0;
  color: var(--success, #067647);
}

.projects-empty,
.projects-error,
.projects-skip-warn {
  font-size: 0.8rem;
  line-height: 1.4;
  margin: var(--space-sm) 0 0;
}

.projects-empty p {
  margin: 0;
}

.projects-error {
  color: var(--danger, #b42318);
}

.projects-skip-warn {
  color: var(--text-secondary);
  padding: var(--space-sm);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}

/* ─── ADD SOURCE MODAL (SOURCES_ENABLED + PROJECTS_ENABLED) ── */
.source-add-card {
  max-width: 32rem;
}

.source-add-lead {
  margin: 0 0 var(--space-md);
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.source-adapter-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.source-adapter-choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  width: 100%;
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated, transparent);
  color: inherit;
  cursor: pointer;
}

.source-adapter-choice:hover:not(:disabled),
.source-adapter-choice:focus-visible:not(:disabled) {
  border-color: var(--accent, var(--text-secondary));
  outline: none;
}

.source-adapter-choice.is-placeholder,
.source-adapter-choice:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.source-adapter-choice-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.source-adapter-choice-body {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.source-adapter-choice-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.source-add-loading,
.source-add-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.source-add-zip-step {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.source-add-upload-zone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  border: 1px dashed var(--border-muted);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary, transparent);
}

.source-add-upload-zone.is-dragover {
  border-color: var(--accent, var(--text-secondary));
}

.source-add-upload-zone.is-ready {
  border-style: solid;
  border-color: var(--accent, var(--text-secondary));
}

.source-add-upload-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.source-add-upload-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  min-height: 1.2em;
}

.source-add-upload-status.is-ok {
  color: var(--text-primary);
}

.source-add-upload-status.is-err {
  color: var(--danger, #b33);
}

.project-create-step-label {
  margin: 0 0 0.15rem;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.project-create-step.hidden,
.project-create-step[hidden] {
  display: none;
}

.project-guided-lead {
  margin: 0 0 var(--space-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.project-guided-summary {
  margin: 0 0 var(--space-sm);
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.project-create-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.project-create-actions .hidden,
.project-create-actions [hidden] {
  display: none !important;
}

.project-create-card .muted {
  font-weight: 400;
  color: var(--text-muted);
}

.library-hint {
  margin: 0 0 var(--space-md);
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.ready-next-steps {
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.ready-next-steps h3 {
  margin: 0 0 var(--space-xs);
  font-size: 1rem;
  color: var(--text-primary);
}

.ready-next-steps .section-desc {
  margin: 0 0 var(--space-md);
  font-size: 0.82rem;
}

.ready-next-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.import-destination-panel {
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.import-destination-title {
  margin: 0 0 var(--space-xs);
  font-size: 1.05rem;
}

.import-destination-desc {
  margin: 0 0 var(--space-md);
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.import-destination-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 28rem;
}

.import-destination-row select {
  width: 100%;
}

.import-destination-actions {
  margin-top: var(--space-sm);
}

.import-overview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md) var(--space-lg);
  margin: var(--space-lg) 0;
}

.import-overview-stats > div {
  margin: 0;
}

.import-overview-stats dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.import-overview-stats dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.import-overview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
}

.import-overview-secondary {
  margin-top: var(--space-lg);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-muted);
}

.job-item-actions .btn-sm {
  white-space: nowrap;
}

.library-empty {
  margin-top: var(--space-lg);
  padding: var(--space-lg);
  border: 1px dashed var(--border-muted);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.library-empty h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin: 0 0 var(--space-sm);
}

.library-empty p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.job-failure-panel {
  margin: 0 0 var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-muted);
  border-left: 3px solid var(--danger, #b45309);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
}

.job-failure-panel[hidden] {
  display: none !important;
}

.job-failure-panel h3 {
  margin: 0 0 var(--space-sm);
  font-size: 0.95rem;
  color: var(--text-primary);
}

.job-failure-message {
  margin: 0 0 var(--space-md);
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.job-failure-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.first-run-guide {
  margin: 0 0 var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.first-run-guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.first-run-guide-head h3 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.first-run-steps {
  margin: 0;
  padding-left: 1.15rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.55;
}

.first-run-steps li + li {
  margin-top: 0.35rem;
}

.auth-register-perk {
  margin: 0 0 var(--space-md);
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
}

.job-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.job-item-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.job-item:hover {
  background: var(--bg-hover);
}

.job-info { flex: 1; }

.job-info .job-name {
  font-weight: 500;
  font-size: 0.85rem;
}

.job-info .job-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.job-status {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  text-transform: uppercase;
}

.job-status.ready {
  background: rgba(63, 185, 80, 0.15);
  color: var(--accent-green);
}

.job-status.failed {
  background: rgba(248, 81, 73, 0.15);
  color: var(--accent-red);
}

.job-status.pending,
.job-status.parsing,
.job-status.threading {
  background: rgba(45, 212, 168, 0.15);
  color: var(--accent-blue);
}

/* ─── Rename Dialog ────────────────────────────────────── */
.rename-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.rename-dialog-content {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  width: 480px;
  max-width: 90vw;
}

.rename-dialog-content h3 {
  margin-bottom: var(--space-md);
}

.rename-dialog-content input {
  width: 100%;
  margin-bottom: var(--space-lg);
}

.rename-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ─── SCROLLBAR ────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 900px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-nav {
    overflow-x: auto;
    width: 100%;
  }

  .threads-layout {
    grid-template-columns: 1fr;
  }

  .thread-preview-panel .section-card {
    position: static;
    max-height: none;
  }
}

/* ─── ACCENT BUTTON ────────────────────────────────── */
.btn-accent {
  background: var(--accent-dim);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

.btn-accent:hover:not(:disabled) {
  background: rgba(45, 212, 168, 0.15);
  border-color: var(--accent-blue);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ─── GENERIC MODAL OVERLAY ────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: rgba(21, 21, 24, 0.95);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalSlideIn 0.3s ease-out;
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ─── FOLDER PICKER MODAL ──────────────────────────── */
.folder-picker {
  width: 680px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: rgba(21, 21, 24, 0.95);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalSlideIn 0.3s ease-out;
}

.picker-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 10px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  overflow-x: auto;
  white-space: nowrap;
  font-size: 0.8rem;
  scrollbar-width: thin;
}

.picker-breadcrumbs::-webkit-scrollbar { height: 4px; }
.picker-breadcrumbs::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 2px; }

.crumb {
  color: var(--text-link);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.crumb:hover {
  background: var(--bg-hover);
}

.crumb-sep {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.7rem;
}

.crumb-current {
  color: var(--text-primary);
  font-weight: 600;
  cursor: default;
}

.crumb-current:hover {
  background: transparent;
}

.picker-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border-muted);
  background: rgba(255,255,255,0.015);
}

.picker-sort-select {
  width: auto;
  min-width: 120px;
  padding: 4px 10px;
  font-size: 0.75rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  cursor: pointer;
}

.picker-sort-select:focus {
  outline: none;
  border-color: rgba(45, 212, 168, 0.5);
}

.picker-item-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.picker-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  min-height: 200px;
  max-height: 420px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

.picker-item:hover {
  background: var(--bg-hover);
}

.picker-item.selected {
  background: var(--bg-active);
  border-left-color: var(--accent-blue);
}

.picker-item.is-telegram-export {
  background: rgba(45, 212, 168, 0.04);
}

.picker-item.is-telegram-export:hover {
  background: rgba(45, 212, 168, 0.1);
}

.picker-item-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.picker-item-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-item-name .item-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-telegram {
  background: var(--accent-dim);
  color: var(--accent-blue);
  border: 1px solid var(--border-accent);
}

.badge-zip {
  background: #d2992225;
  color: var(--accent-orange);
  border: 1px solid #d2992240;
}

.picker-item-size {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.picker-item-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.75rem;
}

.picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border-default);
  background: var(--bg-secondary);
  gap: 12px;
}

.picker-selected {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.picker-selected.has-selection {
  color: var(--accent-blue);
}

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

.picker-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.picker-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.picker-loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Advanced Settings Panel ─────────── */
.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0;
  font-weight: 500;
  transition: color 0.2s;
}
.btn-link:hover {
  color: var(--accent-blue);
}

.input-sm {
  width: 80px;
  padding: 4px 8px;
  font-size: 0.82rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.setting-advanced {
  grid-column: 1 / -1;
}

/* ─── STORAGE PROVIDERS ────────────────────────────── */

.storage-list {
  margin-bottom: 16px;
}

.storage-empty p {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 12px 0;
}

.storage-provider-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: border-color var(--transition-fast);
}

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

.sp-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.sp-info {
  flex: 1;
  min-width: 0;
}

.sp-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.sp-type {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sp-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ─── MODAL CARD (new storage modal variant) ──────── */

.modal-card {
  background: rgba(21, 21, 24, 0.97);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 80px -12px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255,255,255,0.05);
  animation: modalSlideIn 0.3s ease-out;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-default);
}

/* ─── BUTTON VARIANTS ─────────────────────────────── */

.btn-xs {
  padding: 4px 10px;
  font-size: 0.72rem;
  border-radius: var(--radius-sm);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-danger {
  color: #ef4444;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

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

/* ─── FORM HELPERS ────────────────────────────────── */

.input-full {
  width: 100%;
}

.input-sm {
  width: 100px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* ─── EXPORT DESTINATION ──────────────────────────── */

.export-destination {
  margin: 20px 0;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}

.export-destination label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

/* ─── AI ANALYSIS ───────────────────────────────────── */

.ai-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.ai-preset-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all var(--transition-fast);
  color: var(--text-primary);
}

.ai-preset-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.ai-preset-icon {
  font-size: 1.5rem;
}

.ai-preset-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.ai-translate-opts {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
}

.ai-custom-prompt {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.ai-result-area {
  margin-top: 24px;
  border-top: 1px solid var(--border-default);
  padding-top: 20px;
}

.ai-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ai-result-content {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  font-size: 0.95rem;
  line-height: 1.6;
  max-height: 400px;
  overflow-y: auto;
}

.ai-result-content p {
  margin-top: 0;
  margin-bottom: 1em;
}

.ai-result-content p:last-child {
  margin-bottom: 0;
}

.ai-result-content ul, .ai-result-content ol {
  margin-top: 0;
  margin-bottom: 1em;
  padding-left: 24px;
}

.ai-result-content strong {
  color: var(--text-primary);
}

/* Loading Dots */
.ai-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  color: var(--text-muted);
}

.ai-loading-dots {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.ai-loading-dots span {
  width: 8px;
  height: 8px;
  background-color: var(--primary-color);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.ai-loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.ai-loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.ai-error {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-top: 20px;
  font-size: 0.9rem;
}

.ai-cached-results {
  margin-top: 24px;
  border-top: 1px solid var(--border-default);
  padding-top: 20px;
}

.ai-cached-results h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 12px 0;
}

.ai-cached-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ai-cached-item:hover {
  background: var(--bg-hover);
  border-color: var(--primary-color);
}

.ai-cached-preset {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
  text-transform: capitalize;
}

.ai-cached-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.ai-config-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.ai-config-status {
  font-size: 0.85rem;
  font-weight: 500;
}

/* ─── LIGHT THEME OVERRIDES ───────────────────────── */

[data-theme="light"] .modal-card {
  background: rgba(255, 255, 255, 0.98);
}

[data-theme="light"] .storage-provider-card {
  background: var(--bg-primary);
}

/* ─── UPLOAD ZONE ───────────────────────────────────── */

.upload-zone {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  transition: all 0.2s ease;
  background: var(--bg-secondary);
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-blue);
  background: rgba(45, 212, 168, 0.04);
}

.upload-zone.drag-over {
  box-shadow: 0 0 0 3px rgba(45, 212, 168, 0.12);
  transform: scale(1.01);
}

.upload-zone.uploading {
  border-style: solid;
  border-color: var(--accent-blue);
  cursor: default;
}

.upload-zone.upload-success {
  border-color: var(--accent-green);
  background: rgba(52, 211, 153, 0.04);
}

.upload-zone.upload-error {
  border-color: var(--color-danger);
  background: rgba(239, 68, 68, 0.04);
}

.upload-icon {
  margin-bottom: 1rem;
  opacity: 0.5;
  color: var(--text-secondary);
}

.upload-zone:hover .upload-icon,
.upload-zone.drag-over .upload-icon {
  opacity: 1;
  color: var(--accent-blue);
}

.upload-text {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.upload-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.upload-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1rem;
}

/* Upload Progress */
.upload-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.upload-filename {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}

.upload-percent {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-blue);
  font-family: 'JetBrains Mono', monospace;
}

.upload-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.upload-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

[data-theme="light"] .upload-zone {
  background: var(--bg-primary);
  border-color: var(--border-default);
}

[data-theme="light"] .upload-zone:hover,
[data-theme="light"] .upload-zone.drag-over {
  background: rgba(45, 212, 168, 0.06);
}

/* ─── AUTH BAR & MODAL ─────────────────────────────── */

.auth-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.auth-user-email {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-user-plan.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(45, 212, 168, 0.15);
  color: var(--accent-green);
  text-transform: capitalize;
}

.auth-modal-card {
  width: 100%;
  max-width: 420px;
}

.auth-modal-card .modal-body {
  padding: var(--space-lg) var(--space-lg) var(--space-xl);
}

.auth-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  padding: 3px;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

.auth-tabs .tab-btn {
  flex: 1;
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  border-radius: calc(var(--radius-md) - 2px);
}

.auth-tabs .tab-btn.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.auth-form .input-group {
  margin-bottom: var(--space-md);
}

.auth-form .input-group:last-of-type {
  margin-bottom: var(--space-lg);
}

.auth-form .input-group label {
  margin-bottom: var(--space-xs);
}

.auth-form .input-group input {
  font-family: var(--font-sans);
}

.auth-form .btn-full {
  width: 100%;
  margin-top: var(--space-md);
}

.auth-error {
  color: var(--accent-red, #f87171);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.auth-success {
  color: var(--accent-green, #2DD4A8);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.auth-helper {
  margin: 0.35rem 0 0;
}

.auth-helper-text {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.auth-unverified {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.auth-toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: min(520px, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg, 10px);
  border: 1px solid var(--border-default);
  background: var(--bg-elevated, var(--bg-secondary));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.auth-toast.is-error {
  border-color: rgba(248, 113, 113, 0.45);
}

.auth-toast-close {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.verify-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.75rem 1.25rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg, 10px);
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.1);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.verify-banner p {
  margin: 0;
}

.account-verify-panel {
  margin: 1rem 0 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid rgba(251, 191, 36, 0.3);
  background: rgba(251, 191, 36, 0.08);
  max-width: 520px;
}

.account-verify-panel p {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.account-danger-zone {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  max-width: 520px;
}

body.hosted-ingest .input-mode-tabs {
  display: none;
}

.field-error {
  color: var(--accent-red, #f87171);
  font-size: 0.78rem;
  margin: 0.35rem 0 0;
}

.input-group input.input-invalid {
  border-color: var(--accent-red, #f87171);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.25);
}

.auth-form .btn-full.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.85;
}

.auth-form .btn-full.is-loading .btn-label {
  visibility: hidden;
}

.btn-spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: auth-spin 0.7s linear infinite;
}

@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

.account-profile {
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--bg-input, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.account-profile-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.35rem 0;
  font-size: 0.875rem;
}

.account-label {
  color: var(--text-tertiary);
}

.account-value {
  color: var(--text-primary);
  font-weight: 500;
}

.account-subheading {
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
}

.account-password-form {
  max-width: 420px;
}

.account-tokens {
  margin-top: 1.75rem;
  max-width: 520px;
}

.api-token-once {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
  background: var(--bg-input, rgba(255, 255, 255, 0.04));
}

.api-token-value {
  display: block;
  margin: 0.5rem 0;
  padding: 0.5rem 0.65rem;
  word-break: break-all;
  font-size: 0.8rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}

.api-token-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.api-token-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
  font-size: 0.875rem;
}

.api-token-list .token-meta {
  color: var(--text-tertiary);
  font-size: 0.75rem;
}

.api-token-list .token-revoked {
  opacity: 0.55;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ─── BILLING & PLANS ──────────────────────────────── */

.auth-user-status.badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.auth-user-status.status-active {
  background: rgba(45, 212, 168, 0.15);
  color: #2DD4A8;
}

.auth-user-status.status-cancelled {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

.auth-user-status.status-trial {
  background: rgba(59, 164, 200, 0.15);
  color: #3BA4C8;
}

.billing-status-panel {
  margin-bottom: 1.5rem;
}

.billing-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--bg-input, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.billing-status-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.billing-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.billing-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.billing-usage {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.usage-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.usage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.usage-label {
  color: var(--text-secondary);
}

.usage-count {
  color: var(--text-primary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.usage-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-input, rgba(255, 255, 255, 0.06));
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #2DD4A8, #3BA4C8);
  transition: width 0.3s ease;
}

.usage-bar-fill.usage-warning {
  background: linear-gradient(90deg, #fbbf24, #f97316);
}

.usage-bar-fill.usage-full {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

.billing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

/* ─── Export credit badge (header) ─────────────────── */

.credit-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(45, 212, 168, 0.4);
  background: rgba(45, 212, 168, 0.12);
  color: var(--accent-green);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.credit-badge:hover {
  background: rgba(45, 212, 168, 0.22);
}

.credit-badge.credits-empty {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

/* ─── Credit ledger table ──────────────────────────── */

.billing-ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.billing-ledger th,
.billing-ledger td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle, rgba(128, 128, 128, 0.18));
}

.billing-ledger th {
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}

.billing-ledger td.ledger-credit {
  color: var(--accent-green);
  font-weight: 600;
}

.billing-ledger td.ledger-debit {
  color: #ef4444;
  font-weight: 600;
}

.billing-notice {
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.2);
}

.billing-plans-section {
  margin-top: 0.5rem;
}

.billing-period-toggle {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.billing-period-toggle .tab-btn {
  flex: 0 0 auto;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
}

.billing-plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.billing-loading {
  grid-column: 1 / -1;
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.plan-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
  background: var(--bg-input, rgba(255, 255, 255, 0.03));
  transition: border-color 0.2s, box-shadow 0.2s;
}

.plan-card:hover {
  border-color: rgba(45, 212, 168, 0.35);
}

.plan-card.plan-current {
  border-color: #2DD4A8;
  box-shadow: 0 0 0 1px rgba(45, 212, 168, 0.25);
}

.plan-card.plan-featured {
  border-color: rgba(59, 164, 200, 0.5);
}

.plan-current-badge {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: rgba(45, 212, 168, 0.15);
  color: #2DD4A8;
}

.plan-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.25rem;
  color: var(--text-primary);
}

.plan-price {
  font-size: 1.5rem;
  font-weight: 800;
  color: #2DD4A8;
  margin-bottom: 0.15rem;
}

.plan-price-sub {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: 0.85rem;
}

.plan-savings {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  color: #2DD4A8;
  background: rgba(45, 212, 168, 0.1);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.plan-features {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  flex: 1;
}

.plan-features li {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.25rem 0;
  padding-left: 1.1rem;
  position: relative;
}

.plan-features li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: #2DD4A8;
  font-size: 0.75rem;
}

.plan-card .btn {
  width: 100%;
  margin-top: auto;
}

.upgrade-modal-card {
  max-width: 420px;
}

.upgrade-modal-hint {
  font-size: 0.85rem;
  color: var(--text-tertiary);
  margin-top: 0.5rem;
}

.upgrade-modal-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

/* ─── STATS CHARTS & ENGAGEMENT (D2, C7) ─────────────── */
.stats-charts-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.chart-card {
  padding: var(--space-md);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.chart-card h3 {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin: 0 0 var(--space-sm);
}

.emoji-heatmap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-chip {
  padding: 4px 8px;
  background: var(--accent-dim);
  border-radius: var(--radius-md);
}

.message-search-bar {
  margin-bottom: var(--space-md);
}

.message-search-results {
  margin-top: var(--space-sm);
  max-height: 200px;
  overflow-y: auto;
}

.search-result-item {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border-default);
}

/* ─── UI cleanup: chrome, focus, settings ─────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 2000;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--brand-green);
  color: #042f2e;
  font-weight: 600;
}

.skip-link:focus {
  top: 12px;
}

.wordmark-thread { color: var(--brand-green); }
.wordmark-clarity { color: var(--brand-blue); }

[data-theme="light"] .wordmark-thread { color: #0f766e; }
[data-theme="light"] .wordmark-clarity { color: #0e7490; }

.header-icon img {
  height: 36px;
  width: auto;
  display: block;
}

.nav-btn {
  min-height: 40px;
}

.user-menu-wrap {
  position: relative;
}

.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 8px 4px 4px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.user-menu-trigger:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-dim);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.user-menu-caret {
  color: var(--text-muted);
}

.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 200px;
  padding: 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  z-index: 120;
}

.user-menu-meta:not(:has(.badge:not(.hidden))) {
  display: none;
}

.user-menu-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 8px 10px;
  border-bottom: 1px solid var(--border-muted);
  margin-bottom: 4px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.user-menu-item:hover {
  background: var(--bg-hover);
}

.user-menu-item-danger {
  color: var(--status-error);
}

.input-mode-tabs .tab-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 76px;
  padding: 12px 14px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
  text-align: left;
}

.input-mode-tabs .tab-btn .tab-label {
  font-weight: 600;
  color: var(--text-primary);
}

.input-mode-tabs .tab-icon {
  color: var(--text-secondary);
}

.method-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.input-mode-tabs .tab-btn.active,
[data-theme="light"] .input-mode-tabs .tab-btn.active {
  background: var(--accent-dim);
  border-color: var(--brand-green);
  color: var(--text-primary);
  box-shadow: none;
}

.input-mode-tabs .tab-btn.active .tab-icon {
  color: var(--brand-green);
}

[data-theme="light"] .input-mode-tabs .tab-btn.active .tab-icon {
  color: #0f766e;
}

.settings-toolbar {
  margin-bottom: var(--space-md);
}

.settings-subnav {
  display: flex;
  gap: 4px;
  padding: 4px;
  width: fit-content;
  max-width: 100%;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
}

.settings-tab {
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.settings-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.settings-context {
  margin-bottom: var(--space-md);
}

.disclosure-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.disclosure-toggle::before {
  content: '';
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 5px solid currentColor;
  transition: transform var(--transition-fast);
}

.disclosure-toggle[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

.stat-k {
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-chip strong {
  font-variant-numeric: tabular-nums;
}

.export-options {
  display: grid;
  gap: 10px;
  margin: var(--space-md) 0 var(--space-lg);
}

.picker-item-icon {
  min-width: 2.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.sp-icon {
  min-width: 3.2rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.tab-btn:focus-visible,
.nav-btn:focus-visible,
.settings-tab:focus-visible {
  outline: 2px solid var(--brand-green);
  outline-offset: 2px;
}

.btn {
  min-height: 40px;
}

.btn-xs {
  min-height: 32px;
}

@media (max-width: 720px) {
  .input-mode-tabs {
    grid-template-columns: 1fr;
  }

  .auth-user-email,
  .header-subtitle {
    display: none;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
