:root {
    /* Palette — overridden per-request from Admin -> Branding via an inline <style> block */
    --brand: #28AD4B;
    --secondary: #33A57B;
    --accent: #2770B7;
    --success: #38AA60;
    --warning: #BF9936;
    --error: #B22F34;
    --info: #3F65B2;

    --bg: #F5F8F6;
    --surface: #FFFFFF;
    --ink: #10241A;
    --muted: #6C7B73;
    --border: rgba(16, 36, 26, 0.09);
    --border-strong: rgba(16, 36, 26, 0.16);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16,36,26,.05), 0 10px 30px -16px rgba(16,36,26,.18);

    --font-display: 'Sora', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); margin: 0; }
button { font-family: inherit; }

.shell { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    background: rgba(255,255,255,0.86);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; min-width: 0; }
.brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--brand), var(--secondary));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem; flex-shrink: 0;
}
.brand-logo-img { width: 34px; height: 34px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.brand-text em { font-style: normal; color: var(--brand); }

.topnav-desktop { display: flex; align-items: center; gap: 6px; }
.topnav-desktop a {
    font-weight: 600; font-size: 0.9rem; padding: 9px 14px; border-radius: 999px; color: var(--muted);
}
.topnav-desktop a:hover { background: rgba(16,36,26,0.05); color: var(--ink); }
.topnav-desktop a.active { background: var(--ink); color: #fff; }

.user-chip { display: flex; align-items: center; gap: 10px; margin-left: 8px; padding-left: 14px; border-left: 1px solid var(--border); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--info)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }
.user-chip .role-badge { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--brand); }

.hamburger { display: none; width: 40px; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: #fff; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.hamburger span, .hamburger span::before, .hamburger span::after { content:''; display:block; width: 18px; height: 2px; background: var(--ink); position: relative; transition: 0.2s; }
.hamburger span::before { position: absolute; top: -6px; }
.hamburger span::after { position: absolute; top: 6px; }

.mobile-drawer {
    display: none;
    position: fixed; inset: 0; z-index: 50;
    background: rgba(16,36,26,0.4);
}
.mobile-drawer .panel {
    position: absolute; top: 0; right: 0; bottom: 0; width: min(78vw, 320px);
    background: #fff; padding: 20px; display: flex; flex-direction: column; gap: 4px;
    box-shadow: -12px 0 30px rgba(0,0,0,0.15);
}
.mobile-drawer.open { display: block; }
.mobile-drawer a.drawer-link { display: block; padding: 13px 14px; border-radius: var(--radius-sm); font-weight: 600; color: var(--ink); }
.mobile-drawer a.drawer-link.active { background: var(--ink); color: #fff; }
.mobile-drawer .drawer-user { padding: 14px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.mobile-drawer .drawer-close { align-self: flex-end; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: none; font-size: 1.1rem; }

/* ---------- Layout ---------- */
.content { flex: 1; padding: 28px 24px 60px; max-width: 1080px; margin: 0 auto; width: 100%; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 1.6rem; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 60ch; font-size: 0.94rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; justify-content: center;
    font-weight: 700; font-size: 0.88rem;
    padding: 11px 20px;
    border: none; border-radius: 999px;
    background: linear-gradient(135deg, var(--brand), var(--secondary));
    color: #fff;
    cursor: pointer;
    min-height: 42px;
    transition: transform 0.12s, box-shadow 0.12s;
    box-shadow: 0 6px 16px -8px rgba(40,173,75,0.55);
}
.btn:hover { transform: translateY(-1px); }
.btn-ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--border-strong); box-shadow: none; }
.btn-small { padding: 8px 14px; font-size: 0.8rem; min-height: 40px; }
.btn-danger { background: none; border: 1.5px solid var(--error); color: var(--error); box-shadow: none; }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-block { width: 100%; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.meter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }

.meter-card { display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.meter-card .m-name { font-family: var(--font-display); font-size: 1.08rem; font-weight: 700; margin: 0; }
.meter-card .m-meta { color: var(--muted); font-size: 0.83rem; margin-bottom: 10px; }

.odometer {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 2.1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1;
    color: var(--ink);
}
.odometer small {
    display: block;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.68rem;
    color: var(--muted);
    letter-spacing: 0.3px;
    margin-top: 8px;
    text-transform: uppercase;
}

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 0.72rem; font-weight: 700;
    padding: 4px 10px; border-radius: 999px;
    margin-top: 10px; width: fit-content;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.over { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); }
.badge.under { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.badge.neutral { color: var(--muted); background: rgba(16,36,26,0.06); }
.badge.role-admin { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.role-user { color: var(--muted); background: rgba(16,36,26,0.06); }
.badge.inactive { color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent); }

.card-footer { margin-top: 14px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 12px; }
.card-footer .amt { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; }

/* ---------- Forms ---------- */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; max-width: 520px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; font-size: 0.85rem; margin-bottom: 6px; }
.field .hint { font-size: 0.78rem; color: var(--muted); margin-top: 5px; }
input, select, textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-family: var(--font-body);
    font-size: 16px; /* keep >=16px so iOS Safari doesn't auto-zoom on focus */
    color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.form-row { display: flex; gap: 14px; }
.form-row .field { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.9rem; white-space: nowrap; }
th { font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); background: var(--bg); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #FAFBFA; }
td.num { font-variant-numeric: tabular-nums; text-align: right; font-family: var(--font-mono); }
td.wrap { white-space: normal; }

/* ---------- Bill breakdown ---------- */
.bill-lines { list-style: none; padding: 0; margin: 0; }
.bill-lines li { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 0.92rem; gap: 12px; }
.bill-lines li.total { border-top: 2px solid var(--ink); border-bottom: none; font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; padding-top: 14px; margin-top: 4px; }

/* ---------- Empty state ---------- */
.empty { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 44px 20px; text-align: center; color: var(--muted); background: #fff; }
.empty a { color: var(--brand); font-weight: 700; }

/* ---------- Misc ---------- */
.section-title { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; margin: 30px 0 14px; }
.flash { background: var(--success); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 600; font-size: 0.9rem; }
.flash.error { background: var(--error); }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 22px; }
.breadcrumb { font-size: 0.83rem; color: var(--muted); margin-bottom: 8px; }
.breadcrumb a { color: var(--accent); font-weight: 600; }

.swatch { width: 100%; height: 46px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); margin-top: 6px; }
.color-field input[type=color] { padding: 4px; height: 46px; cursor: pointer; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(150px,1fr)); gap: 14px; margin-bottom: 24px; }
.stat-box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-box .num { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; }
.stat-box .label { font-size: 0.78rem; color: var(--muted); font-weight: 600; margin-top: 2px; }

.cat-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 20% 10%, color-mix(in srgb, var(--brand) 10%, transparent), transparent 40%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); padding: 34px 30px; }
.auth-card .brand { justify-content: center; margin-bottom: 22px; font-size: 1.3rem; }
.auth-card h1 { text-align: center; font-size: 1.3rem; margin-bottom: 4px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 0.88rem; margin-bottom: 22px; }
.auth-hint { text-align: center; margin-top: 16px; font-size: 0.82rem; color: var(--muted); }

@media (max-width: 760px) {
    .topnav-desktop { display: none; }
    .hamburger { display: flex; }
    .topbar { padding: 12px 16px; }
    .content { padding: 20px 16px 90px; }
    .form-row { flex-direction: column; gap: 0; }
    .page-head { flex-direction: column; }
    .page-head .btn { width: 100%; }
    .odometer { font-size: 1.8rem; }
}

/* ---------- Responsive tables: stack as cards on narrow screens ---------- */
@media (max-width: 640px) {
    .table-wrap { border: none; background: none; overflow: visible; }
    .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap th, .table-wrap td, .table-wrap tr { display: block; }
    .table-wrap { min-width: 0; }
    .table-wrap table { min-width: 0; }
    .table-wrap thead { display: none; }
    .table-wrap tr {
        background: #fff;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        margin-bottom: 12px;
        padding: 6px 4px;
    }
    .table-wrap td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 9px 14px;
        border-bottom: 1px dashed var(--border);
        white-space: normal;
        text-align: right;
    }
    .table-wrap tr td:last-child { border-bottom: none; }
    .table-wrap td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: var(--muted);
        text-align: left;
        flex-shrink: 0;
    }
    .table-wrap td.num { font-size: 1rem; }
    .table-wrap td[data-label=""]::before,
    .table-wrap td:not([data-label])::before { content: none; }
    .table-wrap td:not([data-label]) {
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 12px;
    }
    .table-wrap td:not([data-label]) .btn { flex: 1; min-width: 90px; }
}
