:root {
  --bg: #050608;
  --bg-glow: #0a0d14;
  --bg-spot-1: rgba(56, 189, 248, 0.12);
  --bg-spot-2: rgba(52, 211, 153, 0.16);
  --panel: rgba(255, 255, 255, 0.05);
  --panel-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.2);
  --text: #eef2f7;
  --muted: #a5afbb;
  --accent: #34d399;
  --accent-2: #38bdf8;
  --accent-blue: var(--accent-2);
  --text-primary: var(--text);
  --text-muted: var(--muted);
  --stroke: var(--border);
  --danger: #f87171;
  --sidebar-bg: #0b0d12;
  --topbar-bg: rgba(12, 16, 22, 0.96);
  --topbar-border: rgba(255, 255, 255, 0.08);
  --topbar-height: 68px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --space-6: 32px;
  --shadow-1: 0 10px 24px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 18px 40px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-glow: #eef2f7;
  --bg-spot-1: rgba(56, 189, 248, 0.12);
  --bg-spot-2: rgba(52, 211, 153, 0.12);
  --panel: rgba(255, 255, 255, 0.9);
  --panel-2: rgba(248, 250, 252, 0.95);
  --border: rgba(148, 163, 184, 0.3);
  --border-strong: rgba(148, 163, 184, 0.5);
  --text: #0f172a;
  --muted: #475569;
  --accent: #059669;
  --accent-2: #0ea5e9;
  --danger: #dc2626;
  --sidebar-bg: #f8fafc;
  --topbar-bg: rgba(255, 255, 255, 0.95);
  --topbar-border: rgba(148, 163, 184, 0.4);
  --shadow-1: 0 12px 24px rgba(15, 23, 42, 0.12);
  --shadow-2: 0 20px 40px rgba(15, 23, 42, 0.16);
}
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Sora", sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(circle at top right, var(--bg-spot-1), transparent 40%),
    radial-gradient(circle at 10% 20%, var(--bg-spot-2), transparent 35%);
  min-height: 100vh;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 20px;
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  height: calc(100vh - var(--topbar-height));
  position: sticky;
  top: var(--topbar-height);
  align-self: start;
  overflow-y: auto;
}

.session-title {
  font-family: "Fraunces", serif;
  font-size: 20px;
  margin-bottom: 8px;
}

.session-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.brand-title {
  font-family: "Fraunces", serif;
  font-size: 22px;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.user-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.user-card .label {
  color: var(--muted);
  font-size: 10px;
}

.user-card .value {
  font-size: 12px;
  margin-top: 2px;
}

.user-card.compact {
  padding: 8px 10px;
}

.user-card.compact .label {
  font-size: 9px;
}

.user-card.compact .value {
  font-size: 11px;
}

.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 6px;
}

.nav-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 6px 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nav-link {
  text-decoration: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.nav-link.active,
.nav-link:hover {
  color: var(--text);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
  font-weight: 600;
  background: rgba(52, 211, 153, 0.12);
}

.nav-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 4px;
  background: var(--accent);
  border-radius: 999px;
}

.nav-link:hover {
  transform: translateX(2px);
}

.sidebar-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.pill {
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  min-height: var(--topbar-height);
}

.topbar-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: var(--text);
}

.brand-name {
  font-family: "Fraunces", serif;
  font-size: 20px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
}

.topbar-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.btn-icon svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.user-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
}

.user-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
}

.caret svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  flex-wrap: wrap;
}

.page-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page-title {
  font-family: "Fraunces", serif;
  font-size: 26px;
}

.page-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.page-header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.page-header-actions form {
  display: flex;
  gap: 12px;
  align-items: center;
}

.breadcrumb {
  font-family: "Fraunces", serif;
  font-size: 18px;
  display: flex;
  gap: 6px;
  align-items: center;
}

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

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

.dataset-status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.upload-form {
  margin: 0;
}

.file-button {
  cursor: pointer;
}

.file-button input {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.panel h2,
.panel h3 {
  font-family: "Fraunces", serif;
  margin-top: 0;
}

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

.panel-meta {
  color: var(--text-muted);
  font-size: 12px;
}

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

.chart-panel {
  padding: 16px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 240px !important;
}

.chart-panel.span-2 {
  grid-column: span 2;
}

.chart-panel.span-3 {
  grid-column: span 3;
}

.chart-card {
  position: relative;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.chart-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-title {
  font-family: "Fraunces", serif;
  font-size: 18px;
  margin: 0;
  max-width: 100%;
  word-break: break-word;
}

.chart-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  max-width: 100%;
  word-break: break-word;
}

.chart-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: not-allowed;
}

.icon-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.chart-skeleton {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  background: linear-gradient(
    120deg,
    rgba(255, 255, 255, 0.02) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.02) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  opacity: 0;
  pointer-events: none;
}

.chart-card.loading .chart-skeleton {
  opacity: 1;
}

.chart-card.loading canvas {
  opacity: 0.35;
}

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

.chart-empty {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.empty-state {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

.empty-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.empty-title {
  font-size: 13px;
  color: var(--text);
}

.empty-note {
  font-size: 11px;
  color: var(--muted);
}

.empty-cta {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
}

.select-input {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 6px 10px;
  color: var(--text-primary);
  min-width: 160px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.select-input:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.chart-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 100%;
}

.chart-controls .select-input {
  width: 100%;
  max-width: 240px;
}

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

.insight-card {
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.insight-label {
  color: var(--text-muted);
  font-size: 12px;
}

.insight-value {
  font-size: 15px;
  margin-top: 6px;
}

.insight-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.analyst-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.analyst-form input {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text-primary);
  min-width: 240px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.analyst-form input:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

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

.analyst-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
  min-height: 320px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.analyst-card canvas {
  width: 100% !important;
  height: 280px !important;
}

.analyst-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
}

.analyst-hero {
  padding: var(--space-5);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.08), rgba(52, 211, 153, 0.08));
}

.analyst-hero h2 {
  font-size: 28px;
  margin-bottom: 4px;
}

.analyst-hero .panel-meta {
  font-size: 13px;
  margin-top: 12px;
}

.analyst-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.analyst-chips {
  margin-top: 12px;
}

.btn {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s ease;
}

.btn:hover {
  border-color: var(--accent-2);
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(120deg, rgba(52, 211, 153, 0.2), rgba(56, 189, 248, 0.2));
  border-color: rgba(56, 189, 248, 0.5);
}

.btn-ghost {
  padding: 8px 12px;
  font-size: 12px;
  opacity: 0.6;
}

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

.file-input {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--border-strong);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--muted);
}

.file-input input {
  display: none;
}

.notice {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: var(--accent);
}

.uploading {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--accent-blue);
}

.hidden {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.3);
  border-top-color: var(--accent-blue);
  animation: spin 0.8s linear infinite;
}

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

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding-bottom: 10px;
  color: var(--muted);
}

tbody tr {
  border-top: 1px solid var(--border);
  cursor: pointer;
}

tbody td {
  padding: 12px 6px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpi-grid .info-card {
  padding: 12px;
}

.kpi-grid .value {
  font-size: 14px;
}

.info-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow: hidden;
}

.info-card .label {
  color: var(--muted);
  font-size: 12px;
  word-break: break-word;
}

.info-card .value {
  font-size: 16px;
  margin-top: 6px;
  word-break: break-word;
}

.audit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audit-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
  color: var(--muted);
}

.audit-type {
  color: var(--text-primary);
  font-weight: 600;
}

.audit-message {
  margin-top: 4px;
}

.audit-time {
  margin-top: 6px;
  font-size: 11px;
}

.audit-empty {
  color: var(--muted);
  font-size: 12px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.filter-grid input {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
}

.chat-form {
  display: flex;
  gap: 12px;
}

.chat-form input {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}

.chip-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
}

.chip:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.chat-answer,
.chat-history {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.chat-question {
  color: var(--text-muted);
  margin-bottom: 6px;
}

.chat-answer .label {
  color: var(--muted);
  margin-bottom: 6px;
}

.chat-answer .meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}

.extracted-text {
  background: rgba(0, 0, 0, 0.4);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  max-height: 320px;
  overflow: auto;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
  }
  .topbar-controls {
    width: 100%;
    justify-content: flex-start;
  }
  .sidebar {
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .analytics-grid,
  .analyst-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .chart-panel.span-3 {
    grid-column: 1 / -1;
  }
  .chat-form {
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  .analyst-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}
