/* ==========================================================================
   FinCore (fincore365.eu) – Design System (Light & Dark Theme)
   ========================================================================== */
:root,
[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elev: #0f1729;
  --surface: #131c30;
  --surface-2: #1a2540;
  --surface-3: #22304f;
  --sidebar-bg: linear-gradient(180deg, #0d1527 0%, #090f1d 100%);
  --topbar-bg: rgba(11, 18, 32, 0.84);
  --border: #25324d;
  --border-strong: #34456a;
  --text: #e8eef9;
  --text-soft: #c4cee3;
  --muted: #8b9bb8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --accent-ink: #062a40;
  --accent-soft: rgba(56, 189, 248, 0.13);
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --violet: #a78bfa;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
  --badge-ok-bg: rgba(34, 197, 94, 0.14);
  --badge-ok-fg: #86efac;
  --badge-warn-bg: rgba(245, 158, 11, 0.15);
  --badge-warn-fg: #fcd34d;
  --badge-err-bg: rgba(239, 68, 68, 0.16);
  --badge-err-fg: #fca5a5;
  --badge-info-bg: rgba(56, 189, 248, 0.14);
  --badge-info-fg: #7dd3fc;
  --badge-violet-bg: rgba(139, 92, 246, 0.18);
  --badge-violet-fg: #ddd6fe;
  --badge-muted-bg: rgba(148, 163, 184, 0.14);
  --badge-muted-fg: #cbd5e1;
}

[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f8;
  --sidebar-bg: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.9);
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-2: #6d5dfc;
  --accent-ink: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --violet: #6d5dfc;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 25px rgba(15, 23, 42, 0.1);
  --badge-ok-bg: #dcfce7;
  --badge-ok-fg: #166534;
  --badge-warn-bg: #fef3c7;
  --badge-warn-fg: #92400e;
  --badge-err-bg: #fee2e2;
  --badge-err-fg: #991b1b;
  --badge-info-bg: #dbeafe;
  --badge-info-fg: #1e40af;
  --badge-violet-bg: #ede9fe;
  --badge-violet-fg: #5b21b6;
  --badge-muted-bg: #f1f5f9;
  --badge-muted-fg: #475569;
}

:root {
  --sidebar-w: 252px;
  --topbar-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin-top: 0; letter-spacing: -0.01em; line-height: 1.25; }
code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 0.06rem 0.35rem;
  border-radius: 5px;
}

/* ---------- Shell & Sidebar ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--sidebar-bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 60; overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 1.05rem 1.15rem; border-bottom: 1px solid var(--border); color: var(--text);
}
.sidebar-brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #2563eb, #6d5dfc);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3);
}
.brand-title { font-weight: 750; font-size: 1.06rem; line-height: 1.15; }
.brand-title span { color: var(--accent); }
.brand-sub { display: block; font-size: 0.7rem; color: var(--muted); font-weight: 500; margin-top: 2px; }
.sidebar-section {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); padding: 1.05rem 1.2rem 0.35rem;
}
.nav { display: flex; flex-direction: column; gap: 2px; padding: 0.3rem 0.7rem; }
.nav a, .nav .nav-btn {
  display: flex; align-items: center; gap: 0.68rem;
  padding: 0.56rem 0.8rem; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 550; font-size: 0.92rem;
  border: 1px solid transparent; background: transparent;
  width: 100%; text-align: left; cursor: pointer; font-family: inherit;
}
.nav a svg, .nav .nav-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav a:hover, .nav .nav-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(56, 189, 248, 0.22); font-weight: 650; }
.sidebar-spacer { flex: 1; }
.sidebar-foot { padding: 0.6rem 0.7rem 1rem; border-top: 1px solid var(--border); }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(2, 6, 16, 0.55); z-index: 55;
}
body.sidebar-open .sidebar-backdrop { display: block; }

.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 1.5rem;
  background: var(--topbar-bg); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-title { font-size: 1.05rem; font-weight: 650; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.menu-toggle {
  display: none; width: 40px; height: 40px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; place-items: center; padding: 0;
}
.menu-toggle svg { width: 20px; height: 20px; }
.company-select { min-width: 170px; max-width: 240px; padding: 0.35rem 2rem 0.35rem 0.65rem !important; font-size: 0.86rem !important; font-weight: 600; }
.theme-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center; font-size: 1rem;
}
.theme-btn:hover { background: var(--surface-3); }

.container { width: 100%; max-width: 1460px; margin: 0 auto; padding: 1.4rem 1.5rem 0.5rem; flex: 1; }

/* ---------- Grids, Cards, KPI ---------- */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-3-1 { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(260px, 1fr); gap: 1.25rem; margin-bottom: 1.25rem; }
.grid-1-2 { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(0, 2.2fr); gap: 1.25rem; margin-bottom: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.35rem; margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.grid-4 > .card, .grid-2 > .card, .grid-3-1 > .card, .grid-1-2 > .card { margin-bottom: 0; }
.card h2 { font-size: 1.06rem; font-weight: 650; margin: 0 0 0.75rem; }
.card h3 { font-size: 0.96rem; font-weight: 650; margin: 0 0 0.6rem; }
.kpi-card { position: relative; overflow: hidden; }
.kpi-card::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.stat-label { color: var(--muted); font-size: 0.73rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 1.85rem; font-weight: 750; color: var(--text); margin: 0.25rem 0 0.15rem; letter-spacing: -0.02em; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.table-wrap > table { min-width: 600px; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.68rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  color: var(--muted); font-weight: 650; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--surface-2); border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--accent-soft); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Tabs & Badges ---------- */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.tab-link {
  display: inline-flex; align-items: center; gap: 0.38rem;
  padding: 0.38rem 0.8rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 0.82rem; font-weight: 600;
}
.tab-link:hover { color: var(--text); text-decoration: none; border-color: var(--border-strong); }
.tab-link.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.16rem 0.6rem; border-radius: 999px;
  font-size: 0.73rem; font-weight: 650; white-space: nowrap;
}
.badge-ok { background: var(--badge-ok-bg); color: var(--badge-ok-fg); }
.badge-warn { background: var(--badge-warn-bg); color: var(--badge-warn-fg); }
.badge-err { background: var(--badge-err-bg); color: var(--badge-err-fg); }
.badge-info { background: var(--badge-info-bg); color: var(--badge-info-fg); }
.badge-violet { background: var(--badge-violet-bg); color: var(--badge-violet-fg); }
.badge-muted { background: var(--badge-muted-bg); color: var(--badge-muted-fg); }

/* ---------- Buttons & Forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.48rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font-family: inherit; font-size: 0.88rem; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); font-weight: 650; }
.btn-danger { background: var(--badge-err-bg); color: var(--badge-err-fg); border-color: rgba(239, 68, 68, 0.35); }
.btn-sm { padding: 0.28rem 0.68rem; font-size: 0.8rem; border-radius: 7px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 0.85rem 1rem; }
label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 0.28rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="email"],
input[type="date"], select, textarea {
  width: 100%; padding: 0.5rem 0.7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-family: inherit; font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }

/* ---------- Charts & Trees ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 0.75rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 4px; }
.bar-pair { display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; height: 120px; }
.bar-rev { width: 40%; max-width: 16px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 3px; }
.bar-cost { width: 40%; max-width: 16px; border-radius: 4px 4px 0 0; background: var(--accent-2); min-height: 3px; opacity: 0.85; }
.bar-lbl { font-size: 0.7rem; color: var(--muted); }

.wh-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0.75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 0.45rem; color: var(--text);
}
.wh-item:hover { background: var(--surface-3); text-decoration: none; }
.wh-item.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 650; }

.report-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 0.9rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); margin-bottom: 0.55rem;
}
.report-link:hover { border-color: var(--accent); text-decoration: none; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 2rem; background: var(--surface); border-top: 1px solid var(--border);
  padding: 1.5rem; color: var(--muted); font-size: 0.82rem;
}
.footer-inner {
  max-width: 1460px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.75rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1060px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow-md); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .menu-toggle { display: grid; }
  .grid-3-1, .grid-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 0.85rem; }
  .container { padding: 1rem 0.85rem; }
  .card { padding: 1rem; }
  .company-select { min-width: 120px; max-width: 165px; }
  input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea { font-size: 16px; min-height: 42px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
}

/* ---------- Print / PDF preview ---------- */
@media print {
  .sidebar, .topbar, .site-footer, .no-print { display: none !important; }
  .app-main { margin-left: 0 !important; }
  body { background: #ffffff !important; color: #000000 !important; }
  .card { border: 1px solid #cbd5e1 !important; box-shadow: none !important; background: #ffffff !important; color: #000000 !important; page-break-inside: avoid; }
}
