/* Regula Patrimonio — Design System */
@import url('https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&family=Geist+Mono:wght@400;500;600&display=swap');

:root {
  /* Surfaces */
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F2EC;
  --surface-3: #EEECE4;

  /* Ink */
  --ink: #0A0A0A;
  --ink-2: #2A2A28;
  --muted: #6B6963;
  --muted-2: #9A9890;

  /* Borders */
  --border: #E8E6DF;
  --border-strong: #D6D3C9;

  /* Accent */
  --accent: oklch(0.48 0.08 155);
  --accent-soft: oklch(0.92 0.03 155);
  --accent-ink: oklch(0.32 0.08 155);

  /* Semantic */
  --green: oklch(0.58 0.12 155);
  --amber: oklch(0.72 0.14 70);
  --red: oklch(0.55 0.18 25);
  --green-soft: oklch(0.94 0.04 155);
  --amber-soft: oklch(0.94 0.05 70);
  --red-soft: oklch(0.94 0.05 25);

  /* Type */
  --f-sans: 'Geist', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --f-mono: 'Geist Mono', ui-monospace, 'SF Mono', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 0 rgba(10, 10, 10, 0.02);
  --shadow-md: 0 1px 2px rgba(10, 10, 10, 0.04), 0 0 0 1px rgba(10, 10, 10, 0.03);
  --shadow-pop: 0 12px 32px -8px rgba(10, 10, 10, 0.12), 0 2px 6px rgba(10, 10, 10, 0.04);

  /* Radii */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--f-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'ss01', 'cv11';
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
input, textarea { font-family: inherit; }

/* Numerics */
.num, .mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tnum { font-variant-numeric: tabular-nums; }

/* Layout primitives */
.app {
  display: grid;
  grid-template-columns: 220px 1fr 380px;
  height: 100vh;
  overflow: hidden;
}
.app.full-chat { grid-template-columns: 220px 1fr; }

/* Left sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 2px;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--f-mono); font-weight: 600; font-size: 12px;
}
.brand-name { font-weight: 600; font-size: 13px; letter-spacing: -0.01em; }
.brand-sub { font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.nav-group { margin-top: 12px; }
.nav-label { font-family: var(--f-mono); font-size: 10px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.08em; padding: 6px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px; border-radius: var(--r-sm);
  font-size: 13px; color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--ink); color: var(--bg); }
.nav-item.active .nav-icon { color: var(--bg); }
.nav-icon { width: 14px; height: 14px; color: var(--muted); flex: none; }
.nav-count { margin-left: auto; font-family: var(--f-mono); font-size: 10px; color: var(--muted); }
.nav-item.active .nav-count { color: rgba(255,255,255,0.6); }

.side-company {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--r-sm);
  font-size: 12px; color: var(--ink-2);
  cursor: pointer;
}
.side-company:hover { background: var(--surface-2); }
.side-company.active { background: var(--surface-3); }
.side-company-dot { width: 6px; height: 6px; border-radius: 2px; flex: none; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--r-sm);
}
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-size: 11px; font-weight: 500; }

/* Main */
.main { overflow-y: auto; overflow-x: hidden; }
.topbar {
  height: 52px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
}
.breadcrumb { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.breadcrumb .current { color: var(--ink); font-weight: 500; }
.breadcrumb .sep { color: var(--muted-2); }

.topbar-spacer { flex: 1; }
.pill-select {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 12px; background: var(--surface);
  font-family: var(--f-mono); color: var(--ink-2);
}
.pill-select:hover { border-color: var(--border-strong); }
.kbd {
  font-family: var(--f-mono); font-size: 10px;
  border: 1px solid var(--border); border-radius: 3px;
  padding: 1px 4px; color: var(--muted); background: var(--surface);
}
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--r-sm);
  font-size: 12px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }

/* Page */
.page { padding: 24px 32px 48px; max-width: 1400px; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.page-subtitle { font-size: 12px; color: var(--muted); margin-top: 3px; font-family: var(--f-mono); }
.page-meta { display: flex; gap: 8px; align-items: center; }

/* Section */
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.section-title { font-size: 13px; font-weight: 600; letter-spacing: -0.005em; }
.section-sub { font-family: var(--f-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-2); }
.section-actions { display: flex; gap: 6px; }

/* KPI Hero grid */
.kpi-hero-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.kpi-hero {
  padding: 16px 18px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.kpi-hero:last-child { border-right: none; }
.kpi-hero-label {
  font-family: var(--f-mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.kpi-hero-value {
  font-family: var(--f-mono); font-size: 28px; font-weight: 500;
  letter-spacing: -0.02em; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi-hero-value .unit { font-size: 14px; color: var(--muted); margin-left: 2px; }
.kpi-hero-foot { display: flex; align-items: center; justify-content: space-between; }
.delta {
  font-family: var(--f-mono); font-size: 11px;
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 5px; border-radius: 3px;
}
.delta.up { color: var(--green); background: var(--green-soft); }
.delta.down { color: var(--red); background: var(--red-soft); }
.delta.flat { color: var(--muted); background: var(--surface-2); }
.kpi-hero-spark { height: 28px; width: 84px; }

/* Company cards */
.company-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.company-card {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.company-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.company-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.company-logo {
  width: 34px; height: 34px; border-radius: 7px;
  display: grid; place-items: center;
  font-family: var(--f-mono); font-weight: 600; font-size: 13px;
  flex: none;
}
.company-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.company-meta { font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 2px; }
.company-status { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; }
.status-dot.green { background: var(--green); }
.status-dot.amber { background: var(--amber); }
.status-dot.red { background: var(--red); }
.status-label { font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.company-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 16px;
  align-items: end;
}
.mini-kpi-label { font-family: var(--f-mono); font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 3px; }
.mini-kpi-value { font-family: var(--f-mono); font-size: 15px; font-weight: 500; letter-spacing: -0.01em; }
.mini-kpi-delta { font-family: var(--f-mono); font-size: 10px; margin-top: 2px; }

/* Panels */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-title { font-size: 12px; font-weight: 600; }
.panel-body { padding: 14px 16px; }

/* Two-col layouts */
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.cols-2-3 { display: grid; grid-template-columns: 2fr 3fr; gap: 12px; }
.cols-3-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; }

/* Alerts */
.alert-row {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px;
  align-items: center;
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.alert-row:last-child { border-bottom: none; }
.alert-severity { font-family: var(--f-mono); font-size: 10px; padding: 2px 6px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 500; }
.sev-critical { color: var(--red); background: var(--red-soft); }
.sev-warning { color: var(--amber); background: var(--amber-soft); }
.sev-info { color: var(--muted); background: var(--surface-2); }
.alert-text { color: var(--ink-2); }
.alert-company { font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.alert-date { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }

/* Tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.data th {
  text-align: left;
  font-family: var(--f-mono);
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  font-weight: 500;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
table.data td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
table.data tr:nth-child(even) td { background: rgba(0,0,0,0.008); }
table.data tr:last-child td { border-bottom: none; }
table.data .n { font-family: var(--f-mono); text-align: right; }
table.data .muted-row td { color: var(--muted); }
table.data .total-row td { font-weight: 600; border-top: 1px solid var(--border-strong); background: var(--surface-2) !important; }

/* Chat sidebar */
.chat-panel {
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex; flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.chat-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.chat-head-title { font-size: 13px; font-weight: 600; }
.chat-head-scope { font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.msg { font-size: 12.5px; line-height: 1.5; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: 10px 10px 2px 10px; }
.msg.ai { display: flex; gap: 10px; }
.msg.ai .ai-avatar { width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: white; display: grid; place-items: center; font-family: var(--f-mono); font-size: 11px; font-weight: 600; flex: none; }
.msg.ai .ai-content { flex: 1; color: var(--ink-2); }
.ai-citation {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--f-mono); font-size: 10px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
  margin: 0 2px;
  vertical-align: baseline;
}
.ai-citation sup { font-size: 9px; color: var(--accent); }

.quick-prompts { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.quick-prompt {
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 12px; color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.quick-prompt:hover { background: var(--surface-2); border-color: var(--border-strong); }
.quick-prompt .qp-icon { color: var(--muted); flex: none; }

.chat-input-wrap { padding: 12px 14px; border-top: 1px solid var(--border); }
.chat-input {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
  padding: 8px 10px;
  display: flex; align-items: flex-end; gap: 8px;
}
.chat-input:focus-within { border-color: var(--border-strong); }
.chat-input textarea {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 13px; background: transparent;
  min-height: 20px; max-height: 120px;
  color: var(--ink);
}
.chat-input textarea::placeholder { color: var(--muted-2); }
.chat-send {
  width: 26px; height: 26px; border-radius: 5px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  flex: none;
}
.chat-scope-row { display: flex; gap: 6px; margin-bottom: 8px; font-family: var(--f-mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-top: 24px;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab:hover { color: var(--ink-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.tab .tab-count { font-family: var(--f-mono); font-size: 10px; color: var(--muted-2); margin-left: 6px; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--f-mono); font-size: 10px;
  padding: 2px 6px; border-radius: 3px;
  background: var(--surface-2); color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.accent { background: var(--accent-soft); color: var(--accent-ink); }

/* Treemap */
.treemap { display: grid; gap: 2px; height: 240px; }
.treemap-cell {
  padding: 10px 12px;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden;
  border-radius: 2px;
  color: var(--ink);
}
.tm-label { font-size: 11px; font-weight: 500; }
.tm-value { font-family: var(--f-mono); font-size: 12px; font-weight: 500; }
.tm-pct { font-family: var(--f-mono); font-size: 10px; opacity: 0.7; }

/* Forms / upload */
.drop-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  color: var(--muted);
}
.drop-zone strong { color: var(--ink); font-weight: 500; }

/* Doc row */
.doc-row {
  display: grid;
  grid-template-columns: 28px 1fr 120px 100px 120px 60px;
  gap: 12px; align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.doc-row:hover { background: var(--surface-2); }
.doc-icon {
  width: 28px; height: 32px; border-radius: 3px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center;
  font-family: var(--f-mono); font-size: 9px; color: var(--muted); font-weight: 600;
}
.doc-title { font-weight: 500; color: var(--ink); }
.doc-sub { font-family: var(--f-mono); font-size: 10px; color: var(--muted); margin-top: 1px; }

/* Full chat page */
.chat-full { display: flex; flex-direction: column; height: 100%; }
.chat-full-body { flex: 1; overflow-y: auto; padding: 32px 48px; }
.chat-full-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.chat-empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; padding: 64px 0 32px;
}
.chat-empty .mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); color: white;
  display: grid; place-items: center;
  font-family: var(--f-mono); font-weight: 600; font-size: 20px;
  margin-bottom: 16px;
}
.chat-empty h2 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.02em; }
.chat-empty p { color: var(--muted); font-size: 13px; margin: 0; }
.empty-prompts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  width: 100%; max-width: 640px; margin-top: 28px;
}
.empty-prompt {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
  padding: 12px 14px;
  text-align: left;
  font-size: 12.5px; color: var(--ink-2);
  display: flex; flex-direction: column; gap: 4px;
}
.empty-prompt:hover { border-color: var(--border-strong); background: var(--bg); }
.empty-prompt .ep-tag { font-family: var(--f-mono); font-size: 9px; color: var(--muted-2); text-transform: uppercase; letter-spacing: 0.08em; }
.empty-prompt .ep-text { color: var(--ink); }

.scope-bar {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  background: var(--bg);
}
.scope-seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.scope-seg button {
  padding: 4px 10px; border-radius: 3px;
  font-size: 12px; color: var(--muted);
  font-family: var(--f-sans);
}
.scope-seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Tables in messages */
.msg-table {
  border: 1px solid var(--border); border-radius: var(--r-md);
  overflow: hidden; margin: 8px 0;
}
.msg-table table { width: 100%; }
.msg-table th, .msg-table td {
  padding: 6px 10px; font-size: 11px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.msg-table th {
  background: var(--surface-2);
  font-family: var(--f-mono);
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 500;
}
.msg-table td.n { font-family: var(--f-mono); text-align: right; font-variant-numeric: tabular-nums; }
.msg-table tr:last-child td { border-bottom: none; }

.msg-actions { display: flex; gap: 6px; margin-top: 8px; }

/* Utility */
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.text-muted { color: var(--muted); }
.text-accent { color: var(--accent); }
.hidden { display: none !important; }

/* Scrollbars */
.chat-body::-webkit-scrollbar, .main::-webkit-scrollbar, .chat-full-body::-webkit-scrollbar { width: 8px; height: 8px; }
.chat-body::-webkit-scrollbar-thumb, .main::-webkit-scrollbar-thumb, .chat-full-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.chat-body::-webkit-scrollbar-track, .main::-webkit-scrollbar-track, .chat-full-body::-webkit-scrollbar-track { background: transparent; }

/* Charts */
.axis-label { font-family: var(--f-mono); font-size: 9px; fill: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-line { stroke: var(--border-strong); stroke-width: 1; }

/* Drag */
.kpi-tile {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface);
  padding: 12px 14px;
  position: relative;
}
.kpi-tile .drag-handle {
  position: absolute; top: 8px; right: 8px;
  color: var(--muted-2);
  font-family: var(--f-mono); font-size: 9px;
  cursor: grab;
}
.kpi-tile.add-new {
  border-style: dashed;
  display: grid; place-items: center;
  color: var(--muted);
  cursor: pointer;
  min-height: 96px;
}
.kpi-tile.add-new:hover { border-color: var(--border-strong); color: var(--ink); }

/* Badge stack */
.tag-row { display: flex; gap: 4px; flex-wrap: wrap; }
