/* App layout + components — Inventon financial command center. */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.hidden { display: none !important; }

/* ── App frame ─────────────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: var(--z-sidebar);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-5) var(--s-4);
  font-weight: 700;
  letter-spacing: 0.3px;
}
.brand .logo {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 800;
}
.brand .name { font-size: 15px; }
.brand .sub { display: block; font-size: 11px; color: var(--faint); font-weight: 500; }

.nav { padding: var(--s-2); overflow-y: auto; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3);
  margin: 2px 0;
  border-radius: var(--r-sm);
  color: var(--muted);
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  font-weight: 500;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.25);
}
.nav-item .ico { width: 18px; height: 18px; display: grid; place-items: center; flex: 0 0 18px; }
.nav-item .ico svg { width: 18px; height: 18px; }

/* ── Main / topbar ─────────────────────────────────────────────────────── */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-5);
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
}
#page-title { font-size: 17px; font-weight: 700; margin: 0; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: var(--s-3); color: var(--muted); font-size: 13px; }
.topbar-user .email { color: var(--text); }

#view { padding: var(--s-5); flex: 1; min-width: 0; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover { background: var(--panel-2); border-color: var(--faint); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #04212f; font-weight: 600; }
.btn-accent:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn svg { width: 16px; height: 16px; }

/* ── Cards / panels ────────────────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s-4); }
.card-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-sub { color: var(--muted); font-size: 12px; margin: -8px 0 var(--s-4); }

.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ── KPI tiles ─────────────────────────────────────────────────────────── */
.kpis { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-sm);
}
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: var(--s-2); font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.kpi .meta { color: var(--faint); font-size: 12px; margin-top: var(--s-1); }
.kpi.accent { border-color: rgba(56, 189, 248, 0.3); }
.kpi.accent .value { color: var(--accent); }
.kpi.pos .value { color: var(--pos); }
.kpi.neg .value { color: var(--neg); }
.kpi.warn .value { color: var(--warn); }

/* ── Tables ────────────────────────────────────────────────────────────── */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border);
}
table.tbl td { padding: var(--s-3); border-bottom: 1px solid rgba(51, 65, 85, 0.5); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover td { background: var(--panel-2); }
table.tbl td.right, table.tbl th.right { text-align: right; }
table.tbl td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 2px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-high { background: var(--neg-bg); color: var(--neg); }
.badge-med { background: var(--warn-bg); color: var(--warn); }
.badge-low { background: var(--panel-2); color: var(--muted); }
.badge-accent { background: var(--accent-bg); color: var(--accent); }
.badge-pos { background: var(--pos-bg); color: var(--pos); }

/* ── Inputs ────────────────────────────────────────────────────────────── */
.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
.field { margin-bottom: var(--s-4); }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: var(--s-2); }

/* ── Placeholder (stub modules) ────────────────────────────────────────── */
.placeholder { text-align: center; padding: var(--s-7) var(--s-5); color: var(--muted); }
.placeholder .ph-ico { font-size: 36px; margin-bottom: var(--s-3); opacity: 0.6; }
.placeholder h2 { margin: 0 0 var(--s-2); color: var(--text); }

/* ── Loading / empty ───────────────────────────────────────────────────── */
.loading, .empty { color: var(--muted); padding: var(--s-5); text-align: center; }
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto var(--s-3);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: var(--z-toast);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  box-shadow: var(--shadow);
  min-width: 220px;
  max-width: 360px;
  animation: toast-in 0.18s ease;
}
.toast.info { border-left-color: var(--accent); }
.toast.success { border-left-color: var(--pos); }
.toast.error { border-left-color: var(--neg); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ── Login ─────────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 70% -10%, rgba(56, 189, 248, 0.08), transparent),
    var(--bg);
  z-index: var(--z-overlay);
  padding: var(--s-5);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  box-shadow: var(--shadow-lg);
}
.login-card .brand { padding: 0 0 var(--s-5); justify-content: center; }
.login-card h1 { font-size: 18px; margin: 0 0 var(--s-2); text-align: center; }
.login-card p.sub { color: var(--muted); text-align: center; margin: 0 0 var(--s-5); font-size: 13px; }
.login-error { color: var(--neg); font-size: 13px; margin-bottom: var(--s-3); min-height: 18px; }

/* ── Chart container ───────────────────────────────────────────────────── */
.chart { width: 100%; height: 280px; }
.chart-sm { height: 200px; }
.chart-lg { height: 360px; }

/* ── Chat bubbles ──────────────────────────────────────────────────────── */
.chat-msg { display: flex; margin-bottom: var(--s-4); }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 72%;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r);
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.55;
}
.chat-msg.user .chat-bubble { background: var(--accent-bg); border: 1px solid rgba(56, 189, 248, 0.25); }
.chat-msg.assistant .chat-bubble { background: var(--panel-2); border: 1px solid var(--border); }
.chat-tool {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin: var(--s-1) 0;
  padding-left: var(--s-3);
  border-left: 2px solid var(--border);
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  :root { --sidebar-w: 64px; }
  .brand .name, .brand .sub, .nav-item .label { display: none; }
  .brand { justify-content: center; padding: var(--s-4) 0; }
  .nav-item { justify-content: center; }
}
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
