:root {
  --brand: #3b4cca;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, white);
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f6f7fb;
  --card: #ffffff;
  --green: #0f9d58;
  --orange: #e8710a;
  --purple: #7b3fe4;
  --red: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; background: #0e1530; color: #cbd2ea; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand img { max-height: 34px; max-width: 150px; object-fit: contain; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; font-weight: 800; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8d97bd; letter-spacing: .3px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: #b4bcdb; text-decoration: none; background: none; border: 0; cursor: pointer; width: 100%; text-align: left; font-weight: 500; position: relative; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-item .badge-dot { margin-left: auto; background: #ef4444; color: #fff; font-size: 11px; border-radius: 10px; padding: 0 6px; min-width: 18px; text-align: center; line-height: 18px; }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 10px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1280px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.2px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card h2 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(3, 1fr); margin-bottom: 18px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr; } }
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--c, var(--brand)); }
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .label svg { color: var(--c, var(--brand)); }
.kpi .val { font-size: 24px; font-weight: 700; margin-top: 8px; letter-spacing: -.4px; }
.kpi .sub { color: var(--muted); margin-top: 2px; font-size: 13px; }
.two { grid-template-columns: 1.1fr 1fr; }
@media (max-width: 1000px) { .two { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; color: var(--ink); white-space: nowrap; }
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn[disabled] { opacity: .55; cursor: default; }

table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding: 10px 14px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 12px 14px; border-bottom: 1px solid #f0f1f5; vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover { background: #fafbff; }
.t .r { text-align: right; white-space: nowrap; }
.t tfoot td { font-weight: 700; background: #fafbfc; border-top: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
.sub-text { color: var(--muted); font-size: 12.5px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; background: #f3f4f6; color: #4b5563; white-space: nowrap; }
.pill.paid, .pill.ok { background: #e6f6ec; color: #0b7a43; }
.pill.partial, .pill.warn { background: #fff1e0; color: #b45309; }
.pill.overdue, .pill.bad { background: #fde8e6; color: #b42318; }
.pill.pending { background: #eef0f5; color: #4b5563; }
.pill.brand { background: var(--brand-soft); color: var(--brand); }

.monthbar { display: inline-flex; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.monthbar button { border: 0; background: none; padding: 8px 10px; cursor: pointer; display: grid; place-items: center; }
.monthbar button:hover { background: #f3f4f6; }
.monthbar .lbl { padding: 0 12px; font-weight: 600; min-width: 140px; text-align: center; position: relative; cursor: pointer; }
.monthbar input[type=month] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

.tabs { display: inline-flex; background: #eceef5; padding: 3px; border-radius: 10px; gap: 2px; margin-bottom: 16px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.rate-chip { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 13px; }
.rate-chip.stale { background: #fff1e0; color: #b45309; }
.banner { padding: 11px 14px; border-radius: 10px; background: #fff1e0; color: #92400e; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 34px; height: 34px; opacity: .5; margin-bottom: 8px; }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 15px; }

.strip { display: flex; gap: 28px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); background: #fcfcfe; border-radius: var(--radius) var(--radius) 0 0; }
.strip div span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.strip div b { font-size: 17px; }

.remind { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-bottom: 1px solid #f0f1f5; }
.remind:last-child { border-bottom: 0; }
.remind .ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: #f3f4f6; flex: none; }
.remind .ic.bad { background: #fde8e6; color: var(--red); }
.remind .ic.warn { background: #fff1e0; color: #b45309; }
.remind .ic.ok { background: var(--brand-soft); color: var(--brand); }
.remind .body { flex: 1; min-width: 0; }
.remind .body b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bars { display: flex; align-items: flex-end; gap: 14px; height: 190px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .pair { display: flex; align-items: flex-end; gap: 4px; flex: 1; width: 100%; justify-content: center; }
.bars .bar { width: 38%; max-width: 26px; border-radius: 5px 5px 0 0; min-height: 2px; }
.bars .in { background: var(--green); }
.bars .out { background: #f0a56a; }
.bars .m { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; }

/* ---------- forms + modal */
.modal-back { position: fixed; inset: 0; background: rgba(15, 20, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfc; border-radius: 0 0 14px 14px; }
.f { display: grid; gap: 5px; }
.f > label, .lbl-t { font-weight: 600; font-size: 13px; }
.f .hint { color: var(--muted); font-size: 12px; }
.f input, .f select, .f textarea, .inp { width: 100%; padding: 9px 11px; border: 1px solid #d5d9e3; border-radius: 9px; background: #fff; outline: none; }
.f input:focus, .f select:focus, .f textarea:focus, .inp:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .cols { grid-template-columns: 1fr; } }
.cf-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; }
.err { color: var(--red); font-size: 13px; min-height: 0; }
.inline-new { background: #f8f9fc; border: 1px dashed #cfd5e6; border-radius: 10px; padding: 12px; display: grid; gap: 10px; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.cell-inp { width: 120px; text-align: right; padding: 6px 8px; border: 1px solid #d5d9e3; border-radius: 8px; }
.cell-inp:focus { outline: none; border-color: var(--brand); }
.settings-grid { display: grid; gap: 16px; max-width: 760px; }
.seg { justify-self: start; display: inline-flex; border: 1px solid #d5d9e3; border-radius: 9px; overflow: hidden; }
.seg label { padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg input { display: none; }
.seg input:checked + span { color: var(--brand); }
.seg label:has(input:checked) { background: var(--brand-soft); color: var(--brand); }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #0e1530, #1c2a63); padding: 20px; }
.auth .box { background: #fff; width: 100%; max-width: 400px; border-radius: 16px; padding: 32px 30px; box-shadow: 0 30px 60px rgba(0, 0, 0, .35); }
.auth h1 { margin: 14px 0 4px; font-size: 21px; }
.auth p { margin: 0 0 20px; color: var(--muted); }
.auth .logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.auth .logo img { max-height: 44px; max-width: 200px; }
.auth .logo .mark { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.auth .btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); max-width: 360px; }
.toast.error { background: #b42318; }

/* ---------- small screens */
@media (max-width: 860px) {
  .sidebar { width: 64px; padding: 14px 8px; }
  .sidebar .nav-item span, .brand span, .brand small { display: none; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .nav-item .badge-dot { position: absolute; top: 2px; right: 6px; margin: 0; }
  .main { padding: 20px 16px 60px; }
  .brand { justify-content: center; padding: 6px 0 16px; }
  .brand img { display: none; }
}
@media print { .sidebar, .actions { display: none; } }
