:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-2: #4338ca;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar: #111827;
  --sidebar-muted: #94a3b8;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #1f2937;
  --border: #243244;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-2: #4f46e5;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar: #030712;
  --sidebar-muted: #64748b;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #e2e8f0;
  padding: 24px 16px;
  border-right: 1px solid rgba(255,255,255,.06);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: linear-gradient(145deg, #6366f1, #4f46e5);
}
.brand-title { font-size: 15px; font-weight: 700; color: #fff; margin: 0; }
.brand-subtitle { font-size: 12px; color: var(--sidebar-muted); margin: 0; }

.menu { display: flex; flex-direction: column; gap: 6px; }
.menu-label {
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: #64748b; margin: 12px 10px 6px;
}
.menu-label.mt { margin-top: 18px; }

.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: #cbd5e1; font-weight: 500;
}
.menu-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.menu-item.active {
  background: rgba(99,102,241,.22); color: #fff; border: 1px solid rgba(99,102,241,.45);
}

.content { padding: 24px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px;
}
h1 { font-size: 24px; line-height: 1.2; font-weight: 700; margin: 0; }
.topbar-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.topbar-actions { display: flex; gap: 10px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: transparent; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; margin: 0 0 8px; }
.card h3 { font-size: 22px; line-height: 1.25; font-weight: 700; margin: 0 0 7px; }
.stat-meta { font-size: 12px; color: var(--muted); margin: 0; }
.positive { color: var(--success); font-weight: 600; }
.negative { color: var(--danger); font-weight: 600; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel h2 { font-size: 16px; font-weight: 700; margin: 0; }
.link { color: var(--primary); font-weight: 600; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 700px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
th { color: var(--muted); font-weight: 600; }
.text-right { text-align: right; }

.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge.success { color: #065f46; background: #d1fae5; }
.badge.warning { color: #92400e; background: #fef3c7; }
.badge.danger { color: #7f1d1d; background: #fee2e2; }

.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text); padding: 10px 12px; font-size: 13px;
}
.textarea { min-height: 100px; resize: vertical; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; background:
  radial-gradient(circle at 20% 10%, rgba(99,102,241,.18), transparent 35%),
  radial-gradient(circle at 80% 90%, rgba(14,165,233,.14), transparent 28%),
  var(--bg);
  padding: 16px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-top: 0; }
.login-actions { display: flex; gap: 10px; margin-top: 14px; }
.login-actions .btn { flex: 1; }

@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-actions { width: 100%; }
  .btn { width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
}

/* Sidebar polish + collapsible submenu */
.sidebar {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, .55) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(99,102,241,.7), rgba(148,163,184,.42));
  border-radius: 999px;
  border: 2px solid var(--sidebar);
}
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, .75); }

.submenu-toggle {
  width: 100%;
  border: 0;
  background: transparent;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px 6px;
  margin-top: 10px;
  cursor: pointer;
  font: inherit;
}
.submenu-toggle span:first-child {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.submenu-toggle .chevron { transition: transform .18s ease; font-size: 12px; }
.submenu-toggle.collapsed .chevron { transform: rotate(-90deg); }
.submenu { display: grid; gap: 6px; overflow: hidden; transition: max-height .22s ease, opacity .18s ease; max-height: 900px; opacity: 1; }
.submenu.collapsed { max-height: 0; opacity: 0; }
.menu-item.child { padding-left: 20px; font-size: 13px; }
.menu-item.child span { opacity: .9; }

.action-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.action-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.action-card h3 { margin: 0 0 6px; font-size: 15px; }
.action-card p { margin: 0; color: var(--muted); font-size: 13px; }
.danger-zone { border-color: rgba(220, 38, 38, .35); }
.delete-box { background: rgba(220, 38, 38, .06); border: 1px solid rgba(220, 38, 38, .25); border-radius: 14px; padding: 16px; }

@media (max-width: 900px) { .action-grid { grid-template-columns: 1fr; } }

/* SaaS + avatar support */
.user-mini {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  background: rgba(255,255,255,.045);
  margin-bottom: 18px;
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.18);
  background: linear-gradient(145deg, #6366f1, #06b6d4);
}
.avatar-lg { width: 84px; height: 84px; }
.user-mini-name { margin: 0; font-size: 13px; font-weight: 700; color: #fff; }
.user-mini-role { margin: 0; font-size: 11px; color: #94a3b8; }
.menu-item i { width: 18px; text-align: center; opacity: .95; }
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.profile-upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.metric-split {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 14px;
}
.timeline { display: grid; gap: 12px; }
.timeline-item { display: flex; gap: 10px; align-items: flex-start; }
.timeline-dot { width: 9px; height: 9px; border-radius: 999px; background: var(--primary); margin-top: 6px; }
.timeline-item p { margin: 0; color: var(--muted); font-size: 13px; }
.timeline-item strong { color: var(--text); }
@media (max-width: 900px) { .metric-split { grid-template-columns: 1fr; } .profile-header { align-items: flex-start; flex-direction: column; } }

/* Dashboard infographic chart */
.chart-bars { height: 260px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 18px; align-items: end; padding: 16px 6px 4px; }
.chart-bars div { height: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; align-items: end; position: relative; padding-bottom: 24px; }
.chart-bars span, .chart-bars em { display: block; border-radius: 999px 999px 6px 6px; min-height: 18px; }
.chart-bars span { background: linear-gradient(180deg, var(--primary), #818cf8); }
.chart-bars em { background: linear-gradient(180deg, #f97316, #fb923c); }
.chart-bars small { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); color: var(--muted); font-size: 12px; }
@media (max-width: 640px) { .chart-bars { gap: 10px; height: 210px; } }

/* Dashboard polish */
.dashboard-hero .card { position: relative; overflow: hidden; }
.dashboard-hero .card::after { content:""; position:absolute; right:-34px; top:-34px; width:110px; height:110px; border-radius:999px; background: rgba(99,102,241,.09); }
.dashboard-grid { display:grid; grid-template-columns: minmax(0,2fr) minmax(280px,1fr); gap:14px; margin-bottom:18px; }
.dashboard-grid.lower { grid-template-columns: minmax(0,1.35fr) minmax(0,1fr); }
.dashboard-main { min-height:320px; }
.legend { display:flex; align-items:center; gap:8px; color:var(--muted); font-size:12px; font-weight:600; }
.income-dot,.expense-dot { display:inline-block; width:10px; height:10px; border-radius:999px; }
.income-dot { background:var(--primary); }
.expense-dot { background:var(--warning); }
.dynamic-chart { height:240px; align-items:end; padding-top:8px; }
.dynamic-chart div { min-height:220px; }
.dynamic-chart span { background: linear-gradient(180deg, var(--primary), rgba(99,102,241,.45)); }
.dynamic-chart em { background: linear-gradient(180deg, var(--warning), rgba(245,158,11,.35)); }
.automation-list { display:grid; gap:10px; }
.automation-list a { display:flex; align-items:center; gap:12px; padding:12px; border:1px solid var(--border); border-radius:12px; background:var(--surface-2); }
.automation-list strong { width:42px; height:42px; border-radius:12px; display:grid; place-items:center; color:#fff; background:linear-gradient(145deg,var(--primary),var(--primary-2)); font-size:18px; }
.automation-list span { color:var(--muted); font-weight:600; }
.alert-list { display:grid; gap:10px; }
.alert-item { display:block; padding:12px; border:1px solid var(--border); border-left-width:4px; border-radius:12px; background:var(--surface-2); }
.alert-item strong { display:block; margin-bottom:3px; }
.alert-item span { color:var(--muted); font-size:12px; }
.alert-item.danger { border-left-color:var(--danger); }
.alert-item.warning { border-left-color:var(--warning); }
.alert-item.info { border-left-color:var(--primary); }
@media (max-width: 1100px) { .dashboard-grid, .dashboard-grid.lower { grid-template-columns: 1fr; } }

/* Professional infographic system */
:root {
  --accent-blue:#2563eb; --accent-cyan:#0891b2; --accent-violet:#7c3aed; --accent-rose:#e11d48;
  --glass: rgba(255,255,255,.72);
}
:root[data-theme="dark"] { --glass: rgba(17,24,39,.72); }
.content { background:
  radial-gradient(circle at 12% 0%, rgba(79,70,229,.08), transparent 26%),
  radial-gradient(circle at 88% 12%, rgba(8,145,178,.07), transparent 24%);
}
.topbar { background: var(--glass); backdrop-filter: blur(16px); border:1px solid var(--border); border-radius:20px; padding:16px 18px; box-shadow: var(--shadow); }
.card.metric-card, .stats-grid .card { position:relative; overflow:hidden; border-radius:18px; background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 86%, var(--primary) 14%)); }
.card.metric-card::before, .stats-grid .card::before { content:""; position:absolute; inset:0 0 auto 0; height:4px; background:linear-gradient(90deg,var(--primary),var(--accent-cyan)); }
.card.metric-card::after, .stats-grid .card::after { content:""; position:absolute; right:-28px; bottom:-42px; width:130px; height:130px; border-radius:999px; background:rgba(99,102,241,.08); pointer-events:none; }
.stat-label { text-transform:uppercase; letter-spacing:.04em; }
.card h3 { font-size: clamp(20px,2.1vw,30px); letter-spacing:-.03em; }
.panel { border-radius:18px; }
.panel-head h2 { display:flex; align-items:center; gap:8px; }
.panel-head h2::before { content:""; width:10px; height:22px; border-radius:999px; background:linear-gradient(180deg,var(--primary),var(--accent-cyan)); display:inline-block; }
.insight-grid { display:grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap:14px; }
.insight-card { display:flex; align-items:center; gap:14px; border:1px solid var(--border); border-radius:16px; padding:15px; background:linear-gradient(145deg,var(--surface),var(--surface-2)); }
.insight-card strong { display:block; font-size:16px; }
.insight-card small { display:block; color:var(--muted); margin-top:3px; }
.insight-icon { width:44px; height:44px; border-radius:14px; display:grid; place-items:center; color:#fff; background:linear-gradient(145deg,var(--primary),var(--accent-violet)); box-shadow:0 12px 26px rgba(79,70,229,.22); }
.insight-icon.green { background:linear-gradient(145deg,#16a34a,#22c55e); box-shadow:0 12px 26px rgba(22,163,74,.20); }
.insight-icon.orange { background:linear-gradient(145deg,#f97316,#f59e0b); box-shadow:0 12px 26px rgba(249,115,22,.20); }
.success-panel { border-color:rgba(22,163,74,.28); background:linear-gradient(145deg,var(--surface),rgba(22,163,74,.08)); }
.table-wrap table { border-collapse:separate; border-spacing:0; }
th { background:var(--surface-2); position:sticky; top:0; z-index:1; }
th:first-child { border-top-left-radius:12px; }
th:last-child { border-top-right-radius:12px; }
tbody tr { transition: background .15s ease, transform .15s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 78%, var(--primary) 22%); }
.badge { border:1px solid transparent; }
.badge.success { border-color:rgba(22,163,74,.18); }
.badge.warning { border-color:rgba(217,119,6,.18); }
.badge.danger { border-color:rgba(220,38,38,.18); }
.chart-bars { border-radius:18px; background:
  linear-gradient(to top, rgba(148,163,184,.13) 1px, transparent 1px) 0 0/100% 20%,
  linear-gradient(145deg,var(--surface),var(--surface-2));
  border:1px solid var(--border); padding:22px 18px 8px;
}
.chart-bars span, .chart-bars em { box-shadow:0 12px 22px rgba(15,23,42,.10); }
.progress-strip { height:10px; border-radius:999px; background:var(--surface-2); overflow:hidden; }
.progress-strip > span { display:block; height:100%; border-radius:inherit; background:linear-gradient(90deg,var(--primary),var(--accent-cyan)); }
@media (max-width: 900px) { .insight-grid { grid-template-columns:1fr; } .topbar { align-items:flex-start; } }

/* Portal + executive infographic v2 */
.portal-shell { width:100%; display:grid; gap:16px; }
.portal-hero { display:flex; align-items:center; justify-content:space-between; gap:18px; color:#fff; padding:28px; border-radius:26px; background:
  radial-gradient(circle at 15% 20%, rgba(255,255,255,.24), transparent 24%),
  linear-gradient(135deg,#1e1b4b,#4f46e5 52%,#0891b2); box-shadow:0 24px 60px rgba(30,27,75,.28); overflow:hidden; position:relative; }
.portal-hero::after { content:""; position:absolute; right:-80px; top:-80px; width:220px; height:220px; border-radius:999px; border:34px solid rgba(255,255,255,.11); }
.portal-hero h1 { font-size:clamp(28px,5vw,48px); letter-spacing:-.05em; margin:4px 0 6px; }
.portal-hero p { margin:0; color:rgba(255,255,255,.82); }
.eyebrow { text-transform:uppercase; font-size:12px; font-weight:800; letter-spacing:.12em; color:rgba(255,255,255,.72)!important; }
.portal-badge { display:flex; align-items:center; gap:10px; position:relative; z-index:1; padding:12px 16px; border-radius:999px; background:rgba(255,255,255,.14); border:1px solid rgba(255,255,255,.22); backdrop-filter: blur(14px); font-weight:700; }
.executive-strip { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; }
.executive-tile { padding:16px; border-radius:18px; background:linear-gradient(145deg,var(--surface),var(--surface-2)); border:1px solid var(--border); position:relative; overflow:hidden; }
.executive-tile::after { content:""; position:absolute; right:-35px; top:-35px; width:92px; height:92px; border-radius:999px; background:rgba(99,102,241,.10); }
.executive-tile strong { display:block; font-size:22px; letter-spacing:-.03em; }
.executive-tile span { color:var(--muted); font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.04em; }
@media (max-width:900px){ .portal-hero{align-items:flex-start; flex-direction:column;} .executive-strip{grid-template-columns:1fr;} }

.log-box { max-height:420px; overflow:auto; white-space:pre-wrap; word-break:break-word; border:1px solid var(--border); border-radius:16px; background:linear-gradient(145deg,#020617,#111827); color:#d1fae5; padding:16px; font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace; font-size:12px; line-height:1.55; }
