/* ===== TOKENS ===== */
:root {
  --bg: #0b0c14;
  --surface: #10111c;
  --surface-2: #181924;
  --surface-hover: #1e2030;
  --border: #232540;
  --border-light: #191a2e;
  --text: #eeeef4;
  --text-2: #9899b8;
  --muted: #565778;
  --accent: #2762F2;
  --accent-hover: #1a52e0;
  --accent-dim: rgba(39,98,242,0.12);
  --success: #22c55e;
  --success-dim: rgba(34,197,94,0.1);
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.1);
  --warning: #f59e0b;
  --warning-dim: rgba(245,158,11,0.1);
  --red: var(--danger);
  --green: var(--success);
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --bnav-h: 60px;
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 2px 8px rgba(0,0,0,0.5), 0 8px 32px rgba(0,0,0,0.3);
  --font-h: 'Syne', sans-serif;
  --font: 'DM Sans', sans-serif;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3 { font-family: var(--font-h); letter-spacing: -0.02em; line-height: 1.2; color: var(--text); }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { color: var(--text-2); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; flex-shrink: 0; }
button { font-family: var(--font); }

/* ===== LAYOUT ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 50;
  transition: transform 0.22s cubic-bezier(0.4,0,0.2,1);
}
.sb-brand {
  padding: 18px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sb-brand-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #0e0e14;
  flex-shrink: 0;
}
.sb-brand-name {
  font-family: var(--font-h);
  font-size: 17px; font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.sb-section {
  padding: 14px 10px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.sb-nav {
  flex: 1;
  padding: 8px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  transition: background 0.1s, color 0.1s;
  border: none; background: transparent;
  width: 100%; text-align: left;
  user-select: none;
}
.sb-item:hover { background: var(--surface-hover); color: var(--text-2); }
.sb-item.active { background: var(--accent-dim); color: var(--accent); }
.sb-item.active svg { opacity: 1; }
.sb-item svg { opacity: 0.6; }
.sb-user {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.sb-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
  font-family: var(--font-h);
  border: 1px solid rgba(245,166,35,0.2);
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 1px; }
.sb-logout {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 5px; border-radius: 6px;
  display: flex; align-items: center;
  transition: color 0.1s, background 0.1s;
  flex-shrink: 0;
}
.sb-logout:hover { color: var(--danger); background: var(--danger-dim); }

/* ===== CONTENT ===== */
.content-wrap {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 14px;
  background: var(--surface);
  position: sticky; top: 0; z-index: 40;
}
.menu-btn {
  display: none; background: none; border: none;
  color: var(--text-2); cursor: pointer;
  padding: 4px; border-radius: 6px;
  align-items: center; justify-content: center;
  transition: background 0.1s;
}
.menu-btn:hover { background: var(--surface-2); }
.page-title { font-family: var(--font-h); font-size: 16px; font-weight: 700; color: var(--text); }
.main { flex: 1; padding: 24px; max-width: 1280px; width: 100%; }

/* ===== OVERLAY ===== */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 45;
  backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bnav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  overflow-x: auto; scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar { display: none; }
.bottom-nav { display: none; align-items: stretch; }
.bnav-item {
  flex: 1; min-width: 56px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; background: none; border: none;
  color: var(--muted); cursor: pointer;
  padding: 6px 4px;
  font-size: 10px; font-weight: 500;
  transition: color 0.1s;
  white-space: nowrap;
}
.bnav-item.active { color: var(--accent); }
.bnav-item svg { width: 20px; height: 20px; }

/* ===== CARD ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 24px;
  margin-bottom: 14px;
}
.card-header {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 18px; gap: 12px;
}
.card-header h2 { margin: 0; }

/* ===== KPI ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 12px; margin-bottom: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  position: relative; overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent);
  opacity: 0.4;
}
.kpi-card.accent::before { opacity: 1; }
.kpi-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-h);
  font-size: 24px; font-weight: 700;
  color: var(--text); letter-spacing: -0.03em; line-height: 1;
}
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi-success .kpi-value { color: var(--success); }
.kpi-danger .kpi-value { color: var(--danger); }
.kpi-accent .kpi-value { color: var(--accent); }

/* Progress bar */
.progress-wrap {
  margin-top: 12px; height: 3px;
  background: var(--surface-2); border-radius: 99px; overflow: hidden;
}
.progress-bar { height: 100%; border-radius: 99px; transition: width 0.5s ease; }

/* Budget cards */
.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px; margin-bottom: 0;
}
.budget-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
}
.budget-item-name {
  font-weight: 600; font-size: 13px; color: var(--text);
  margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.budget-item-row {
  display: flex; align-items: baseline;
  justify-content: space-between; gap: 6px;
  margin-bottom: 8px;
}
.budget-item-spent { font-size: 16px; font-weight: 700; font-family: var(--font-h); color: var(--text); }
.budget-item-total { font-size: 12px; color: var(--muted); }
.budget-item-sub { font-size: 11px; font-weight: 600; margin-top: 6px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0 0 var(--r-lg) var(--r-lg); }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td {
  text-align: left; padding: 12px 14px; font-size: 14px;
  border-bottom: 1px solid var(--border-light); color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover td { background: var(--surface-hover); }
td.muted { color: var(--muted); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; font-size: 11px; font-weight: 600;
  border-radius: 99px; text-transform: uppercase; letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-green { background: var(--success-dim); color: var(--success); }
.badge-orange { background: var(--warning-dim); color: var(--warning); }
.badge-gray { background: rgba(96,96,122,0.15); color: var(--muted); }
.badge-blue { background: rgba(99,102,241,0.12); color: #a5b4fc; }
.badge-amber { background: var(--accent-dim); color: var(--accent); }

/* ===== FORMS ===== */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 150px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-2); }
input, select, textarea {
  font-family: var(--font); font-size: 14px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 9px 12px;
  outline: none; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
select { cursor: pointer; }
select option { background: var(--surface-2); }
textarea { min-height: 72px; resize: vertical; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); cursor: pointer; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font); font-size: 14px; font-weight: 600;
  border: 1px solid transparent; border-radius: 99px;
  padding: 8px 18px; cursor: pointer;
  background: var(--accent); color: #0e0e14;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: transparent; color: var(--text-2); border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-secondary {
  background: transparent; color: var(--accent); border-color: var(--accent);
}
.btn-secondary:hover { background: var(--accent-dim); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ===== LOGIN ===== */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 40% at 50% -5%, rgba(245,166,35,0.07), transparent),
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 100% 100%, 36px 36px, 36px 36px;
  padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 36px 40px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  width: 46px; height: 46px; background: var(--accent);
  border-radius: 13px; display: flex; align-items: center;
  justify-content: center; margin: 0 auto 20px; color: #0e0e14;
}
.login-card h1 { text-align: center; margin-bottom: 6px; font-size: 22px; }
.login-card > p { text-align: center; margin-bottom: 24px; font-size: 13px; }

/* ===== MODAL ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 28px;
  width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { margin-bottom: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end;
  gap: 8px; margin-top: 20px;
}

/* ===== FILTER BAR ===== */
.filter-bar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 20px; margin-bottom: 14px;
}
.filter-bar .form-row { margin-bottom: 0; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 200; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 11px 16px; border-radius: var(--r);
  box-shadow: var(--shadow); font-size: 14px; max-width: 320px;
  animation: fadeUp 0.2s ease;
}
.toast.error { border-color: var(--danger); color: #fca5a5; background: var(--danger-dim); }
.toast.success { border-color: var(--success); color: #86efac; background: var(--success-dim); }
@keyframes fadeUp {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ===== UTILS ===== */
.error-text { color: var(--danger); font-size: 13px; margin-top: 6px; }
.muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.fw-600 { font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }
.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px;
}
.checkbox-grid label {
  font-size: 13px; display: flex; align-items: center; gap: 7px;
  cursor: pointer; color: var(--text-2);
}
.section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--muted); margin-bottom: 10px;
}
.empty {
  text-align: center; padding: 40px 20px; color: var(--muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .content-wrap { margin-left: 0; }
  .topbar { padding: 0 14px; }
  .menu-btn { display: flex; }
  .bottom-nav { display: flex; }
  .main { padding: 14px; padding-bottom: calc(var(--bnav-h) + 16px); }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 14px 16px; }
  .kpi-value { font-size: 20px; }
  .card { padding: 14px 16px; border-radius: var(--r); }
  .modal { padding: 20px; }
  .form-row { flex-direction: column; gap: 10px; }
  .field { min-width: 100%; }
  .toast-container { bottom: calc(var(--bnav-h) + 10px); right: 12px; left: 12px; }
  .toast { max-width: 100%; }
  .card-header { flex-wrap: wrap; gap: 10px; }
  .budget-grid { grid-template-columns: 1fr 1fr; }
  .login-card { padding: 28px 24px; }
}
@media (max-width: 480px) {
  .budget-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
