:root {
  --brand:#4f46e5; --brand-dark:#4338ca; --brand-soft:#eef2ff;
  --ink:#0f172a; --muted:#64748b; --line:#e2e8f0; --bg:#f1f5f9;
  --ok:#16a34a; --ok-soft:#dcfce7; --warn:#d97706; --warn-soft:#fef3c7;
  --danger:#dc2626; --danger-soft:#fee2e2; --info-soft:#e0f2fe; --info:#0284c7;
}
* { box-sizing: border-box; }
html, body { margin:0; height:100%; }
body {
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  color:var(--ink); background:var(--bg); font-size:14px;
}
#app { display:flex; min-height:100vh; }

/* Sidebar */
.sidebar { width:230px; background:#fff; border-right:1px solid var(--line);
  display:flex; flex-direction:column; padding:18px 14px; position:sticky; top:0; height:100vh; }
.brand { display:flex; align-items:center; gap:10px; font-weight:800; font-size:18px; padding:6px 8px 18px; }
.brand .mark { width:32px;height:32px;border-radius:8px;background:var(--brand);color:#fff;
  display:grid;place-items:center;font-size:15px;font-weight:800; }
#nav { display:flex; flex-direction:column; gap:3px; }
#nav a { display:block; padding:10px 12px; border-radius:9px; color:var(--ink); text-decoration:none;
  cursor:pointer; font-weight:500; font-size:14px; }
#nav a:hover { background:var(--bg); }
#nav a.active { background:var(--brand-soft); color:var(--brand-dark); font-weight:600; }
.sidebar-foot { margin-top:auto; padding-top:14px; }
.whoami { font-size:12px; color:var(--muted); padding:0 8px 10px; line-height:1.4; }
.whoami b { color:var(--ink); display:block; font-size:13px; }
.role-pill { display:inline-block; margin-top:3px; padding:1px 7px; border-radius:999px; background:var(--brand-soft); color:var(--brand-dark); font-weight:600; font-size:11px; text-transform:capitalize; }

/* Content */
.content { flex:1; min-width:0; display:flex; flex-direction:column; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding:20px 28px; border-bottom:1px solid var(--line); background:#fff; }
.topbar h1 { margin:0; font-size:22px; }
.view { padding:24px 28px; }

/* Buttons */
.btn-primary { background:var(--brand); color:#fff; border:0; padding:10px 16px; border-radius:9px;
  font-weight:600; cursor:pointer; font-size:14px; }
.btn-primary:hover { background:var(--brand-dark); }
.btn-ghost { background:#fff; color:var(--ink); border:1px solid var(--line); padding:9px 14px;
  border-radius:9px; font-weight:600; cursor:pointer; font-size:14px; }
.btn-ghost:hover { background:var(--bg); }
.btn-sm { padding:5px 10px; font-size:13px; border-radius:7px; }
.icon-btn { border:0; background:transparent; cursor:pointer; font-size:15px; padding:4px 7px; border-radius:6px; color:var(--muted); }
.icon-btn:hover { background:var(--bg); color:var(--ink); }

/* Version banner */
.version-banner { padding:12px 18px; border-radius:12px; margin-bottom:18px; font-size:16px; border:1px solid var(--line); }
.version-banner b { font-size:18px; font-weight:800; }
.version-banner.role-admin { background:var(--brand-soft); color:var(--brand-dark); border-color:#c7d2fe; }
.version-banner.role-accountant { background:var(--warn-soft); color:var(--warn); border-color:#fde68a; }
.version-banner.role-team { background:var(--ok-soft); color:var(--ok); border-color:#bbf7d0; }

/* KPI cards */
.kpis { display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:16px; margin-bottom:24px; }
.kpi { background:#fff; border:1px solid var(--line); border-radius:14px; padding:18px 20px; }
.kpi .label { color:var(--muted); font-size:13px; font-weight:600; }
.kpi .value { font-size:26px; font-weight:800; margin-top:6px; }
.kpi .hint { color:var(--muted); font-size:12px; margin-top:4px; }

/* Goal progress bars */
.goalrow { margin:14px 0; }
.goalrow:first-child { margin-top:4px; }
.goalrow-head { display:flex; justify-content:space-between; align-items:baseline; font-size:14px; margin-bottom:6px; }
.goalbar { height:10px; background:var(--bg); border-radius:999px; overflow:hidden; }
.goalbar-fill { height:100%; background:var(--brand); border-radius:999px; transition:width .35s ease; }
.goalbar-fill.done { background:var(--ok); }
.goal-met { color:var(--ok); font-weight:700; }
.pos { color:var(--ok); font-weight:700; }
.neg { color:var(--danger); font-weight:700; }
tfoot .totals-row td { border-top:2px solid var(--ink); font-weight:800; background:#f8fafc; }
/* Frozen header + totals row on the clients table (scrolls within its own box) */
#cl-table { max-height:68vh; overflow:auto; }
#cl-table table thead th { position:sticky; top:0; z-index:3; background:#f1f5f9; }
#cl-table table tr.row-total td { position:sticky; top:39px; z-index:2; background:#eef2ff; font-weight:800; border-bottom:2px solid var(--brand); }
.pl-toggle { border:1px solid var(--line); background:#fff; width:20px; height:20px; border-radius:5px; cursor:pointer; font-weight:700; line-height:1; color:var(--brand-dark); padding:0; }
.pl-toggle:hover { background:var(--brand-soft); }
.pl-d > td { background:#fafbff; padding:4px 18px; }
.pl-detail-row { display:flex; justify-content:space-between; gap:16px; padding:5px 8px 5px 30px; font-size:13px; border-bottom:1px dashed var(--line); }
.pl-detail-row:last-child { border-bottom:0; }

/* Panels */
.panel { background:#fff; border:1px solid var(--line); border-radius:14px; margin-bottom:22px; overflow:hidden; }
.panel-head { display:flex; align-items:center; justify-content:space-between; padding:14px 18px; border-bottom:1px solid var(--line); }
.panel-head h3 { margin:0; font-size:15px; }
.panel-body { padding:4px 0; }
.empty { padding:34px 18px; text-align:center; color:var(--muted); }

/* Tables */
table { width:100%; border-collapse:collapse; }
th { text-align:left; font-size:12px; text-transform:uppercase; letter-spacing:.03em; color:var(--muted);
  padding:11px 18px; border-bottom:1px solid var(--line); white-space:nowrap; }
td { padding:12px 18px; border-bottom:1px solid var(--line); vertical-align:middle; }
tr:last-child td { border-bottom:0; }
tbody tr:hover { background:#fafbff; }
.num { text-align:right; font-variant-numeric:tabular-nums; }
.mono { font-family:ui-monospace,Menlo,Consolas,monospace; font-size:13px; background:var(--bg); padding:2px 6px; border-radius:5px; }
.chips-row { gap:6px; align-items:center; }
.chip { display:inline-block; padding:3px 10px; border-radius:999px; background:var(--brand-soft); color:var(--brand-dark); font-size:12px; font-weight:600; cursor:pointer; border:1px solid transparent; }
.chip:hover { border-color:var(--brand); }
.chip.off { background:var(--bg); color:var(--muted); text-decoration:line-through; }
.link-cell { color:var(--brand-dark); cursor:pointer; }
.link-cell:hover { text-decoration:underline; }
.strong { font-weight:700; }
.muted { color:var(--muted); }
.sub { font-size:12px; color:var(--muted); }

/* Sub-tabs */
.subtabs { display:flex; gap:2px; margin-bottom:18px; border-bottom:1px solid var(--line); }
.subtabs a { padding:9px 16px; cursor:pointer; font-weight:600; color:var(--muted); border-bottom:2px solid transparent; margin-bottom:-1px; }
.subtabs a:hover { color:var(--ink); }
.subtabs a.active { color:var(--brand-dark); border-bottom-color:var(--brand); }

/* Tools row */
.tools { display:flex; gap:10px; align-items:center; margin-bottom:16px; flex-wrap:wrap; }
.tools input[type=search], .tools select { padding:9px 12px; border:1px solid var(--line); border-radius:9px; font-size:14px; background:#fff; }
.tools input[type=search] { min-width:240px; }
.spacer { flex:1; }

/* Badges */
.badge { display:inline-flex; align-items:center; gap:5px; padding:3px 9px; border-radius:999px;
  font-size:12px; font-weight:600; }
.badge.recurring { background:var(--brand-soft); color:var(--brand-dark); }
.badge.onetime { background:var(--info-soft); color:var(--info); }
.badge.paid { background:var(--ok-soft); color:var(--ok); }
.badge.unpaid { background:var(--danger-soft); color:var(--danger); }
.badge.active { background:var(--ok-soft); color:var(--ok); }
.badge.churned { background:#f1f5f9; color:var(--muted); }
.badge.due-soon { background:var(--warn-soft); color:var(--warn); }
.badge.overdue { background:var(--danger-soft); color:var(--danger); }
.badge.status-quoted { background:#f1f5f9; color:var(--muted); }
.badge.status-approved { background:var(--info-soft); color:var(--info); }
.badge.status-in-progress { background:var(--warn-soft); color:var(--warn); }
.badge.status-completed { background:var(--ok-soft); color:var(--ok); }
.badge.status-cancelled { background:var(--danger-soft); color:var(--danger); }

/* Modal */
.modal-overlay { position:fixed; inset:0; background:rgba(15,23,42,.45); display:grid; place-items:center; z-index:50; padding:20px; }
.modal-overlay.hidden { display:none; }
.modal { background:#fff; width:100%; max-width:520px; border-radius:16px; box-shadow:0 20px 60px rgba(15,23,42,.25);
  max-height:90vh; display:flex; flex-direction:column; }
.modal-head { display:flex; align-items:center; justify-content:space-between; padding:18px 22px; border-bottom:1px solid var(--line); }
.modal-head h2 { margin:0; font-size:18px; }
.modal-close { border:0; background:transparent; font-size:26px; line-height:1; cursor:pointer; color:var(--muted); }
.modal-body { padding:20px 22px; overflow-y:auto; display:grid; grid-template-columns:1fr 1fr; gap:14px 16px; }
.modal-foot { display:flex; justify-content:flex-end; gap:10px; padding:16px 22px; border-top:1px solid var(--line); }
.field { display:flex; flex-direction:column; gap:6px; }
.field.full { grid-column:1 / -1; }
.field label { font-size:13px; font-weight:600; }
.field .req { color:var(--danger); }
.field input, .field select, .field textarea {
  padding:10px 12px; border:1px solid var(--line); border-radius:9px; font-size:14px; font-family:inherit; background:#fff; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline:none; border-color:var(--brand); box-shadow:0 0 0 3px rgba(79,70,229,.15); }
.field textarea { resize:vertical; min-height:64px; }
.field .help { font-size:12px; color:var(--muted); }
.form-error { grid-column:1/-1; color:var(--danger); font-size:13px; }
.hidden { display:none !important; }

/* Toast */
.toast { position:fixed; bottom:24px; left:50%; transform:translateX(-50%);
  background:var(--ink); color:#fff; padding:12px 20px; border-radius:10px; font-weight:600; z-index:60;
  box-shadow:0 10px 30px rgba(0,0,0,.25); }
.toast.err { background:var(--danger); }
.toast.hidden { display:none; }

@media (max-width:820px){
  .sidebar { width:64px; }
  .brand-name, #nav a { font-size:0; }
  #nav a { text-align:center; }
  .modal-body { grid-template-columns:1fr; }
}
