:root {
  --teal: #0B6E7A; --teal-dark: #085560; --teal-light: #E5F4F6;
  --ink: #1c2b33; --muted: #64748b; --line: #e2e8f0;
  --bg: #f4f7f9; --card: #fff;
  --red: #dc2626; --red-bg: #fef2f2; --amber: #d97706; --amber-bg: #fffbeb;
  --green: #16a34a; --green-bg: #f0fdf4;
  --radius: 12px; --shadow: 0 1px 3px rgba(16,42,51,.08), 0 4px 16px rgba(16,42,51,.06);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, "Segoe UI", Rubik, Arial, sans-serif; background: var(--bg); color: var(--ink); }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #0e2229; color: #cfe3e8; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 22px 20px 16px; font-size: 19px; color: #fff; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand b { color: #6fd3de; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: #6fd3de; box-shadow: 0 0 10px #6fd3de; }
#nav { display: flex; flex-direction: column; padding: 8px 10px; gap: 2px; }
#nav a { color: #b7ccd3; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-size: 14.5px; transition: .15s; }
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: var(--teal); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; font-size: 11.5px; color: #5d7a83; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 26px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 20px; }
.topbar-actions { display: flex; gap: 8px; }
.view { padding: 24px 26px 60px; }

.btn { border: none; border-radius: 9px; padding: 9px 16px; font-size: 13.5px; cursor: pointer; font-family: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; transition: .15s; }
.btn.primary { background: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-dark); }
.btn.primary.outline { background: #fff; color: var(--teal); border: 1.5px solid var(--teal); }
.btn.ghost { background: #eef2f5; color: var(--ink); }
.btn.ghost:hover { background: #e2e8ee; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.danger { background: var(--red-bg); color: var(--red); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--teal); }
.kpi.red { border-top-color: var(--red); }
.kpi.amber { border-top-color: var(--amber); }
.kpi.green { border-top-color: var(--green); }
.kpi .k-label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.kpi .k-value { font-size: 24px; font-weight: 700; }
.kpi .k-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.red .k-value { color: var(--red); }

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

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: right; padding: 10px 16px; color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); background: #fafcfd; white-space: nowrap; }
td { padding: 11px 16px; border-bottom: 1px solid #f1f5f8; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7fafb; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.pending { background: var(--amber-bg); color: var(--amber); }
.pill.paid { background: var(--green-bg); color: var(--green); }
.pill.waived { background: #f1f5f9; color: var(--muted); }
.pill.auto { background: var(--teal-light); color: var(--teal); }
.pill.cat { background: #f1f5f9; color: #475569; }

.empty { padding: 34px; text-align: center; color: var(--muted); font-size: 14px; }
.money { font-weight: 700; white-space: nowrap; }
.late { color: var(--red); font-weight: 600; font-size: 12px; }
.muted { color: var(--muted); font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 7px 16px; font-size: 13px; cursor: pointer; font-family: inherit; }
.tabs button.on { background: var(--teal); border-color: var(--teal); color: #fff; }

/* reports */
.report-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.rt-title { font-size: 14px; color: var(--muted); margin-inline-end: auto; }
.rate-box { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.rate-box input { width: 76px; padding: 6px 9px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

/* modals */
.modal-back { display: none; position: fixed; inset: 0; background: rgba(12,35,42,.45); z-index: 50; align-items: flex-start; justify-content: center; padding: 40px 16px; }
.modal-back.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 640px; max-width: 100%; max-height: calc(100vh - 60px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.small { width: 480px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 17px; }
.modal-head .x { border: none; background: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid2 .span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
input, select, textarea { border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal-light); border-color: var(--teal); }
.hint { font-size: 12px; color: var(--muted); margin-top: 12px; }
.pay-desc { background: var(--teal-light); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; }
.summary-pre { white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.7; background: #fafcfd; border: 1px solid var(--line); border-radius: 8px; padding: 14px; }

/* client detail */
.client-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--teal); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; }
.client-head .info h2 { font-size: 19px; }
.client-head .info .muted { margin-top: 2px; }
.back-link { color: var(--teal); cursor: pointer; font-size: 13px; margin-bottom: 14px; display: inline-block; }

#toast { position: fixed; bottom: 24px; right: 50%; transform: translateX(50%); background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: .25s; z-index: 99; }
#toast.show { opacity: 1; }

@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .brand { font-size: 0; padding: 18px 0; justify-content: center; }
  #nav a { text-align: center; font-size: 17px; }
  .sidebar-foot { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .grid2 .span2 { grid-column: span 1; }
}
