:root {
    --ink: #152033;
    --muted: #5b6b7c;
    --line: #d7e0ea;
    --bg: #eef3f8;
    --card: #ffffff;
    --brand: #0f6cbd;
    --brand-2: #094a84;
    --ok: #1f8a4c;
    --warn: #b86a00;
    --bad: #b42318;
    --font: "DM Sans", "Source Sans 3", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.portal-body {
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(15, 108, 189, 0.16), transparent 60%),
        linear-gradient(180deg, #f7fafc 0%, var(--bg) 100%);
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.portal-top {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(10px);
    background: rgba(255,255,255,0.88);
    border-bottom: 1px solid var(--line);
}
.portal-top-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.portal-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.portal-brand .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    background: #fff;
    border: 3px solid #e31c23;
    font-weight: 700;
}
.portal-brand .brand-copy {
    display: grid;
    line-height: 1.15;
}
.portal-brand .brand-copy strong { font-size: 1.05rem; }
.portal-brand .brand-copy small { color: var(--muted); font-size: 0.78rem; }
.portal-brand.light .brand-copy strong,
.portal-brand.light .brand-copy small { color: #fff; }

.portal-nav {
    display: flex;
    gap: 8px;
    margin-left: 12px;
}
.portal-nav a {
    padding: 8px 12px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 600;
}
.portal-nav a.active,
.portal-nav a:hover {
    background: rgba(15, 108, 189, 0.1);
    color: var(--brand-2);
}
.portal-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.portal-user strong { display: block; font-size: 0.92rem; }
.portal-user small { color: var(--muted); }
.btn-portal-return {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 0;
    background: #f97316;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 10px 14px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}
.btn-portal-return:hover { background: #ea580c; }

.portal-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 48px;
    display: grid;
    gap: 18px;
}
.portal-foot {
    max-width: 1100px;
    margin: 0 auto 24px;
    padding: 0 20px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.88rem;
}

.flash {
    border-radius: 12px;
    padding: 12px 14px;
    font-weight: 600;
}
.flash.ok { background: #e8f8ef; color: var(--ok); }
.flash.bad { background: #fdecec; color: var(--bad); }

.portal-hero-card,
.portal-panel,
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(21, 32, 51, 0.04);
}
.portal-hero-card {
    padding: 22px;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    background:
        linear-gradient(135deg, rgba(15,108,189,0.08), rgba(255,255,255,0.9)),
        var(--card);
}
.portal-hero-card h1 { margin: 0 0 6px; font-size: 1.6rem; }
.portal-hero-card p { margin: 0; color: var(--muted); }
.debt-box {
    min-width: 180px;
    border-radius: 14px;
    padding: 14px 16px;
    display: grid;
    gap: 4px;
}
.debt-box span { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.debt-box strong { font-size: 1.35rem; }
.debt-box.warn { background: #fff4e5; color: var(--warn); }
.debt-box.ok { background: #e8f8ef; color: var(--ok); }

.portal-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.stat { padding: 16px; }
.stat span { color: var(--muted); font-size: 0.82rem; }
.stat strong { display: block; margin-top: 6px; font-size: 1.1rem; }

.portal-panel { padding: 18px; }
.panel-head-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.panel-head-row h1, .panel-head-row h2 { margin: 0; }
.invoice-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 14px 0;
    border-top: 1px solid var(--line);
}
.invoice-row:first-of-type { border-top: 0; }
.invoice-row small { display: block; color: var(--muted); margin-top: 2px; }
.invoice-row-right { display: flex; align-items: center; gap: 12px; }
.muted-row { opacity: 0.9; }
.empty { color: var(--muted); margin: 8px 0; }

.btn-primary, .btn-secondary, .btn-ghost {
    border: 0;
    border-radius: 10px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #12263a; color: #fff; }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
}
.btn-primary.block, .btn-secondary.block { width: 100%; }
a.btn-primary, a.btn-secondary, a.btn-ghost { text-decoration: none; }

.invoice-download-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 16px;
}
.invoice-download-row .hint { font-size: 13px; }

.chip-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-tabs a {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
    font-weight: 600;
}
.chip-tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.table-scroll { overflow: auto; }
.portal-table { width: 100%; border-collapse: collapse; }
.portal-table th, .portal-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.portal-table th { color: var(--muted); font-size: 0.8rem; }
.pill {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}
.pill.ok { background: #e8f8ef; color: var(--ok); }
.pill.warn { background: #fff4e5; color: var(--warn); }
.pill.info { background: #e8f1ff; color: var(--brand-2); }
.pill.off { background: #eef1f5; color: #64748b; }

.invoice-detail-grid {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr;
    gap: 16px;
}
.kv { display: grid; gap: 10px; margin: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.kv.compact > div { border-bottom: 0; padding-bottom: 0; }
.subhead { margin: 18px 0 8px; font-size: 1rem; }
.pay-aside h2 { margin-top: 0; }
.amount-big { font-size: 1.8rem; font-weight: 700; margin: 8px 0; }
.muted { color: var(--muted); }
.pay-form { margin-top: 12px; display: grid; gap: 6px; }
.hint { color: var(--warn); }
.back-link { color: var(--muted); font-weight: 600; }
.result-panel { text-align: center; max-width: 560px; margin: 0 auto; }
.result-icon { font-size: 2.4rem; margin-bottom: 8px; }
.result-icon.ok { color: var(--ok); }
.result-icon.bad { color: var(--bad); }
.result-icon.warn { color: var(--warn); }
.result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.portal-login-body {
    font-family: var(--font);
    min-height: 100vh;
    margin: 0;
    background: #0b1726;
}
.portal-login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
}
.portal-login-hero {
    position: relative;
    background:
        linear-gradient(160deg, rgba(9, 74, 132, 0.55), rgba(11, 23, 38, 0.75)),
        url("https://images.unsplash.com/photo-1451187580459-43490279c0fa?auto=format&fit=crop&w=1600&q=70") center/cover;
    color: #fff;
    padding: 48px;
    display: grid;
    align-content: end;
}
.hero-veil { position: absolute; inset: 0; background: linear-gradient(180deg, transparent, rgba(8,16,28,0.65)); }
.hero-copy { position: relative; z-index: 1; max-width: 480px; }
.hero-copy p { font-size: 1.15rem; line-height: 1.5; color: rgba(255,255,255,0.9); }
.portal-login-panel {
    background: #f7fafc;
    padding: 48px 40px;
    display: grid;
    align-content: center;
    gap: 10px;
}
.portal-login-panel h1 { margin: 0; font-size: 1.8rem; }
.lede { margin: 0 0 10px; color: var(--muted); }
.portal-login-form { display: grid; gap: 12px; }
.portal-login-form label { display: grid; gap: 6px; font-weight: 600; color: #314155; }
.portal-login-form input[type="text"],
.portal-login-form input[type="password"] {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    background: #fff;
}
.remember {
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-weight: 500 !important;
}
.support-line { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.support-line a { color: var(--brand); font-weight: 600; }

.stat-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.82rem;
    color: var(--brand);
    font-weight: 600;
}
.traffic-totals {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 0.88rem;
    font-weight: 700;
}
.traffic-totals .down { color: #2563eb; }
.traffic-totals .up { color: #0d9488; }
.portal-chart-wrap {
    margin-top: 8px;
    min-height: 220px;
}

@media (max-width: 900px) {
    .portal-stats, .invoice-detail-grid, .portal-login-shell { grid-template-columns: 1fr; }
    .portal-login-hero { min-height: 240px; padding: 28px; align-content: center; }
    .portal-user strong, .portal-nav { display: none; }
    .portal-hero-card { flex-direction: column; align-items: stretch; }
}
