:root {
  --bg: #0f1117;
  --surface: #161922;
  --surface-2: #1d2130;
  --line: #262b3a;
  --text: #e7e9ef;
  --muted: #9aa2b4;
  --faint: #6b7385;
  --brand: #6366f1;
  --brand-ink: #c7d0ff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-ink); }
button { font-family: inherit; }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(99, 102, 241, .14), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(52, 211, 153, .07), transparent 55%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.auth-card h1 { font-size: 19px; margin: 22px 0 4px; letter-spacing: -.02em; }
.auth-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99, 102, 241, .22); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--brand);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 11px 15px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: #5458e0; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.block { width: 100%; margin-top: 22px; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn.ghost:hover { color: var(--text); border-color: var(--faint); }
.btn.sm { padding: 7px 11px; font-size: 13px; }

.form-error {
  margin-top: 16px;
  background: rgba(248, 113, 113, .1);
  border: 1px solid rgba(248, 113, 113, .3);
  color: #fecaca;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 13.5px;
}
.hidden { display: none !important; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
}
.side-brand { padding: 6px 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: var(--muted);
  text-align: left; width: 100%;
  padding: 9px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: rgba(99, 102, 241, .16); color: var(--brand-ink); }
.nav .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .55; }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 14px; }
.side-foot .who { font-size: 13px; }
.side-foot .who .name { font-weight: 600; }
.side-foot .who .org { color: var(--faint); font-size: 12px; }

.main { padding: 26px 34px 60px; max-width: 1040px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; }
.page-head h2 { font-size: 22px; letter-spacing: -.02em; margin: 0; }
.page-head .muted { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* ---------- Stat row ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .k { color: var(--faint); font-size: 12px; text-transform: none; }
.stat .v { font-size: 24px; font-weight: 680; letter-spacing: -.02em; margin-top: 6px; }

/* ---------- Table ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; color: var(--faint); font-weight: 600;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.num { font-variant-numeric: tabular-nums; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; }

.pill { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.pill.paid { background: rgba(52, 211, 153, .15); color: var(--green); }
.pill.open { background: rgba(99, 102, 241, .16); color: var(--brand-ink); }
.pill.overdue { background: rgba(248, 113, 113, .15); color: var(--red); }
.pill.role { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 5px 8px; font-size: 13px;
}

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(5, 6, 10, .6); backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow); padding: 24px; overflow-y: auto;
}
.drawer h3 { margin: 4px 0 2px; font-size: 18px; letter-spacing: -.01em; }
.drawer .close { position: absolute; top: 16px; right: 16px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 14px; margin-top: 18px; font-size: 14px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; }
.notes-box {
  margin-top: 18px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 13px 14px; font-size: 13.5px; color: var(--muted); white-space: pre-wrap;
}

.empty { padding: 40px; text-align: center; color: var(--faint); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px; gap: 12px; overflow-x: auto; }
  .side-brand { padding: 0 6px 0 2px; }
  .nav { flex-direction: row; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 20px 16px 50px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
