:root {
  --navy: #0b2447;
  --blue: #1e73be;
  --accent: #19a7ce;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1a1f29;
  --muted: #6b7280;
  --ok: #157347;
  --warn: #b45309;
  --line: #e5e7eb;
}
* { box-sizing: border-box; }
input, select, textarea, button { max-width: 100%; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }

.topbar { display: flex; align-items: center; gap: 24px; background: var(--navy); color: #fff; padding: 12px 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { background: var(--accent); color: #fff; border-radius: 8px; padding: 4px 8px; font-weight: 800; }
.brand-mark.large { font-size: 28px; padding: 10px 16px; }
.brand-name { font-size: 15px; }
.nav { display: flex; gap: 18px; margin-left: 12px; flex: 1; }
.nav a { color: #cdd9e5; text-decoration: none; font-size: 14px; }
.nav a:hover { color: #fff; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user .roles { color: #9db4c9; font-size: 11px; }

.content { max-width: 1120px; margin: 0 auto; padding: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.page-title-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-title-actions h1 { margin: 0; }
.muted { color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 20px 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.kpi.big { grid-column: span 2; }
.kpi-val { font-size: 24px; font-weight: 800; color: var(--navy); }
.kpi-lbl { font-size: 12px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card { min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }
.warn-card { border-color: #f0c27a; background: #fff8ec; }

table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; }
thead, tbody { min-width: max-content; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; margin-left: 8px; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }

.ai-panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 18px 0; }
.ai-head { display: flex; justify-content: space-between; align-items: center; }
.ai-head h2 { margin: 0; font-size: 16px; }
.ai-out { margin-top: 12px; white-space: pre-wrap; line-height: 1.5; font-size: 14px; }
.comparison-panel { margin: 18px 0; }
.compact-copy { margin: 4px 0 0; font-size: 13px; }
.dashboard-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.dashboard-filters label, .dashboard-question { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.dashboard-filters select, .dashboard-filters input, .dashboard-question textarea { width: 100%; min-width: 0; padding: 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; }
.filter-help { margin: -8px 0 14px; font-size: 12px; }
.dashboard-question { margin-bottom: 12px; }
.dashboard-question textarea { resize: vertical; font-size: 14px; font-weight: 400; }
.comparison-table { margin-top: 12px; }
#comparison-title { margin: 18px 0 0; font-size: 15px; }
.comparison-result-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; }
.comparison-result-head #comparison-title { margin: 0; }
#coverage-note { font-size: 12px; }
.comparison-visual { margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.comparison-visual h3 { margin: 0 0 16px; font-size: 15px; }
#comparison-chart { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 28px; }
.chart-group { min-width: 0; }
.chart-group > strong { display: block; margin-bottom: 7px; font-size: 12px; }
.chart-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) 58px; gap: 8px; align-items: center; margin: 6px 0; font-size: 11px; }
.chart-track { height: 12px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.chart-bar { display: block; min-width: 2px; height: 100%; border-radius: inherit; background: #94a3b8; }
.chart-bar.current { background: var(--blue); }
.chart-value { text-align: right; font-variant-numeric: tabular-nums; }
.value-explanation { margin-top: 18px; padding: 16px; border: 1px solid #b9d7ef; border-radius: 10px; background: #f3f8fd; }
.value-explanation h3 { margin: 0 0 8px; font-size: 15px; }
.value-explanation > p { margin: 0; line-height: 1.5; font-size: 13px; }
.driver-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 14px; }
.driver-columns h4 { margin: 0 0 7px; color: var(--navy); font-size: 12px; }
.driver-columns ul { margin: 0; padding-left: 18px; font-size: 11px; line-height: 1.5; }
.breakdown-panel { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fff; }
.breakdown-panel summary { color: var(--navy); cursor: pointer; font-size: 14px; font-weight: 700; }
.breakdown-table { margin-top: 12px; max-height: 460px; }
.breakdown-table td:not(:first-child), .breakdown-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.breakdown-table .decline-row td { background: #fff8f6; }
.breakdown-table tfoot th, .breakdown-table tfoot td { border-top: 2px solid var(--navy); background: #edf5fc; font-weight: 800; }
.overview-controls { margin-top: 18px; }
.overview-period { margin: 24px 0 12px; font-size: 18px; }
.overview-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.overview-period-card { display: grid; gap: 5px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.overview-period-card.upcoming { border-color: #a7ccec; background: #f3f8fd; }
.overview-period-card > strong { color: var(--navy); font-size: 28px; }
.overview-period-card > span:not(.period-label), .overview-period-card > div { color: var(--muted); font-size: 12px; }
.period-label { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.money-basis { margin: 10px 0 20px; font-size: 12px; }
.course-health-chart { display: grid; gap: 14px; margin-top: 18px; }
.course-health-item { min-width: 0; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.course-health-item:last-child { border-bottom: 0; }
.course-health-item h3 { margin: 0 0 8px; font-size: 13px; }
.course-health-row { display: grid; grid-template-columns: 64px minmax(80px, 1fr) minmax(220px, auto); gap: 10px; align-items: center; margin: 6px 0; font-size: 11px; }
.course-detail { text-align: right; font-variant-numeric: tabular-nums; }
.health-table th[colspan] { text-align: center; }
.health-table .past-heading, .health-table .past-col { background: #f1f5f9; }
.health-table .upcoming-heading, .health-table .upcoming-col { background: #e8f3fc; }
.health-table .past-heading { color: #475569; border-top: 3px solid #94a3b8; }
.health-table .upcoming-heading { color: #155b91; border-top: 3px solid var(--blue); }
.health-table .upcoming-start { border-left: 2px solid #b9d7ef; }

.btn { display: inline-block; background: var(--blue); color: #fff; border: none; border-radius: 8px; padding: 10px 18px; font-size: 14px; cursor: pointer; text-decoration: none; }
.btn:hover { background: #17629f; }
.btn.secondary { background: #64748b; }
.btn-sm { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; text-decoration: none; }
.ai-head .btn-sm { background: var(--blue); border-color: var(--blue); }

.login-card { max-width: 420px; margin: 60px auto; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 36px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 16px 0 6px; }
.login-card .btn { margin-top: 18px; }
.notice { background: #fff8ec; border: 1px solid #f0c27a; border-radius: 10px; padding: 14px; text-align: left; margin: 18px 0; font-size: 13px; }
.notice code { background: #eee; padding: 1px 5px; border-radius: 4px; }

.upload-form { display: grid; gap: 14px; max-width: 480px; }
.upload-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
.upload-form input, .upload-form select { width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.analysis { white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 14px; font-size: 13px; line-height: 1.5; font-family: ui-monospace, monospace; }
.financial-workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 18px; margin-top: 20px; align-items: start; }
.financial-workspace .upload-form { max-width: none; }
.financial-documents .document-list { margin-bottom: 0; }
.financial-documents li { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.financial-chat-panel { min-height: 680px; display: flex; flex-direction: column; }
.financial-chat-head h2 { margin-bottom: 0; }
.initial-analysis { margin: 16px 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.initial-analysis p { margin: 5px 0 10px; font-size: 12px; }
.initial-analysis .analysis { max-height: 220px; overflow-y: auto; background: #fff; }
.suggested-questions { display: flex; gap: 7px; flex-wrap: wrap; margin: 14px 0 4px; }
.suggested-questions button { border: 1px solid #bfdbfe; border-radius: 999px; padding: 7px 10px; background: #eff6ff; color: var(--navy); cursor: pointer; font-size: 12px; }
.suggested-questions button:hover { background: #dbeafe; }
.financial-messages { max-height: 54vh; }

.footer { max-width: 1120px; margin: 0 auto; padding: 18px 24px; color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }

.project-toolbar { display: grid; grid-template-columns: minmax(220px, 0.7fr) minmax(360px, 1.3fr); gap: 16px 24px; align-items: end; margin-top: 20px; }
.project-picker, .project-create { display: flex; flex-direction: column; gap: 7px; }
.project-picker label, .project-create label { color: var(--muted); font-size: 12px; font-weight: 600; }
.project-picker select, .project-create input { width: 100%; min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; }
.project-create-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.project-toolbar .status { grid-column: 1 / -1; margin: -6px 0 0; }
.chat-workspace { min-width: 0; overflow: hidden; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.compact-form { display: flex; gap: 8px; }
.compact-form input, .chat-form textarea { min-width: 0; width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.conversation-link { display: flex; justify-content: space-between; gap: 8px; padding: 9px; color: var(--ink); text-decoration: none; border-radius: 8px; }
.conversation-link:hover, .conversation-link.active { background: #e8f1fa; color: var(--navy); }
.project-head, .section-head, .actions, .chat-form { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.project-head { padding: 18px; border-bottom: 1px solid #cbdbea; border-left: 4px solid var(--blue); background: linear-gradient(90deg, #edf5fc 0, #fff 60%); }
.project-head h2, .project-head p, .section-head h2 { margin: 0; }
.current-project { min-width: 0; }
.current-project h2 { margin-top: 3px; color: var(--navy); font-size: 21px; overflow-wrap: anywhere; }
.project-eyebrow { color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.project-columns { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; }
.conversation-list { min-width: 0; align-self: stretch; padding: 18px; background: #f8fafc; border-right: 1px solid var(--line); }
.conversation-list .section-head { min-width: 0; flex-wrap: wrap; }
.conversation-list .section-head h2 { min-width: 0; }
.conversation-list .section-head .btn-sm { flex: 0 0 auto; margin-left: auto; }
.conversation-list > .conversation-link { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-sm.solid { background: var(--blue); border-color: var(--blue); }
.documents-heading { margin-top: 28px !important; }
.document-list { padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
.conversation-list .compact-form { display: grid; margin-top: 12px; }
.conversation-list input[type=file] { max-width: 100%; font-size: 12px; }
.chat-panel { min-height: 560px; display: flex; flex-direction: column; padding: 18px 18px 14px 0; }
.messages { flex: 1; min-height: 320px; max-height: 60vh; overflow-y: auto; padding: 8px 0; }
.message { max-width: 86%; margin: 10px 0; padding: 12px 14px; border-radius: 12px; line-height: 1.45; }
.message.user { margin-left: auto; background: #e8f1fa; }
.message.assistant { background: #f1f5f9; }
.message-content { margin-top: 5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.citations { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.document-download { display: inline-block; margin-top: 10px; padding: 7px 11px; border-radius: 7px; background: var(--blue); color: #fff; font-size: 12px; font-weight: 700; text-decoration: none; }
.document-download:hover { background: #17629f; }
.chat-form { align-items: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
.chat-form textarea { resize: vertical; }
.status { min-height: 20px; margin-top: 10px; }
.empty-state { text-align: center; padding: 50px 20px; }

@media (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .financial-workspace { grid-template-columns: 280px minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .user { width: 100%; flex-wrap: wrap; }
  .content { padding: 18px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .financial-workspace { grid-template-columns: 1fr; }
  .dashboard-filters { grid-template-columns: 1fr; }
  #comparison-chart { grid-template-columns: 1fr; }
  .driver-columns { grid-template-columns: 1fr; }
  .overview-kpis { grid-template-columns: 1fr; }
  .course-health-row { grid-template-columns: 58px minmax(60px, 1fr); }
  .course-detail { grid-column: 1 / -1; text-align: left; }
  .project-toolbar, .project-columns { grid-template-columns: 1fr; }
  .project-create-row { grid-template-columns: 1fr; }
  .conversation-list { border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-panel { padding: 18px; }
  .project-head, .actions, .chat-form { flex-wrap: wrap; }
  .comparison-result-head { align-items: flex-start; flex-direction: column; }
  .page-title-actions { align-items: flex-start; flex-direction: column; }
  .project-head { align-items: flex-start; }
  .chat-form textarea { flex: 1 0 100%; }
  .nav { display: none; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
  .message { max-width: 94%; }
  th, td { padding: 8px; }
}
