*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #0A0A0F;
  --ink2: #0E0E15;
  --card: #16161F;
  --card2: #1B1B27;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #D4D4E8;
  --muted: #8484A8;
  --white: #fff;
  --p: #8B5CF6;
  --p2: #A78BFA;
  --pk: #EC4899;
  --g: linear-gradient(135deg, #8B5CF6, #EC4899);
  --g2: linear-gradient(135deg, rgba(139,92,246,.16), rgba(236,72,153,.10));
  --green: #10B981;
  --amber: #F59E0B;
  --red: #EF4444;
  --shadow: 0 8px 24px rgba(0,0,0,0.28);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.4);
  --hover: rgba(255,255,255,0.04);
  --wash: rgba(255,255,255,0.05);
  --card-hover: #22222f;

  /* One accent per sidebar topic, so each category reads as its own colour
     even collapsed — reuses the brand purple/amber where a topic already
     has a natural fit (Finance/Reports). */
  --topic-ops: #60A5FA;
  --topic-finance: var(--p);
  --topic-hr: #FB7185;
  --topic-reports: var(--amber);
}

:root[data-theme="light"] {
  --ink: #F3F3F8;
  --ink2: #FFFFFF;
  --card: #FFFFFF;
  --card2: #F5F5FA;
  --border: rgba(20,20,40,0.08);
  --border2: rgba(20,20,40,0.14);
  --text: #3A3A55;
  --muted: #6E6E8F;
  --white: #14142A;
  --green: #059669;
  --amber: #B45309;
  --red: #DC2626;
  --shadow: 0 4px 16px rgba(30,20,60,0.07);
  --shadow-lg: 0 12px 32px rgba(30,20,60,0.12);
  --hover: rgba(20,20,40,0.045);
  --wash: rgba(20,20,40,0.05);
  --card-hover: #E9E9F2;

  /* Darker shades than the dark-mode dot colours, for contrast on white. */
  --topic-ops: #2563EB;
  --topic-hr: #E11D48;
}

html { scroll-behavior: smooth; }

body {
  font-family: "Outfit", -apple-system, sans-serif;
  background:
    radial-gradient(1100px 560px at 14% -8%, rgba(139,92,246,0.10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(236,72,153,0.07), transparent 55%),
    var(--ink);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: "Bricolage Grotesque", sans-serif;
  letter-spacing: -0.02em;
  color: var(--white);
}

a { color: var(--p2); text-decoration: none; transition: color .15s; }
a:hover { color: var(--white); }

::selection { background: rgba(139,92,246,0.35); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(20,20,40,0.14); border-radius: 99px; border: 2px solid var(--ink); }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb, :root:not([data-theme="light"]) ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); }
::-webkit-scrollbar-thumb:hover { background: rgba(139,92,246,0.4); }

input, select, button { font-family: inherit; font-size: 14px; }

input, select {
  background: var(--card2);
  border: 1px solid var(--border2);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--white);
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--p); box-shadow: 0 0 0 3px rgba(139,92,246,0.18); }
input::placeholder { color: var(--muted); opacity: .7; }

button {
  cursor: pointer;
  border: none;
  border-radius: 9px;
  padding: 10px 18px;
  font-weight: 600;
  transition: transform .15s, box-shadow .15s, opacity .15s, filter .15s;
}
button:active { transform: translateY(1px); }

.btn-primary { background: var(--g); color: white; box-shadow: 0 4px 16px rgba(139,92,246,0.32); }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 6px 22px rgba(139,92,246,0.42); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover { background: var(--card-hover); border-color: rgba(139,92,246,0.35); color: var(--white); }

.card {
  background: linear-gradient(180deg, var(--card), var(--card) 60%, var(--card2));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: border-color .2s, transform .2s;
}

.error-box { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #FCA5A5; padding: 10px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 12px; }
:root[data-theme="light"] .error-box { color: #B91C1C; }
.grad-text { background: var(--g); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 11px 12px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--border2); }
td { padding: 13px 12px; border-bottom: 1px solid var(--border); }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(139,92,246,0.045); }
tbody tr:last-child td { border-bottom: none; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 4px 10px 4px 8px; border-radius: 99px; letter-spacing: .01em; border: 1px solid transparent; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-paid { background: rgba(16,185,129,0.12); color: var(--green); border-color: rgba(16,185,129,0.25); }
.badge-unpaid { background: rgba(245,158,11,0.12); color: var(--amber); border-color: rgba(245,158,11,0.25); }
.badge-overdue { background: rgba(239,68,68,0.12); color: var(--red); border-color: rgba(239,68,68,0.25); }
.badge-progress { background: rgba(139,92,246,0.12); color: var(--p2); border-color: rgba(139,92,246,0.25); }
.badge-neutral, .badge-voided { background: var(--wash); color: var(--muted); border-color: var(--border2); }

.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 4px; font-size: 13px; color: var(--muted); font-weight: 500; margin-right: 18px; border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--white); border-bottom-color: var(--p); }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 17px 18px;
  border-top: 2px solid var(--p);
  box-shadow: var(--shadow);
  transition: transform .18s, border-color .18s, box-shadow .18s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 7px; }
.kpi-value { font-family: "Bricolage Grotesque", sans-serif; font-size: 21px; font-weight: 700; color: var(--white); }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* App shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(139,92,246,0.05), transparent 20%), var(--ink2);
  position: sticky;
  top: 0;
  height: 100vh;
  max-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; padding: 0 6px; flex-shrink: 0; }
.sidebar-brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--g);
  display: flex; align-items: center; justify-content: center;
  font-family: "Bricolage Grotesque", sans-serif; font-weight: 800; font-size: 14px; color: #fff;
  box-shadow: 0 4px 14px rgba(139,92,246,0.4); flex-shrink: 0;
}
.biz-switcher {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin-bottom: 18px;
  background: var(--card2); border: 1px solid var(--border2); border-radius: 10px;
  color: var(--text); font-size: 12.5px; font-weight: 600;
  transition: border-color .15s, background .15s;
  flex-shrink: 0;
}
.biz-switcher:hover { color: var(--white); border-color: rgba(139,92,246,0.4); background: var(--card-hover); }
.biz-switcher-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--g); flex-shrink: 0; }
.biz-switcher-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.biz-switcher svg { opacity: .6; flex-shrink: 0; }

.sidebar nav { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--muted); font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
  border-left: 2px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar a.nav-link:hover { color: var(--white); background: var(--hover); }
.sidebar a.nav-link.active {
  color: var(--white); font-weight: 600;
  background: color-mix(in srgb, var(--topic-color, var(--p)) 14%, transparent);
  border-left-color: var(--topic-color, var(--p));
}
.nav-section { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); opacity: .75; margin: 16px 0 5px 12px; }

.nav-section-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); background: none; border: none; cursor: pointer;
  padding: 8px 12px 8px 12px; margin: 8px 0 0; border-radius: 6px;
  transition: color .15s, background .15s;
}
.nav-section-toggle:hover { color: var(--white); background: var(--hover); }
.nav-section-toggle .chevron { opacity: .6; flex-shrink: 0; transition: transform .15s; }
.nav-section-toggle.open .chevron { transform: rotate(180deg); }
.nav-section-toggle.has-active { color: var(--topic-color, var(--p2)); opacity: 1; }
.nav-section-label { display: flex; align-items: center; gap: 8px; }
.nav-section-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--topic-color, var(--p)); flex-shrink: 0; }
.nav-section-body { display: none; margin-top: 3px; }
.nav-section-body.open { display: block; }

.sidebar-user { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding-top: 16px; margin-top: 8px; flex-shrink: 0; }
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--g);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 13px; color: #fff;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12.5px; color: var(--white); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: 10.5px; color: var(--muted); text-transform: capitalize; }
.sidebar-signout {
  width: 30px; height: 30px; border-radius: 8px; background: var(--wash); border: 1px solid var(--border2);
  display: flex; align-items: center; justify-content: center; color: var(--text); flex-shrink: 0;
  transition: background .15s, color .15s;
}
.sidebar-signout:hover { background: rgba(239,68,68,0.12); color: var(--red); border-color: rgba(239,68,68,0.3); }

.main-content { flex: 1; padding: 36px 40px; max-width: 1160px; animation: fadeIn .35s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.stat-value { font-family: "Bricolage Grotesque", sans-serif; font-size: 25px; font-weight: 700; color: var(--white); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
.form-grid label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 5px; font-weight: 500; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  position: relative; overflow: hidden;
}
.login-wrap::before {
  content: ""; position: absolute; width: 640px; height: 640px; border-radius: 50%;
  background: radial-gradient(circle, rgba(139,92,246,0.20) 0%, transparent 70%);
  top: 50%; left: 50%; transform: translate(-50%, -50%); pointer-events: none;
}
.login-card { width: 400px; position: relative; box-shadow: var(--shadow-lg); border-color: var(--border2); }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; border-right: none; border-bottom: 1px solid var(--border); }
  .main-content { padding: 24px 18px; }
}
