:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #e8edf4;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef2ff;
  --pos: #15925a;
  --pos-soft: #e7f7ee;
  --neg: #dc2626;
  --neg-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff5e6;
  --sidebar-1: #111827;
  --sidebar-2: #1f2937;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 34px rgba(15, 23, 42, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Heebo', 'Rubik', 'Segoe UI', system-ui, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: none; }

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

.sidebar {
  width: 246px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2));
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 800; color: #fff;
  padding: 6px 10px 20px;
}
.logo .dot { font-size: 22px; }

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  color: #cbd5e1; font-weight: 500; font-size: 15px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 20px; height: 20px; stroke: currentColor; flex-shrink: 0; opacity: .9; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.on { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(79,70,229,.4); }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.user { display: flex; align-items: center; gap: 10px; padding: 6px 8px 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--brand); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 17px;
}
.user .uname { color: #fff; font-weight: 600; font-size: 14px; }
.user .urole { color: #94a3b8; font-size: 12px; }
.logout-btn {
  width: 100%; background: rgba(255,255,255,.06); color: #e2e8f0;
  border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 9px;
  cursor: pointer; font-size: 14px; font-family: inherit;
}
.logout-btn:hover { background: rgba(255,255,255,.12); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 68px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 30px; position: sticky; top: 0; z-index: 5;
}
.page-title { font-size: 21px; font-weight: 700; margin: 0; }
.topbar .spacer { flex: 1; }
.topbar .today { color: var(--muted); font-size: 14px; }

.content { padding: 28px 30px 48px; max-width: 1180px; width: 100%; }

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 30px 0 12px; font-weight: 700; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 12px; }
.section-head h2 { margin: 0; }

/* ============ KPI cards ============ */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 16px;
}
.kpi .ic { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; }
.kpi .ic svg { width: 24px; height: 24px; stroke: currentColor; }
.kpi .ic.indigo { background: var(--brand-soft); color: var(--brand); }
.kpi .ic.green { background: var(--pos-soft); color: var(--pos); }
.kpi .ic.amber { background: var(--warn-soft); color: var(--warn); }
.kpi .ic.red { background: var(--neg-soft); color: var(--neg); }
.kpi .k { color: var(--ink-2); font-size: 13px; font-weight: 500; }
.kpi .v { font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }

/* smaller stat cards (reports) */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 15px 17px; box-shadow: var(--shadow-sm);
}
.card .k { color: var(--ink-2); font-size: 13px; }
.card .v { font-size: 21px; font-weight: 800; margin-top: 3px; letter-spacing: -.4px; }
.card .v.small { font-size: 14px; font-weight: 600; }

/* ============ panels & chart ============ */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px){ .grid-2 { grid-template-columns: 1fr; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.panel-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-body { padding: 18px 20px; }

.chart { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.chart .bar {
  width: 70%; max-width: 46px; border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  min-height: 4px; position: relative; transition: filter .15s;
}
.chart .col:hover .bar { filter: brightness(1.08); }
.chart .cval { font-size: 11px; color: var(--ink-2); font-weight: 600; }
.chart .clabel { font-size: 12px; color: var(--muted); }

/* mini horizontal bars in balance list */
.bal-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.bal-row:last-child { border-bottom: none; }
.bal-row .nm { width: 92px; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.bal-track { flex: 1; height: 10px; background: #eef1f7; border-radius: 999px; overflow: hidden; }
.bal-fill { height: 100%; border-radius: 999px; }
.bal-fill.pos { background: linear-gradient(90deg, #34d399, var(--pos)); }
.bal-fill.neg { background: linear-gradient(90deg, #f87171, var(--neg)); }
.bal-row .amt { width: 96px; text-align: left; font-size: 13px; font-weight: 700; }

/* ============ tables ============ */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); margin-bottom: 10px; }
th, td { text-align: right; padding: 13px 18px; font-size: 14px; border-bottom: 1px solid var(--line); }
thead th { background: #fafbfe; color: var(--ink-2); font-weight: 600; font-size: 12.5px; letter-spacing: .2px; text-transform: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: none; }
.mono { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-size: 13px; }
.muted { color: var(--muted); }
.pos { color: var(--pos); font-weight: 700; }
.neg { color: var(--neg); font-weight: 700; }

/* ============ badges / pills ============ */
.tag { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.tag.ok { background: var(--pos-soft); color: var(--pos); }
.tag.link { background: var(--warn-soft); color: var(--warn); }
.tag.st-DONE { background: var(--pos-soft); color: var(--pos); }
.tag.st-PARTIAL { background: var(--warn-soft); color: var(--warn); }
.tag.st-FAILED { background: var(--neg-soft); color: var(--neg); }
.tag.st-SENT, .tag.st-SEEN, .tag.st-POSTPONED { background: var(--brand-soft); color: var(--brand); }
.tag.st-CANCELLED { background: #eef1f5; color: #64748b; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--pos-soft); color: var(--pos); }

/* ============ forms / buttons ============ */
button, .btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: var(--brand); color: #fff; border: none; border-radius: 11px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 12px rgba(79,70,229,.22); transition: transform .05s, filter .15s;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button:active, .btn:active { transform: translateY(1px); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; box-shadow: none; }
.btn.ghost, button.ghost { background: var(--brand-soft); color: var(--brand); box-shadow: none; }
.btn.subtle { background: #eef1f7; color: var(--ink-2); box-shadow: none; }

input, select {
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
label { display: block; font-size: 13px; color: var(--ink-2); font-weight: 500; margin-bottom: 5px; }
label input, label select { display: block; width: 100%; margin-top: 5px; }

.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.row-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row-form input { flex: 1 1 200px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; align-items: end; margin-top: 12px; }
.grid-form button { grid-column: 1 / -1; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.row-actions { display: flex; gap: 10px; margin: 16px 0; }
.inline { display: inline; }
summary { cursor: pointer; font-weight: 700; }
details.box[open] summary { margin-bottom: 8px; }

.settle-preview { margin: 14px 0; padding: 13px 16px; background: var(--brand-soft); border-radius: 12px; font-size: 15px; }
.wage { max-width: 360px; margin: 10px 0 16px; }
.crumb { color: var(--muted); font-size: 14px; margin-bottom: 8px; display: inline-block; }

/* ============ login ============ */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 80% -10%, #4f46e5 0%, #312e81 40%, #0f172a 100%);
}
.login-card {
  background: var(--surface); border-radius: 22px; padding: 34px 30px; width: 350px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand-lg { text-align: center; font-size: 30px; }
.login-card h1 { text-align: center; font-size: 20px; margin: 6px 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.login-card label { margin-bottom: 14px; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; margin-top: 4px; }
.err { background: var(--neg-soft); color: var(--neg); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; text-align: center; }

/* ============ responsive ============ */
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; }
  .logo { padding: 6px 10px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item span { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; border: none; padding: 0; display: flex; gap: 10px; align-items: center; }
  .user { display: none; }
  .content { padding: 18px; }
  .topbar { padding: 0 18px; }
}

@media print {
  .sidebar, .topbar, .filters, form, .row-actions { display: none !important; }
  body { background: #fff; }
  .panel, .table-wrap, .card, .kpi { box-shadow: none; }
  .content { padding: 0; }
}
