:root {
  /* Premium dark palette with cyan/azure accent */
  --bg: #0c1017;
  --bg-strong: #090c12;
  --sidebar: #0f1420;
  --surface: #131a28;
  --surface-soft: #182032;
  --surface-border: rgba(255, 255, 255, 0.08);
  --text: #e9efff;
  --muted: #9aa6c4;
  --accent: #5fc8ff;
  --accent-strong: #2ea8ff;
  --accent-soft: rgba(94, 200, 255, 0.14);
  --success: #5ad089;
  --warning: #f5c26b;
  --danger: #ff6b6b;
  --font: 'Inter', 'Sora', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --transition: all 0.18s ease;
}

/* Ensure elements with the hidden attribute are actually hidden,
   even if component styles set display values. */
[hidden] { display: none !important; }

/* Light theme variable overrides */
body[data-theme="light"] {
  /* Professional light palette matching indigo accent */
  --bg: #f6f7fb;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f2f4f8;
  --surface-border: #e4e8f0;
  --text: #0a0d14;
  --muted: #4b5563;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.10);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
}

/* Background for light theme */
body.theme-chatgpt[data-theme="light"] {
  background: radial-gradient(circle at top, #ffffff 0%, var(--bg) 55%);
}

/* Logos that were forced white should not invert in light theme */
body[data-theme="light"] .logo-white { filter: none; }

* {
  box-sizing: border-box;
}

body.theme-chatgpt {
  margin: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(94, 200, 255, 0.14), transparent 35%),
    radial-gradient(circle at 82% 12%, rgba(46, 168, 255, 0.16), transparent 32%),
    linear-gradient(145deg, var(--bg-strong) 0%, #0d1421 45%, #0f1625 100%);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

a {
  color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0));
}

/* Auth view: collapse to single column and hide sidebar/header to avoid blank panel */
body[data-view="auth"] .app-shell { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body[data-view="auth"] #mainArea { grid-column: 1; grid-row: 1; }
body[data-view="auth"] #leftSidebar { display: none !important; }
body[data-view="auth"] #topbar { display: none !important; }

.sidebar {
  background: linear-gradient(170deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.0));
  border-right: 1px solid var(--surface-border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  gap: 24px;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.02), 12px 0 35px rgba(0, 0, 0, 0.28);
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Top row inside sidebar header: brand on left, theme icon on right */
.sidebar-header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Icon-only button for theme toggle */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 32px; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; display: block; }

.brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 16px;
  background: linear-gradient(130deg, #b0c8ff 0%, #5fc8ff 40%, #2ea8ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-section h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer {
  margin-top: auto;
}

.mini-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 16px;
  font-size: 13px;
  color: var(--muted);
}

.mini-card-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.nav-btn {
  text-align: left;
  background: transparent;
  color: var(--text);
  border-color: transparent;
}

.nav-btn {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(1px);
}

.nav-btn.active {
  background: var(--accent-soft);
  border-color: rgba(94, 200, 255, 0.35);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 8px 26px rgba(46, 168, 255, 0.18);
}

.primary-btn,
.ghost-btn,
.nav-btn {
  font-family: inherit;
}

.primary-btn {
  background: linear-gradient(130deg, var(--accent-strong), var(--accent));
  color: #07101f;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 28px rgba(46, 168, 255, 0.28);
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 34px rgba(46, 168, 255, 0.32); }
.primary-btn:active { transform: translateY(0); box-shadow: 0 8px 20px rgba(46, 168, 255, 0.28); }

.ghost-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--surface-border);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  transition: var(--transition);
}
.ghost-btn:hover { border-color: rgba(94, 200, 255, 0.35); color: var(--text); box-shadow: 0 10px 26px rgba(0,0,0,0.16); }

/* Files table formatting */
.files-table { width: 100%; border-collapse: collapse; }
.files-table th, .files-table td { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,0.08); text-align: left; }
.files-table th { font-weight: 600; color: var(--muted); }
.files-table td .row { gap: 6px; }

/* Pricing page */
.plans { display: grid; grid-template-columns: repeat(4, minmax(200px, 1fr)); gap: 20px; margin: 20px 0; }
@media (max-width: 1024px) {
  .plans { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
}
.plan-card { background: var(--surface); border: 1px solid var(--surface-border); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 16px; transition: var(--transition); }
.plan-card:hover { border-color: rgba(79, 70, 229, 0.3); box-shadow: 0 8px 24px rgba(79, 70, 229, 0.12); }
.plan-card h3 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.plan-price { font-size: 32px; font-weight: 700; color: var(--accent); margin: 8px 0; }
.plan-price span { font-size: 14px; color: var(--muted); font-weight: 400; }
.plan-card ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 14px; line-height: 1.8; }
.plan-card button { width: 100%; }

/* Modal styles */
#modal[hidden] { display: none; }
#modal { position: fixed; inset: 0; z-index: 50; }
#modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
#modal-content {
  position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  width: min(1600px, calc(100% - 48px));
  max-height: 98vh; height: 90vh;
  display: flex; flex-direction: column; /* header | body */
  background: var(--surface); border: 1px solid var(--surface-border); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.modal-header {
  flex: 0 0 auto;
  position: sticky; top: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: rgba(11,14,21,0.96); border-bottom: 1px solid #1e2331; z-index: 1;
}
#modal-title { margin-right: 12px; }
.modal-controls-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.modal-controls-row select.pill-select { max-width: 180px; }
#modal-body {
  flex: 1 1 auto; min-height: 0; /* allow it to shrink below content */
  padding: 12px 14px; overflow: auto;
  display: flex; flex-direction: column;
}

#modal.modal--anchor #modal-content {
  width: 360px;
  max-width: calc(100% - 24px);
  height: auto;
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.4);
}
#modal.modal--anchor #modal-backdrop {
  background: transparent;
}

.invoice-gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.invoice-gallery-header p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.invoice-help {
  font-size: 12px;
  color: var(--muted);
}
.invoice-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  width: 100%;
}
.invoice-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.invoice-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.invoice-total-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.invoice-facts-simple {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.invoice-facts-simple .fact-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.invoice-facts-simple .fact-value {
  display: block;
  font-weight: 600;
  color: var(--text);
}
.invoice-card-actions {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.invoice-card-actions .primary-btn {
  margin: 0 auto;
  min-width: 140px;
}
.invoice-vendor {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.invoice-code {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.invoice-total {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}
.invoice-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
}
.invoice-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.invoice-fact .label { color: var(--muted); font-size: 12px; }
.invoice-fact .value { font-weight: 500; }
.invoice-note {
  font-size: 12px;
  color: var(--muted);
}
.invoice-note pre {
  margin: 6px 0 0;
  font-family: inherit;
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 8px;
  color: var(--text);
  white-space: pre-line;
}
.invoice-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.invoice-pill {
  border: 1px dashed var(--surface-border);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.invoice-modal {
  display: flex;
  flex-direction: row;
  gap: 16px;
  height: 100%;
}
.invoice-modal-preview {
  flex: 1 1 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.invoice-preview-meta {
  background: var(--surface-soft);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 14px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.invoice-preview-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.invoice-preview-row span:last-child {
  font-weight: 600;
}
.invoice-pdf-frame {
  flex: 1 1 auto;
  width: 100%;
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  background: #fff;
}
.invoice-preview-actions {
  display: flex;
  justify-content: flex-end;
}
.invoice-modal-loading {
  padding: 40px;
  text-align: center;
}

@media (max-width: 900px) {
  .invoice-modal {
    flex-direction: column;
    height: auto;
  }
  .invoice-modal-preview {
    min-height: 320px;
  }
  .invoice-facts {
    grid-template-columns: 1fr;
  }
}

/* Chart container inside modal fills remaining height */
.chart-modal-box { flex: 1 1 auto; min-height: 0; display: flex; }
.chart-modal-box > canvas { flex: 1 1 auto; width: 100% !important; height: 100% !important; display: block; }

.portfolio-insights-body { display:flex; flex-direction:column; gap:16px; }
.portfolio-chart-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(260px,1fr)); gap:16px; }
.portfolio-chart-grid canvas { width:100% !important; height:220px !important; display:block; }

/* Taller box for Visualize > Customize card */
.viz-controls {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  overflow: visible;
}
.viz-controls .row { margin-bottom: 12px; }

/* Hide scrollbars inside the Customize box but keep scrolling functional */
.viz-controls { -ms-overflow-style: none; scrollbar-width: none; }
.viz-controls::-webkit-scrollbar { display: none; }


.ghost-btn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.08);
  transition: var(--transition);
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.15);
}

.ghost-btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.ghost-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
}

.primary-btn {
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  border-color: rgba(79, 70, 229, 0.7);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
  transition: var(--transition);
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.35);
  transform: translateY(-2px);
}

.primary-btn:active:not(:disabled) {
  filter: brightness(0.95);
  transform: translateY(0);
}

.primary-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.3), 0 8px 20px rgba(79, 70, 229, 0.25);
}

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

.small {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
}

.main-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  padding: 28px 40px 20px;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.main-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
}

.main-header p {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 540px;
  line-height: 1.4;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.view {
  flex: 1;
  overflow-y: auto;
  padding: 24px 40px 40px;
}

.view-chat {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

/* In conversation view, keep composer fixed and only stream scrolls */
.view-chat {
  overflow: hidden;
}
.view-chat .chat-column { min-height: 0; }
.view-chat .chat-layout { height: 100%; }
.view-chat .chat-stream { overflow-y: auto; }

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 32px;
  flex: 1;
  min-height: 0;
}

/* Conversation page: full-width single column */
.view-chat .chat-layout {
  grid-template-columns: minmax(0, 1fr);
}

.chat-column {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 8px;
}

.conversation-log {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.conversation-log:empty {
  display: none;
}

.insights-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  padding-right: 8px;
}

.message {
  background: linear-gradient(140deg, rgba(28, 28, 40, 0.95), rgba(20, 20, 30, 0.85));
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  padding: 20px 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.message .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(16, 163, 127, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.message .message-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 15px;
  line-height: 1.6;
}

.message.user {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.message.user .avatar {
  background: rgba(255, 255, 255, 0.12);
}

.message.assistant .avatar {
  background: rgba(16, 163, 127, 0.16);
}

.message-body p {
  margin: 0;
}

.message-body .muted {
  color: var(--muted);
  font-size: 13px;
}

.message-title {
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 8px;
}

.message-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

.plan {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.sources {
  margin-top: 8px;
  font-size: 12px;
}

.block-group {
  margin-top: 20px;
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--surface-border);
  padding: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

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

.block-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.intro-card {
  background: linear-gradient(140deg, rgba(30, 30, 48, 0.95), rgba(16, 16, 28, 0.92));
}

.intro-card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.intro-tips {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.code-block {
  white-space: pre-wrap;
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  background: var(--surface-soft);
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  padding: 14px;
  max-height: 360px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
}

.table-shell {
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  overflow: auto;
  max-height: 320px;
}

.empty-state {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.error {
  color: var(--danger);
}

table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  text-align: left;
}

th {
  font-weight: 600;
  background: rgba(255, 255, 255, 0.02);
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
}

.log {
  margin-top: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--surface-border);
  padding: 12px;
  border-radius: 14px;
  min-height: 160px;
  max-height: 260px;
  overflow-y: auto;
  color: var(--muted);
}

/* Upload progress list */
.progress-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.progress-item { background: rgba(255,255,255,0.04); border: 1px solid var(--surface-border); border-radius: 10px; padding: 8px 10px; }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-bar { position: relative; height: 8px; background: rgba(255,255,255,0.08); border-radius: 999px; overflow: hidden; }
.progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--accent); border-radius: 999px; transition: width 0.15s ease; }
.progress-status { font-size: 12px; color: var(--muted); margin-top: 6px; }

.status-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
  color: var(--muted);
}

.badge.optimized {
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.4);
}

.badge.converting {
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border-color: rgba(251, 191, 36, 0.4);
}

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

.insight-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.insight-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.insight-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.small-text {
  font-size: 12px;
}

.dataset-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
}

.ds-item {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ds-item strong {
  font-size: 14px;
}

.spin {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: rotate 0.8s linear infinite;
}

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

.typing-dots {
  display: inline-flex;
  gap: 6px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.composer {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.composer .chips {
  margin-top: 8px;
  max-width: 840px;
  margin-left: auto;
  margin-right: auto;
}

/* Hide suggestion chips below the query box */
#suggestions { display: none; }

.composer-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  /* Center the query box and limit max width */
  justify-content: center;
}

.input-shell {
  /* Keep responsive but cap width to align with output boxes */
  flex: 1 1 840px;
  max-width: 840px;
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px;
  gap: 8px;
}

.input-shell input[type="text"] {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  padding: 10px;
  outline: none;
}

select,
input[type="number"],
input[type="file"] {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

input[type="number"] {
  width: 100px;
}

.pill-select {
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-border);
  padding: 8px 12px;
  min-width: 160px;
}

/* Ensure dropdown options render dark themed as well */
.pill-select option {
  background: var(--surface);
  color: var(--text);
}

.pill-select:focus {
  outline: none;
  border-color: rgba(16, 163, 127, 0.6);
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.opt {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.opt input {
  accent-color: var(--accent);
}

.chips,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  background: rgba(16, 163, 127, 0.18);
  border-color: rgba(16, 163, 127, 0.4);
  color: var(--text);
}

.chip.is-active {
  background: rgba(16, 163, 127, 0.25);
  border-color: rgba(16, 163, 127, 0.6);
  color: var(--text);
}

.panel {
  background: linear-gradient(160deg, rgba(255,255,255,0.02), rgba(255,255,255,0.006));
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(8px);
}

.doc-type-filter {
  flex: 1 1 320px;
  min-width: 240px;
}

.doc-type-filter label {
  display: block;
  margin-bottom: 6px;
}

.doc-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  text-transform: capitalize;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.panel h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.panel-sub {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 18px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.dash-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dash-card .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dash-card .code {
  font-family: 'JetBrains Mono', monospace;
}

.prompt-list .q-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 14px;
}

.prompt-list .q-item button {
  flex-shrink: 0;
}

.files-list .file-row {
  width: 100%;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 12px 0;
}

.files-list strong {
  font-size: 14px;
}

.files-list .muted {
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

/* Enhanced hero section for SaaS */
.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 0%, var(--muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.hero-sub {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto;
}

/* Enhanced form styling for auth */
.panel-sub h3 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--text);
}

.panel-sub .row {
  flex-direction: column;
  gap: 14px;
}

.panel-sub input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 15px;
  transition: var(--transition);
}

.panel-sub input::placeholder {
  color: var(--muted);
}

.panel-sub input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(94, 200, 255, 0.2);
}

.panel-sub .primary-btn {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
}

.panel-sub .muted {
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

/* Enhanced link styling */
a {
  transition: var(--transition);
}

a:hover {
  filter: brightness(1.15);
}

/* Enhanced input shell for better chat experience */
.input-shell {
  box-shadow: 0 4px 20px rgba(94, 200, 255, 0.15);
}

.input-shell:focus-within {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(94, 200, 255, 0.25);
}

/* Badge improvements */
.badge {
  transition: var(--transition);
  cursor: default;
}

/* Status badges with improved colors */
.badge.success {
  color: var(--success);
  background: rgba(90, 208, 137, 0.12);
  border-color: rgba(90, 208, 137, 0.4);
}

.badge.warning {
  color: var(--warning);
  background: rgba(245, 194, 107, 0.12);
  border-color: rgba(245, 194, 107, 0.4);
}

.badge.error {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.4);
}

/* Card hover effects */
.invoice-card {
  transition: var(--transition);
}

.invoice-card:hover {
  border-color: var(--accent-soft);
  box-shadow: 0 12px 32px rgba(46, 168, 255, 0.18), 0 10px 30px rgba(0, 0, 0, 0.25);
}

.mini-card {
  transition: var(--transition);
}

.mini-card:hover {
  border-color: rgba(94, 200, 255, 0.3);
  box-shadow: 0 4px 12px rgba(94, 200, 255, 0.12);
}

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* Review filters layout */
.review-filters .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}
.review-filters select,
.review-filters input[type="date"] {
  width: 100%;
}
.review-filters .review-select {
  background: linear-gradient(135deg, rgba(26, 39, 68, 0.95), rgba(12, 18, 30, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-primary, #f5f7ff);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}
.review-filters .review-select option {
  background: rgba(6, 10, 20, 0.95);
  color: #f5f7ff;
}
.review-filters .filter-date-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  width: 100%;
  align-items: flex-start;
}
.review-filters .filter-date-stack .filter-column {
  flex: 1 1 240px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.review-filters .filter-date-stack .primary-btn {
  align-self: stretch;
  width: 100%;
  margin-top: 4px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}
.review-filters .date-input {
  width: clamp(160px, 24vw, 220px) !important;
  max-width: 220px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, rgba(26, 39, 68, 0.9), rgba(12, 18, 30, 0.9));
  color: var(--text-primary, #f5f7ff);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.review-filters .date-input::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.8;
}
.review-filters .date-input:focus {
  outline: none;
  border-color: rgba(94, 200, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(94, 200, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.options-row {
  margin-top: 12px;
}

.stack-on-mobile {
  align-items: stretch;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
  }
  .chat-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    gap: 12px;
  }
  .sidebar-header,
  .sidebar-section,
  .sidebar-footer {
    flex: 1;
  }
  .main-header {
    padding: 24px;
  }
  .view {
    padding: 24px;
  }
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .insights-column {
    order: -1;
    padding-right: 0;
    overflow: visible;
  }
  .split {
    grid-template-columns: 1fr;
  }
  .composer-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .input-shell {
    width: 100%;
    max-width: 100%;
    flex-basis: auto;
  }
}

@media (max-width: 640px) {
  .panel {
    padding: 20px;
  }
  .message {
    padding: 18px;
  }
  .message .avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
  .main-header h1 {
    font-size: 24px;
  }
}
/* Viewport-locked grid wrappers */
html, body { height: 100%; }
#appRoot {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr; /* left | main (full width) */
  grid-template-rows: 1fr;          /* content only (no topbar) */
  overflow: hidden;                 /* lock page scroll */
}
/* Ensure auth view truly collapses the #appRoot grid to a single column */
body[data-view="auth"] #appRoot {
  grid-template-columns: 1fr !important;
  grid-template-rows: 1fr !important;
}
#topbar {
  grid-column: 1 / -1; grid-row: 1;
  position: sticky; top: 0; z-index: 2;
  min-height: 64px; /* ensure sufficient header height */
}
#leftSidebar { grid-column: 1; grid-row: 1; overflow: auto; border-right: 1px solid rgba(255,255,255,0.06); }
#rightSidebar { display: none; }
#mainArea {
  grid-column: 2; grid-row: 1;
  display: grid; grid-template-rows: 1fr auto; /* output | composer */
  overflow: hidden; background: var(--bg);
}
#quota-banner { grid-row: 1; grid-column: 1; display: none; padding: 8px 12px; background: rgba(251, 191, 36, 0.14); border-bottom: 1px solid rgba(251,191,36,0.35); color: #fbbf24; font-size: 13px; }
#quota-banner.danger { background: rgba(239, 68, 68, 0.16); border-bottom-color: rgba(239,68,68,0.45); color: #fca5a5; }
#quota-banner[hidden] { display: none; }
#output { overflow: auto; padding: 0 8px; min-height: 0; width: 100%; box-sizing: border-box; }
#output .view { padding: 8px 8px 16px; }
#composer { position: sticky; bottom: 0; z-index: 1; }
/* Hide composer by default; show only on Conversation view */
#composer { display: none; }
body[data-view="chat"] #composer { display: block; }

/* Light scrollbar styling for scrollable areas */
/* Firefox */
#output, #leftSidebar, #rightSidebar, .chat-stream, .table-shell {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.45) rgba(255,255,255,0.12);
}

/* Brand row (logo + title) used in top header and auth header */
.brand-row { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; }
/* Keep header compact; allow larger logo on login (auth) page */
.brand-logo {
  display: block;
  width: 120px;
  height: auto;
  object-fit: contain;
  color: var(--text);
  margin: 0 auto 10px;
}
.main-header .brand-logo { width: 110px; }
body[data-view="auth"] .brand-logo {
  width: 150px;
  height: auto;
  margin: 0 auto 14px;
}
.logo-white { filter: none; }
@media (max-width: 520px) {
  /* Original responsive sizes for header; larger on auth */
  .main-header .brand-logo { width: 110px; }
  body[data-view="auth"] .brand-logo { width: 180px; }
}
/* WebKit */
#output::-webkit-scrollbar,
#leftSidebar::-webkit-scrollbar,
#rightSidebar::-webkit-scrollbar,
.chat-stream::-webkit-scrollbar,
.table-shell::-webkit-scrollbar {
  width: 10px; height: 10px;
}
#output::-webkit-scrollbar-track,
#leftSidebar::-webkit-scrollbar-track,
#rightSidebar::-webkit-scrollbar-track,
.chat-stream::-webkit-scrollbar-track,
.table-shell::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.08);
}
#output::-webkit-scrollbar-thumb,
#leftSidebar::-webkit-scrollbar-thumb,
#rightSidebar::-webkit-scrollbar-thumb,
.chat-stream::-webkit-scrollbar-thumb,
.table-shell::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.45);
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.12);
}
#output:hover::-webkit-scrollbar-thumb,
#leftSidebar:hover::-webkit-scrollbar-thumb,
#rightSidebar:hover::-webkit-scrollbar-thumb,
.chat-stream:hover::-webkit-scrollbar-thumb,
.table-shell:hover::-webkit-scrollbar-thumb {
  background-color: rgba(255,255,255,0.6);
}

/* Auth (login) page layout tweaks */
body[data-view="auth"] { overflow: hidden; }
body[data-view="auth"] #output {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 24px 16px;
  overflow: hidden;
  /* subtle background accents */
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(79,70,229,0.12), transparent),
    radial-gradient(800px 400px at 90% 110%, rgba(6,182,212,0.10), transparent);
}
body[data-view="auth"] .view-auth { width: 100%; max-width: 520px; margin: 0 auto; padding: 0; }
body[data-view="auth"] .view-auth .panel {
  max-width: 520px;
  margin: 0 auto;
  padding: 22px; /* reduced height via smaller padding */
  gap: 12px; /* tighten vertical spacing between sections */
  border-radius: 16px;
  /* glassy card look */
  backdrop-filter: blur(6px);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 20px 60px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
}
/* Prevent extra row in main grid on auth view to avoid vertical scrollbar */
body[data-view="auth"] #mainArea { grid-template-rows: 1fr !important; }
body[data-view="auth"] .panel-header h2 { font-size: 26px; font-weight: 700; letter-spacing: 0.2px; }
body[data-view="auth"] .view-auth .split { grid-template-columns: 1fr; }
body[data-view="auth"] .view-auth .panel-sub { width: 100%; }
body[data-view="auth"] .view-auth .row input {
  flex: 1 1 auto; min-width: 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  color: var(--text);
  padding: 10px 12px;
}
/* Light theme tweaks for login inputs */
body[data-theme="light"][data-view="auth"] .view-auth .row input {
  background: rgba(0,0,0,0.03);
  border: 1px solid rgba(0,0,0,0.12);
  color: var(--text);
}
body[data-theme="light"][data-view="auth"] .view-auth .row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.18);
}
/* Highlight inputs on focus on login */
body[data-view="auth"] .view-auth .row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.20);
}
body[data-view="auth"] .view-auth .row.stack-on-mobile { gap: 10px; }
/* Hero copy on login */
body[data-view="auth"] .hero { margin: 6px 0 10px; /* tighter spacing below logo */ }
body[data-view="auth"] .hero-title { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: 0.2px; }
body[data-view="auth"] .hero-sub { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
@media (max-width: 520px) {
  body[data-view="auth"] #output { min-height: calc(100vh - 64px); padding: 16px; }
  body[data-view="auth"] .view-auth, body[data-view="auth"] .view-auth .panel { max-width: 100%; }
}
/* Sidebar header top row: brand left, theme toggle right */
.sidebar-header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Light theme refinements for grayscale UI elements */
body[data-theme="light"] .ghost-btn {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--text);
}
body[data-theme="light"] .ghost-btn:hover { background: rgba(0, 0, 0, 0.08); }
body[data-theme="light"] .nav-btn:hover { background: rgba(0, 0, 0, 0.06); }

/* Conversation messages in light theme */
body[data-theme="light"] .message {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  box-shadow: none;
}
body[data-theme="light"] .message.user {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.10);
}

/* Inputs in light theme */
body[data-theme="light"] select,
body[data-theme="light"] input[type="number"],
body[data-theme="light"] input[type="file"] {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.12);
}

/* Scrollbars (Firefox) */
body[data-theme="light"] #output,
body[data-theme="light"] #leftSidebar,
body[data-theme="light"] #rightSidebar,
body[data-theme="light"] .chat-stream,
body[data-theme="light"] .table-shell {
  scrollbar-color: rgba(0,0,0,0.45) rgba(0,0,0,0.12);
}

/* Scrollbars (WebKit) */
body[data-theme="light"] #output::-webkit-scrollbar-track,
body[data-theme="light"] #leftSidebar::-webkit-scrollbar-track,
body[data-theme="light"] #rightSidebar::-webkit-scrollbar-track,
body[data-theme="light"] .chat-stream::-webkit-scrollbar-track,
body[data-theme="light"] .table-shell::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.06);
}
body[data-theme="light"] #output::-webkit-scrollbar-thumb,
body[data-theme="light"] #leftSidebar::-webkit-scrollbar-thumb,
body[data-theme="light"] #rightSidebar::-webkit-scrollbar-thumb,
body[data-theme="light"] .chat-stream::-webkit-scrollbar-thumb,
body[data-theme="light"] .table-shell::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.35);
  border: 2px solid rgba(0,0,0,0.12);
}
body[data-theme="light"] #output:hover::-webkit-scrollbar-thumb,
body[data-theme="light"] #leftSidebar:hover::-webkit-scrollbar-thumb,
body[data-theme="light"] #rightSidebar:hover::-webkit-scrollbar-thumb,
body[data-theme="light"] .chat-stream:hover::-webkit-scrollbar-thumb,
body[data-theme="light"] .table-shell:hover::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.5);
}

/* Additional light theme fixes for conversation and modals */
body[data-theme="light"] .composer { border-top: 1px solid rgba(0, 0, 0, 0.06); }
body[data-theme="light"] .input-shell { background: rgba(0, 0, 0, 0.03); border: 1px solid rgba(0, 0, 0, 0.12); }
body[data-theme="light"] .modal-header { background: rgba(255,255,255,0.96); border-bottom: 1px solid var(--surface-border); }

/* Table grid lines in light theme */
body[data-theme="light"] th,
body[data-theme="light"] td { border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
body[data-theme="light"] th { background: rgba(0, 0, 0, 0.03); }
/* Files table borders in light theme */
body[data-theme="light"] .files-table th,
body[data-theme="light"] .files-table td { border-bottom: 1px solid rgba(0,0,0,0.1); }
body[data-theme="light"] .files-table th { background: rgba(0,0,0,0.02); }
#modal.modal--anchor #modal-content {
  min-width: 280px;
  max-width: 420px;
  height: auto !important;
  max-height: 70vh;
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.4);
}
