:root {
    --navy: #0c1e36;
    --navy-2: #132a4a;
    --gold: #d4a017;
    --gold-soft: #fff4d2;
    --bg: #eef2f7;
    --card: #ffffff;
    --text: #122033;
    --muted: #5d6d82;
    --line: #d7e0ec;
    --ok: #0f7b45;
    --ok-bg: #e7f7ee;
    --warn: #b45309;
    --warn-bg: #fff4e5;
    --err: #b42318;
    --err-bg: #fde8e6;
    --blue: #1d4e89;
    --shadow: 0 10px 30px rgba(12, 30, 54, 0.08);
    --radius: 16px;
    --sidebar: 260px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: "Plus Jakarta Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--blue); }
.mono, td.num, th.num, .kpi-value, .ledger-amt { font-family: "IBM Plex Mono", monospace; }

.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar);
    background: linear-gradient(180deg, var(--navy) 0%, #0a182c 100%);
    color: #dce6f3;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    flex-shrink: 0;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; }
.brand strong { display: block; color: #fff; font-size: 15px; }
.brand span { font-size: 12px; color: #93a6bf; }
.mark {
    width: 40px; height: 40px; border-radius: 12px;
    background: var(--gold); display: grid; place-items: center; flex-shrink: 0;
}
.nav-label {
    margin: 18px 10px 6px; font-size: 11px; letter-spacing: .08em;
    text-transform: uppercase; color: #7f93ab;
}
.nav-link {
    display: block; color: #c9d6e6; text-decoration: none;
    padding: 10px 12px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { box-shadow: inset 3px 0 0 var(--gold); }

.main { flex: 1; min-width: 0; }
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 18px 28px; background: #fff; border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 22px; }
.muted { color: var(--muted); margin: 3px 0 0; font-size: 13px; }
.period-form { margin-left: auto; display: flex; gap: 8px; }
.period-form select, select, input, textarea {
    font: inherit; color: var(--text);
    border: 1px solid var(--line); background: #fff;
    border-radius: 10px; padding: 10px 12px;
}
.period-form select { min-width: 120px; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox strong { display: block; font-size: 14px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700;
}
.role-badge {
    display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase;
    padding: 2px 7px; border-radius: 999px; background: #e8eef7;
}
.role-badge.admin { background: var(--gold-soft); color: #8a6a00; }
.role-badge.agent { background: #e7f0fa; color: var(--blue); }
.text-link { font-size: 13px; font-weight: 700; text-decoration: none; }
.content { padding: 24px 28px 48px; }

.banner {
    background: #eef5ff; border: 1px solid #c9dbf5; color: #1d4e89;
    padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi {
    background: var(--card); border-radius: var(--radius); padding: 18px 18px 16px;
    box-shadow: var(--shadow); border: 1px solid #e8edf4;
}
.kpi.gold { background: linear-gradient(180deg, #fffaf0 0%, #fff 70%); }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.kpi-value { font-size: 26px; font-weight: 700; margin: 8px 0 4px; letter-spacing: -0.03em; }
.kpi-sub { color: var(--muted); font-size: 13px; }
.pos { color: var(--ok); } .neg { color: var(--err); }

.grid-2 { display: grid; grid-template-columns: 1.4fr .8fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid #e8edf4; padding: 18px;
}
.card h2, .card h3 { margin: 0 0 14px; font-size: 16px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { margin-left: auto; }
.search { min-width: 220px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--navy); color: #fff; border: 0; border-radius: 10px;
    padding: 10px 14px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { background: #16325a; }
.btn.gold { background: var(--gold); color: #0c1e36; }
.btn.gold:hover { background: #e0b322; }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.danger { background: var(--err); }
.btn.sm { padding: 7px 10px; font-size: 13px; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: #f7f9fc; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr:hover td { background: #fafcff; }
tfoot td { font-weight: 700; background: #f7f9fc; }
.row-actions { display: flex; gap: 6px; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

.week-block { margin-bottom: 22px; }
.week-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.week-head h3 { margin: 0; font-size: 18px; }

.modal {
    position: fixed; inset: 0; background: rgba(12,30,54,.45);
    display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal.open { display: flex; }
.modal-card { background: #fff; width: min(720px, 100%); border-radius: 18px; padding: 22px; max-height: 92vh; overflow: auto; }
.modal-card h3 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
input, select, textarea { width: 100%; }
textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
    background: var(--ok-bg); color: var(--ok); border: 1px solid #b7ebc8;
    padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 600;
}
.toast.error, .toast.err { background: var(--err-bg); color: var(--err); border-color: #f3c4c0; }
.toast.warn { background: var(--warn-bg); color: var(--warn); }

.login-body {
    min-height: 100vh; display: grid; place-items: center;
    background:
        radial-gradient(900px 420px at 0% 0%, #1d4e89 0%, transparent 55%),
        linear-gradient(160deg, #0c1e36 0%, #16325a 55%, #eef2f7 55%);
}
.login-card {
    width: min(440px, calc(100% - 32px)); background: #fff; border-radius: 20px;
    padding: 32px; box-shadow: 0 24px 60px rgba(12,30,54,.18);
}
.login-card h1 { margin: 8px 0 6px; }
.login-card .lead { color: var(--muted); margin: 0 0 22px; }
.stack { display: grid; gap: 12px; }
.login-brand { display: flex; gap: 12px; align-items: center; }

.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 40px; height: 40px; cursor: pointer; }
.menu-btn { display: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.remain-neg { color: var(--err); font-weight: 700; }
.remain-ok { color: var(--ok); font-weight: 700; }
.ledger { width: 100%; }
.help { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

@media (max-width: 1100px) {
    .kpis, .grid-2, .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: -280px; z-index: 30; transition: left .2s ease; }
    .sidebar.open { left: 0; }
    .menu-btn { display: inline-grid; place-items: center; }
    .topbar { flex-wrap: wrap; }
    .period-form { margin-left: 0; }
    .kpis, .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
}
