/* ═══════════════════════════════════════════════════════
   CLAVIS — Financial Intelligence Platform
   Design System: Navy/Teal — Dark Professional
════════════════════════════════════════════════════════ */

:root {
  --bg:          #080d1a;
  --surface:     #0f1629;
  --surface2:    #19213a;
  --surface3:    #232e4a;
  --border:      #2a3655;
  --border-light:#354169;
  --text:        #eef2ff;
  --text-muted:  #8892b0;
  --text-dim:    #546287;
  --accent:      #14b8a6;       /* Teal */
  --accent-glow: rgba(20,184,166,.18);
  --accent2:     #6366f1;       /* Indigo */
  --green:       #10b981;
  --red:         #f43f5e;
  --yellow:      #f59e0b;
  --blue:        #3b82f6;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
  --shadow-sm:   0 2px 8px rgba(0,0,0,.3);
  --font:        'Inter', system-ui, sans-serif;
  --mono:        'JetBrains Mono', monospace;
  --sidebar-w:   220px;
  --transition:  .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ─── SIDEBAR ─── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0 20px;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 4px;
}

.brand-icon {
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
}

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

.sidebar-tagline {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 0 20px 28px;
}

.nav-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

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

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(20,184,166,.25);
}

.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 0 20px;
}

.version-badge {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  display: inline-block;
}

/* ─── BOTTOM NAV (mobile) ─── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 6px 0 env(safe-area-inset-bottom);
}

.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10px;
  cursor: pointer;
  transition: var(--transition);
}

.bnav-item.active { color: var(--accent); }
.bnav-icon { font-size: 18px; }
.bnav-label { font-size: 9px; }

/* ─── MAIN CONTENT ─── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 32px 32px 60px;
  max-width: 1200px;
}

/* ─── PAGES ─── */
.page { display: none; }
.page.active { display: block; }

/* ─── PAGE HEADER ─── */
.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.page-title .accent { color: var(--accent); }

.page-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.ai-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(20,184,166,.3);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
  align-self: center;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 600px;
}

/* ─── UPLOAD CARD ─── */
.upload-card {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 80px 40px;
  text-align: center;
  cursor: pointer;
  transition: all .25s ease;
  background: var(--surface);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.upload-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 60%, rgba(20,184,166,.06) 0%, transparent 70%);
  pointer-events: none;
}

.upload-card:hover,
.upload-card.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.upload-icon { font-size: 48px; margin-bottom: 16px; }
.upload-title { font-size: 18px; font-weight: 600; margin-bottom: 6px; }
.upload-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.upload-formats {
  font-size: 12px;
  color: var(--text-dim);
  font-family: var(--mono);
  letter-spacing: 1px;
}

/* ─── FILE PREVIEW ─── */
.file-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.file-icon { font-size: 32px; }

.file-details { flex: 1; }
.file-name { font-size: 14px; font-weight: 600; margin-bottom: 3px; word-break: break-all; }
.file-size { font-size: 12px; color: var(--text-muted); }

.btn-remove {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-remove:hover { border-color: var(--red); color: var(--red); }

.optional-row { margin-bottom: 16px; }

.input-note {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
.input-note:focus { border-color: var(--accent); }
.input-note::placeholder { color: var(--text-dim); }

.btn-analyze {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #0d9488);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: .5px;
}
.btn-analyze:hover { opacity: .9; transform: translateY(-1px); box-shadow: 0 8px 24px rgba(20,184,166,.3); }
.btn-analyze:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* ─── ANALYZING CARD ─── */
.analyzing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  text-align: center;
  margin-bottom: 16px;
}

.spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

.analyzing-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.analyzing-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }

.analyzing-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
  text-align: left;
}

.astep {
  font-size: 13px;
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: var(--transition);
}

.astep.active {
  color: var(--accent);
  border-color: rgba(20,184,166,.4);
  background: var(--accent-glow);
}

.astep.done {
  color: var(--green);
  border-color: rgba(16,185,129,.3);
}

/* ─── ERROR CARD ─── */
.error-card {
  background: var(--surface);
  border: 1px solid rgba(244,63,94,.3);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  margin-bottom: 16px;
}

.error-icon { font-size: 36px; margin-bottom: 12px; }
.error-title { font-size: 18px; font-weight: 600; color: var(--red); margin-bottom: 8px; }
.error-msg { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.6; }

.btn-retry {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}
.btn-retry:hover { border-color: var(--accent); color: var(--accent); }

/* ─── FORMATS INFO ─── */
.formats-info {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-top: 24px;
}

.fi-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.fi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

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

/* ─── COMPANY HEADER ─── */
.company-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.company-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.company-meta {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--mono);
}

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

.dq-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid transparent;
}

.dq-badge.high { background: rgba(16,185,129,.15); color: var(--green); border-color: rgba(16,185,129,.3); }
.dq-badge.medium { background: rgba(245,158,11,.15); color: var(--yellow); border-color: rgba(245,158,11,.3); }
.dq-badge.low { background: rgba(244,63,94,.15); color: var(--red); border-color: rgba(244,63,94,.3); }

.btn-export, .btn-new {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-export {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-export:hover { border-color: var(--accent); color: var(--accent); }

.btn-new {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
}
.btn-new:hover { opacity: .85; }

/* ─── DASHBOARD TABS ─── */
.dash-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  overflow-x: auto;
}

.dash-tab {
  flex: 1;
  min-width: 90px;
  padding: 9px 16px;
  background: none;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.dash-tab:hover { color: var(--text); background: var(--surface2); }
.dash-tab.active { background: var(--accent); color: #fff; font-weight: 600; }

.dash-tab-content { display: none; }
.dash-tab-content.active { display: block; }

/* ─── KPI GRID ─── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

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

.kpi-card:hover { border-color: var(--border-light); }

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.kpi-value {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--mono);
  margin-bottom: 8px;
  color: var(--text);
}

.kpi-value.positive { color: var(--green); }
.kpi-value.negative { color: var(--red); }

.kpi-change {
  font-size: 12px;
  font-family: var(--mono);
  padding: 2px 8px;
  border-radius: 12px;
  display: inline-block;
}

.kpi-change.up { background: rgba(16,185,129,.15); color: var(--green); }
.kpi-change.down { background: rgba(244,63,94,.15); color: var(--red); }
.kpi-change.neutral { background: var(--surface2); color: var(--text-dim); }

/* ─── CHARTS ─── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.chart-card.full-width { grid-column: 1 / -1; }

.chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

.chart-card canvas { max-height: 280px; }

/* ─── TABLES ─── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

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

.fin-table th {
  background: var(--surface2);
  padding: 10px 16px;
  text-align: right;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.fin-table th:first-child { text-align: left; }

.fin-table td {
  padding: 9px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-muted);
}

.fin-table td:first-child {
  text-align: left;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
}

.fin-table tr:last-child td { border-bottom: none; }

.fin-table tr:hover td { background: var(--surface2); }

.fin-table tr.subtotal td {
  font-weight: 600;
  color: var(--text);
  border-top: 1px solid var(--border-light);
}

.fin-table tr.total td {
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  border-top: 2px solid rgba(20,184,166,.3);
}

.fin-table tr.section-header td {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 6px 16px;
  font-family: var(--font);
}

.cell-pos { color: var(--green) !important; }
.cell-neg { color: var(--red) !important; }
.cell-null { color: var(--text-dim) !important; }

/* ─── RATIOS GRID ─── */
.ratios-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

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

.ratio-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.ratio-values {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.ratio-period {
  text-align: center;
}

.ratio-period-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.ratio-period-val {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--accent);
}

/* ─── NOTES CARD ─── */
.notes-card {
  background: var(--surface);
  border: 1px solid rgba(245,158,11,.2);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.notes-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--yellow);
}

.notes-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ─── HISTORY ─── */
#page-history .page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.btn-clear-history {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}
.btn-clear-history:hover { border-color: var(--red); color: var(--red); }

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 16px;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--surface2);
}

.hi-icon { font-size: 28px; flex-shrink: 0; }
.hi-info { flex: 1; }
.hi-company { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.hi-meta { font-size: 12px; color: var(--text-muted); }
.hi-arrow { color: var(--text-dim); font-size: 18px; }

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 80px 40px;
}

.es-icon { font-size: 48px; margin-bottom: 16px; color: var(--text-dim); }
.es-title { font-size: 18px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
.es-sub { font-size: 14px; color: var(--text-dim); }

/* ─── GUIDE ─── */
.guide-content { max-width: 700px; }

.guide-section {
  margin-bottom: 36px;
}

.guide-section h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.guide-section p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
}

.guide-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gstep {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

.gstep-num {
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-list li {
  font-size: 14px;
  color: var(--text-muted);
  padding-left: 20px;
  position: relative;
}

.guide-list li::before {
  content: '◆';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 8px;
  top: 5px;
}

/* ─── TOAST ─── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  z-index: 999;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── RESPONSIVE ─── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .ratios-grid { grid-template-columns: repeat(2, 1fr); }
  .fi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .main-content {
    margin-left: 0;
    padding: 20px 16px 80px;
  }
  .company-header {
    flex-direction: column;
    gap: 12px;
  }
  .header-actions { width: 100%; justify-content: flex-start; }
  .dash-tabs { overflow-x: auto; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .ratios-grid { grid-template-columns: 1fr 1fr; }
  .fi-grid { grid-template-columns: 1fr 1fr; }
  .page-title { font-size: 20px; }
}

/* ─── PRINT ─── */
@media print {
  .sidebar, .bottom-nav, .btn-export, .btn-new, .dash-tabs { display: none !important; }
  .main-content { margin: 0; padding: 16px; max-width: 100%; }
  .dash-tab-content { display: block !important; }
  .chart-card, .kpi-card, .table-card { break-inside: avoid; }
}
