:root {
  --sf-primary: #4f46e5;
  --sf-primary-600: #4338ca;
  --sf-accent: #0ea5e9;
  --sf-bg: #f5f6fb;
  --sf-surface: #ffffff;
  --sf-border: #e6e8f0;
  --sf-text: #1f2937;
  --sf-muted: #6b7280;
  --sf-sidebar: #111827;
  --sf-sidebar-2: #1f2937;
  --sf-radius: 14px;
  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79, 70, 229;
  --bs-link-color: #4f46e5;
  --bs-link-hover-color: #4338ca;
  --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
body { background: var(--sf-bg); color: var(--sf-text); font-size: .925rem; }
.btn-primary { --bs-btn-bg: var(--sf-primary); --bs-btn-border-color: var(--sf-primary); --bs-btn-hover-bg: var(--sf-primary-600); --bs-btn-hover-border-color: var(--sf-primary-600); --bs-btn-active-bg: var(--sf-primary-600); --bs-btn-disabled-bg: var(--sf-primary); --bs-btn-disabled-border-color: var(--sf-primary); }
.btn-outline-primary { --bs-btn-color: var(--sf-primary); --bs-btn-border-color: var(--sf-primary); --bs-btn-hover-bg: var(--sf-primary); --bs-btn-hover-border-color: var(--sf-primary); --bs-btn-active-bg: var(--sf-primary); }
.text-primary { color: var(--sf-primary) !important; }
.bg-primary-subtle { background: #eef0ff !important; }
.btn-ai { background: linear-gradient(135deg, #7c3aed, #4f46e5 55%, #0ea5e9); color: #fff; border: 0; }
.btn-ai:hover, .btn-ai:focus { color: #fff; filter: brightness(1.08); }
.btn-ai:disabled { color: #fff; opacity: .7; }
.btn-icon { border: 0; background: transparent; font-size: 1.35rem; padding: .25rem .5rem; }
.form-control, .form-select { border-color: var(--sf-border); }
.form-control:focus, .form-select:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .15); }
.form-label { font-weight: 500; font-size: .85rem; color: #374151; }

/* Layout */
.has-sidebar .main { margin-left: 250px; min-height: 100vh; display: flex; flex-direction: column; }
.sidebar { width: 250px; background: var(--sf-sidebar); color: #cbd5e1; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 1040; }
@media (max-width: 991.98px) { .has-sidebar .main { margin-left: 0; } .sidebar.offcanvas-lg { position: fixed; } }
@media (min-width: 992px) { .sidebar.offcanvas-lg { visibility: visible !important; transform: none !important; } }
.sidebar-brand { display: flex; align-items: center; padding: 1.1rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.06); }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #7c3aed, #4f46e5 55%, #0ea5e9); color: #fff; font-size: 1.05rem; }
.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.sidebar-nav { padding: .75rem .6rem; overflow-y: auto; flex: 1; }
.sidebar .nav-item { display: flex; align-items: center; gap: .75rem; padding: .55rem .75rem; color: #cbd5e1; text-decoration: none; border-radius: 10px; margin-bottom: 2px; font-weight: 500; }
.sidebar .nav-item i { font-size: 1.05rem; width: 20px; text-align: center; opacity: .85; }
.sidebar .nav-item:hover { background: var(--sf-sidebar-2); color: #fff; }
.sidebar .nav-item.active { background: rgba(99, 102, 241, .18); color: #fff; }
.sidebar .nav-item.active i { color: #a5b4fc; opacity: 1; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; padding: 1rem .75rem .35rem; }
.sidebar-foot { padding: .9rem 1rem; border-top: 1px solid rgba(255,255,255,.06); font-size: .8rem; }
.ai-status.on { color: #a7f3d0; }
.ai-status.off a { color: #fcd34d; }
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem; height: 62px; padding: 0 1.5rem; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--sf-border); }
.topbar-title { font-size: 1.1rem; font-weight: 600; }
.btn-user { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--sf-border); border-radius: 999px; padding: .2rem .7rem .2rem .25rem; background: #fff; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--sf-primary); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.content { padding: 1.5rem; flex: 1; }
@media (max-width: 575.98px) { .content { padding: 1rem; } .topbar { padding: 0 1rem; } }

/* Cards */
.card { border: 1px solid var(--sf-border); border-radius: var(--sf-radius); box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: transparent; border-bottom: 1px solid var(--sf-border); font-weight: 600; padding: .85rem 1.1rem; }
.card-body { padding: 1.1rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.4rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: .2rem 0 0; color: var(--sf-muted); }
.stat { display: flex; gap: .9rem; align-items: center; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--sf-muted); font-size: .8rem; }
.tile { display: block; text-decoration: none; color: inherit; transition: transform .12s, box-shadow .12s; height: 100%; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(16,24,40,.08); color: inherit; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--sf-muted); }
.empty i { font-size: 2.6rem; display: block; margin-bottom: .6rem; color: #c7d2fe; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--sf-muted); font-weight: 600; background: #fafbff; white-space: nowrap; }
.table-sm > :not(caption) > * > * { padding: .35rem .5rem; }
.badge-type { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.t-number { color: #0369a1; background: #e0f2fe; }
.t-date { color: #7c2d12; background: #ffedd5; }
.t-text { color: #374151; background: #f3f4f6; }
.t-period { color: #7c2d12; background: #ffedd5; }

/* Folders */
.folder-tree a { display: flex; align-items: center; gap: .5rem; padding: .4rem .6rem; border-radius: 8px; text-decoration: none; color: var(--sf-text); }
.folder-tree a:hover { background: #f3f4ff; }
.folder-tree a.active { background: #eef0ff; color: var(--sf-primary); font-weight: 600; }
.folder-tree .children { padding-left: 1rem; }
.folder-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.dropzone { border: 2px dashed #c7d2fe; border-radius: var(--sf-radius); background: #fafbff; padding: 1.6rem; text-align: center; color: var(--sf-muted); cursor: pointer; transition: background .15s, border-color .15s; }
.dropzone.drag { background: #eef0ff; border-color: var(--sf-primary); }
.file-icon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; font-size: 1.1rem; flex-shrink: 0; }

/* Widgets */
.widget { height: 100%; display: flex; flex-direction: column; }
.widget .card-header { display: flex; align-items: center; gap: .5rem; }
.widget .card-header .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.widget .tools { display: flex; gap: .15rem; opacity: .55; transition: opacity .15s; }
.widget:hover .tools { opacity: 1; }
.widget .tools .btn { padding: .1rem .35rem; border: 0; color: var(--sf-muted); }
.widget .tools .btn:hover { color: var(--sf-primary); background: #eef0ff; }
.widget .card-body { flex: 1; position: relative; min-height: 120px; }
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 360px; }
.kpi-value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi-sub { color: var(--sf-muted); font-size: .8rem; }
.kpi-delta.up { color: #059669; } .kpi-delta.down { color: #dc2626; }
.kpi-spark { height: 46px; margin-top: .5rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.kpi-mini { background: #fafbff; border: 1px solid var(--sf-border); border-radius: 12px; padding: .75rem .9rem; }
.kpi-mini .v { font-size: 1.3rem; font-weight: 700; }
.kpi-mini .l { font-size: .75rem; color: var(--sf-muted); }
.insight { background: linear-gradient(180deg, #faf5ff, #f5f7ff); border: 1px solid #e9d5ff; border-radius: 12px; padding: .75rem .9rem; font-size: .85rem; margin-top: .75rem; }
.insight .insight-head { font-weight: 600; color: #6d28d9; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .35rem; }
.insight ul { padding-left: 1.1rem; margin-bottom: .35rem; }
.insight p:last-child { margin-bottom: 0; }
.loading-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.6); z-index: 2; border-radius: inherit; }
.widget-error { color: #b91c1c; font-size: .85rem; }
.widget-table { max-height: 340px; overflow: auto; }
.sortable-ghost { opacity: .4; }
.drag-handle { cursor: grab; }

/* Model / idea editor */
.idea-box { border: 1px solid #ddd6fe; background: linear-gradient(180deg, #ffffff, #faf5ff); border-radius: var(--sf-radius); }
.idea-box textarea { border: 0; background: transparent; resize: vertical; font-size: 1rem; }
.idea-box textarea:focus { box-shadow: none; }
.formula { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
code.f { background: #f3f4ff; color: #4338ca; padding: .1rem .35rem; border-radius: 5px; }
.step-num { width: 26px; height: 26px; border-radius: 50%; background: #eef0ff; color: var(--sf-primary); display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem; margin-right: .4rem; }
.ai-thinking { display: inline-flex; gap: 4px; }
.ai-thinking span { width: 6px; height: 6px; background: currentColor; border-radius: 50%; animation: blink 1.2s infinite both; }
.ai-thinking span:nth-child(2) { animation-delay: .2s; } .ai-thinking span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

/* Decks */
.slide-thumb { border: 1px solid var(--sf-border); border-radius: 10px; padding: .6rem .7rem; background: #fff; cursor: pointer; margin-bottom: .5rem; display: flex; gap: .5rem; align-items: flex-start; }
.slide-thumb.active { border-color: var(--sf-primary); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.slide-thumb .num { font-weight: 700; color: var(--sf-muted); font-size: .8rem; min-width: 18px; }
.slide-canvas { aspect-ratio: 16 / 9; width: 100%; border-radius: 14px; overflow: hidden; position: relative; background: #fff; border: 1px solid var(--sf-border); }
.slide { position: absolute; inset: 0; padding: 4.5% 5.5%; display: flex; flex-direction: column; container-type: inline-size; }
.slide h2 { font-size: 4.2cqw; font-weight: 700; letter-spacing: -.02em; margin-bottom: 2.5cqw; }
.slide .body { font-size: 1.9cqw; line-height: 1.5; }
.slide .body ul { padding-left: 1.4em; }
.slide .slide-chart { flex: 1; min-height: 0; position: relative; }
.slide .slide-split { display: flex; gap: 3cqw; flex: 1; min-height: 0; }
.slide .slide-split > .slide-chart { flex: 1.7; }
.slide .slide-split > .body { flex: 1; overflow: hidden; }
.slide .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(20cqw, 1fr)); gap: 2cqw; }
.slide .kpi-mini { padding: 2cqw; } .slide .kpi-mini .v { font-size: 3.6cqw; } .slide .kpi-mini .l { font-size: 1.5cqw; }
.slide.layout-title, .slide.layout-closing { justify-content: center; color: #fff; }
.slide.layout-title h2 { font-size: 6cqw; } .slide.layout-title .body { font-size: 2.4cqw; opacity: .9; }
.slide .foot { position: absolute; bottom: 2.5%; left: 5.5%; right: 5.5%; display: flex; justify-content: space-between; font-size: 1.2cqw; color: #9ca3af; }
.theme-indigo .layout-title, .theme-indigo .layout-closing { background: linear-gradient(135deg, #312e81, #4f46e5 60%, #0ea5e9); }
.theme-indigo h2 { color: #1e1b4b; } .theme-indigo .layout-title h2, .theme-indigo .layout-closing h2 { color: #fff; }
.theme-emerald .layout-title, .theme-emerald .layout-closing { background: linear-gradient(135deg, #064e3b, #059669 60%, #34d399); }
.theme-emerald h2 { color: #064e3b; } .theme-emerald .layout-title h2, .theme-emerald .layout-closing h2 { color: #fff; }
.theme-slate .slide { background: #0f172a; color: #e2e8f0; } .theme-slate h2 { color: #fff; }
.theme-slate .layout-title, .theme-slate .layout-closing { background: radial-gradient(circle at 20% 20%, #334155, #0f172a); }
.theme-slate .kpi-mini { background: #1e293b; border-color: #334155; } .theme-slate .kpi-mini .l { color: #94a3b8; }
.theme-sunset .layout-title, .theme-sunset .layout-closing { background: linear-gradient(135deg, #7c2d12, #ea580c 55%, #f59e0b); }
.theme-sunset h2 { color: #7c2d12; } .theme-sunset .layout-title h2, .theme-sunset .layout-closing h2 { color: #fff; }
body.present { background: #000; overflow: hidden; }
.present-stage { position: fixed; inset: 0; display: grid; place-items: center; }
.present-stage .slide-canvas { width: min(100vw, calc(100vh * 16 / 9)); border: 0; border-radius: 0; }
.present-bar { position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(17,24,39,.85); color: #fff; border-radius: 999px; padding: .35rem .5rem; display: flex; gap: .25rem; align-items: center; opacity: 0; transition: opacity .2s; z-index: 10; }
body.present:hover .present-bar { opacity: 1; }
.present-bar .btn { color: #fff; }

/* Guest / auth */
.guest { background: radial-gradient(circle at 15% 10%, #e0e7ff, transparent 40%), radial-gradient(circle at 90% 90%, #e0f2fe, transparent 40%), var(--sf-bg); }
.guest-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; }

/* Markdown */
.md h1, .md h2, .md h3 { font-size: 1rem; font-weight: 700; margin: .6rem 0 .3rem; }
.md ul, .md ol { padding-left: 1.2rem; margin-bottom: .5rem; }
.md p { margin-bottom: .5rem; }

/* Print (reports & decks to PDF) */
@media print {
  .sidebar, .topbar, .no-print, .toast-container, .widget .tools { display: none !important; }
  .has-sidebar .main { margin: 0; }
  .content { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
  .print-slide { page-break-after: always; break-after: page; }
  @page { margin: 12mm; }
}
@media print { .deck-print .slide-canvas { border: 0; border-radius: 0; } @page deck { size: landscape; } }

/* ---------- Mobile / all displays ---------- */
.min-w-0 { min-width: 0; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; display: flex; background: #fff; border-top: 1px solid var(--sf-border); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 16px rgba(16,24,40,.06); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .4rem; color: var(--sf-muted); text-decoration: none; font-size: .68rem; font-weight: 500; }
.tabbar a i { font-size: 1.25rem; }
.tabbar a.active { color: var(--sf-primary); }
@media (max-width: 991.98px) {
  .has-sidebar .content { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .toast-container { bottom: 70px !important; }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
}
@media (max-width: 575.98px) {
  body { font-size: .9rem; }
  .page-head h1 { font-size: 1.2rem; }
  .page-head > div:last-child { width: 100%; }
  .chart-box { height: 230px; } .chart-box.tall { height: 280px; }
  .kpi-value { font-size: 1.6rem; }
  .card-body { padding: .9rem; }
  .table { font-size: .85rem; }
  .btn-user .dropdown-toggle::after { display: none; }
  .modal-dialog:not(.modal-fullscreen-lg-down) { margin: .5rem; }
}
@media (min-width: 1600px) {
  .content { padding: 2rem 2.5rem; }
  .chart-box { height: 320px; } .chart-box.tall { height: 420px; }
}
@media (min-width: 2200px) { body { font-size: 1rem; } .chart-box { height: 380px; } }
@media (hover: none) { .widget .tools { opacity: 1; } }
@media print { .tabbar { display: none !important; } .content { padding-bottom: 0 !important; } }
