:root {
    color-scheme: light;
    --bg: #eef3f1;
    --surface: #f9fbfa;
    --panel: #ffffff;
    --ink: #121a2c;
    --muted: #667085;
    --soft: #e7ecea;
    --line: #d7dfdd;
    --brand: #0f6b68;
    --brand-dark: #0a3f43;
    --amber: #d9791f;
    --blue: #2d5bff;
    --bad: #b42318;
    --ok: #13795b;
    --shadow: 0 18px 45px rgba(25, 38, 59, .10);
    --shadow-soft: 0 8px 24px rgba(25, 38, 59, .07);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .88), rgba(238, 243, 241, .92)),
        repeating-linear-gradient(90deg, rgba(15, 107, 104, .045) 0 1px, transparent 1px 78px),
        var(--bg);
    color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: var(--brand); text-decoration: none; font-weight: 800; }

.shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 20px 0 46px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding: 10px 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-weight: 950;
    box-shadow: 0 12px 26px rgba(15, 107, 104, .22);
}

.brand strong { display: block; font-size: 16px; }
.brand small { display: block; color: var(--muted); font-weight: 650; }

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .72);
}

.main-nav a {
    padding: 8px 11px;
    border-radius: 8px;
    color: #475467;
    font-size: 13px;
}

.main-nav a.active {
    background: var(--brand);
    color: #fff;
}

.hero {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin: 0 0 18px;
}

.page-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin: 8px 0 18px;
    padding: 22px 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .78);
    box-shadow: var(--shadow-soft);
}

.page-head h1 {
    margin: 0;
    font-size: clamp(34px, 4.6vw, 58px);
    line-height: 1;
}

.hero-dashboard {
    padding: 22px 24px;
    border: 1px solid rgba(215, 223, 221, .9);
    border-radius: 12px;
    background: rgba(255, 255, 255, .72);
    box-shadow: var(--shadow-soft);
}

.hero h1,
.auth-copy h1 {
    margin: 0;
    max-width: 760px;
    font-size: clamp(32px, 4.1vw, 54px);
    line-height: 1;
    letter-spacing: 0;
}

.hero-setup {
    display: block;
    margin-top: 10px;
    margin-bottom: 14px;
}

.hero-setup h1 {
    font-size: clamp(34px, 5vw, 64px);
}

.lead {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 18px;
    font-weight: 700;
}

.eyebrow {
    margin: 0 0 9px;
    color: var(--amber);
    font-weight: 950;
    text-transform: uppercase;
    font-size: 12px;
}

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 390px;
    gap: 34px;
    align-items: center;
    min-height: 72vh;
}

.auth-copy p:last-child {
    color: var(--muted);
    max-width: 520px;
    font-size: 18px;
}

.panel,
.stat,
.setup-preview {
    background: rgba(255, 255, 255, .94);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
}

.panel { padding: 18px; }
.panel h2,
.auth-card h2 {
    margin: 0 0 15px;
    font-size: 18px;
    letter-spacing: 0;
}

.grid { display: grid; gap: 16px; }

.forms {
    grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
    align-items: start;
    margin-bottom: 18px;
}

.tracking-forms {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
}

.tracking-card {
    display: flex;
    flex-direction: column;
    min-height: 300px;
}

.tracking-card > label,
.tracking-card > .split,
.tracking-card > .period-fields,
.tracking-card > .form-hint {
    margin-bottom: 10px;
}

.period-fields[hidden] {
    display: none;
}

.tracking-card button[type="submit"] {
    margin-top: auto;
}

.action-row {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
}

.setup-grid {
    grid-template-columns: minmax(320px, 460px) minmax(0, 1fr);
    gap: 22px;
    align-items: stretch;
}

.manage-grid {
    grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
    align-items: start;
}

.setup-card {
    padding: 22px;
    min-height: 100%;
}

.setup-preview {
    position: relative;
    overflow: hidden;
    min-height: 270px;
    padding: 26px;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(10, 63, 67, .96), rgba(15, 107, 104, .9)),
        var(--brand-dark);
}

.preview-meter {
    position: relative;
    z-index: 1;
    display: grid;
    align-content: end;
    min-height: 158px;
    max-width: 410px;
}

.preview-meter span {
    width: 52px;
    height: 52px;
    margin-bottom: 18px;
    border-radius: 14px;
    background:
        linear-gradient(90deg, #fff 0 40%, transparent 40% 52%, #fff 52% 100%),
        rgba(255, 255, 255, .22);
    opacity: .92;
}

.preview-meter strong {
    font-size: clamp(38px, 5vw, 62px);
    line-height: 1;
    letter-spacing: 0;
}

.preview-meter small {
    margin-top: 8px;
    color: rgba(255, 255, 255, .76);
    font-weight: 750;
}

.preview-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 24px;
}

.preview-grid div {
    padding: 13px;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 10px;
    background: rgba(255, 255, 255, .10);
}

.preview-grid b,
.preview-grid span {
    display: block;
}

.preview-grid b {
    font-size: 22px;
}

.preview-grid span {
    color: rgba(255, 255, 255, .78);
    font-size: 12px;
    font-weight: 800;
}

.dashboard,
.tables {
    grid-template-columns: 1.1fr .9fr;
    margin-top: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.panel-head h2 {
    margin: 0;
}

.mini-tabs {
    display: inline-grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.mini-tabs button {
    min-height: 32px;
    margin: 0;
    padding: 0 10px;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

.mini-tabs button.active {
    background: var(--brand);
    color: #fff;
}

.timeline-legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.timeline-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 28px;
    margin: 0;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8fafc;
    color: var(--muted);
    box-shadow: none;
    font-size: 11px;
    font-weight: 800;
    justify-content: flex-start;
}

.timeline-chip.active {
    border-color: rgba(15, 107, 104, .22);
    background: rgba(15, 107, 104, .09);
    color: var(--ink);
}

.timeline-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex: 0 0 10px;
}

.timeline-chip span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timeline-toolbar {
    margin-bottom: 10px;
}

.timeline-toolbar .detail-tabs {
    grid-template-columns: repeat(4, 1fr);
}

.timeline-toolbar .detail-tabs button {
    min-height: 34px;
}

label {
    display: grid;
    gap: 7px;
    color: #566176;
    font-weight: 850;
    font-size: 13px;
}

.form-hint {
    margin: -6px 0 12px;
    color: var(--muted);
    font-weight: 800;
}

.form-feedback {
    margin: -4px 0 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font-weight: 800;
}

.form-feedback.ok {
    border-color: #c5eadc;
    background: #e5f5ef;
    color: var(--ok);
}

.form-feedback.bad {
    border-color: #facaca;
    background: #fdecec;
    color: var(--bad);
}

input,
select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 750;
    line-height: 1.2;
    outline: none;
    transition: border-color .16s ease, box-shadow .16s ease;
}

input:focus,
select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(15, 107, 104, .12);
}

input[type="color"] {
    padding: 5px;
}

button {
    width: 100%;
    min-height: 44px;
    margin-top: 14px;
    border: 0;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font-weight: 950;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(15, 107, 104, .18);
}

.button-secondary {
    width: auto;
    min-width: 190px;
    margin: 0;
    padding: 0 16px;
    background: #e3eeec;
    color: var(--brand-dark);
    box-shadow: none;
}

.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 15px;
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    font-weight: 950;
    white-space: nowrap;
    box-shadow: 0 10px 20px rgba(15, 107, 104, .16);
}

.icon-button {
    display: grid;
    place-items: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
    margin: 0;
    padding: 0;
    border-radius: 8px;
    background: #eef3f1;
    color: var(--ink);
    box-shadow: none;
    font-size: 24px;
    line-height: 1;
}

button:hover { filter: brightness(.96); }
button:disabled {
    background: #94a3b8;
    box-shadow: none;
    cursor: not-allowed;
}

.ghost {
    width: auto;
    margin: 0;
    padding: 0 17px;
    background: #e3eeec;
    color: var(--brand-dark);
    box-shadow: none;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
}

.compact {
    grid-template-columns: minmax(0, 1fr) 72px;
}

.auth-card {
    display: grid;
    gap: 13px;
    padding: 24px;
}

.auth-card button { margin-top: 2px; }

.flash {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 10px;
    font-weight: 850;
    border: 1px solid transparent;
}

.flash.ok {
    background: #e5f5ef;
    border-color: #c5eadc;
    color: var(--ok);
}

.flash.bad {
    background: #fdecec;
    border-color: #facaca;
    color: var(--bad);
}

.meter-switch {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
    gap: 12px;
    min-width: min(520px, 100%);
}

.meter-switch label:only-child {
    grid-column: 2;
}

.empty-panel {
    max-width: 520px;
}

.empty-panel p {
    margin: -4px 0 16px;
}

.modal {
    width: min(440px, calc(100% - 24px));
    padding: 0;
    border: 0;
    background: transparent;
}

.detail-modal {
    width: min(900px, calc(100% - 24px));
}

.modal::backdrop {
    background: rgba(18, 26, 44, .48);
    backdrop-filter: blur(6px);
}

.modal-card {
    display: grid;
    gap: 12px;
    width: 100%;
    margin: 0;
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-head h2 {
    margin: 0;
}

.modal-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-weight: 800;
}

.detail-card {
    border-radius: 18px;
    border-color: #d7e1de;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(246, 249, 248, .96)),
        #fff;
    max-height: min(84vh, 620px);
    overflow: auto;
    box-shadow: 0 28px 70px rgba(18, 26, 44, .16);
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.detail-stats div {
    padding: 12px 14px;
    border: 1px solid #d9e3e0;
    border-radius: 14px;
    background: rgba(255, 255, 255, .86);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.detail-stats span {
    display: block;
    color: var(--muted);
    font-weight: 850;
}

.detail-stats strong {
    display: block;
    margin-top: 3px;
    font-size: 24px;
    line-height: 1.05;
}

.detail-stats small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-weight: 800;
}

.detail-stat-accent {
    position: relative;
    overflow: hidden;
}

.detail-stat-accent::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg, var(--brand), var(--amber));
}

.detail-tabs,
.chart-mode {
    display: grid;
    gap: 6px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
}

.detail-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 4px;
    border: 1px solid #d9e3e0;
    border-radius: 16px;
    background: rgba(255, 255, 255, .76);
}

.detail-tabs {
    grid-template-columns: repeat(4, 1fr);
    border: 0;
    padding: 0;
    background: transparent;
}

.chart-mode {
    grid-template-columns: repeat(2, 1fr);
    width: min(250px, 100%);
    border: 0;
    padding: 0;
    background: transparent;
}

.detail-tabs button,
.chart-mode button {
    min-height: 38px;
    margin: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

.detail-tabs button.active,
.chart-mode button.active {
    background: var(--brand);
    color: #fff;
}

.detail-chart {
    width: 100%;
    cursor: crosshair;
    margin-top: 2px;
    border-top: 1px solid #edf1f5;
    padding-top: 8px;
}

.detail-nav {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    gap: 10px;
    align-items: center;
    margin-top: -2px;
}

.detail-range {
    text-align: center;
    font-size: 14px;
    line-height: 1.2;
}

.detail-nav-btn {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    margin: 0;
    padding: 0;
    border-radius: 12px;
    background: #f3f7f6;
    color: var(--ink);
    box-shadow: none;
    font-size: 24px;
}

.detail-nav-btn:disabled {
    opacity: .45;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 18px 0 16px;
}

.stat {
    padding: 16px;
}

.stat span,
.stat small {
    display: block;
    color: var(--muted);
    font-weight: 800;
}

.stat strong {
    display: block;
    margin: 5px 0 4px;
    font-size: clamp(23px, 2.8vw, 32px);
    line-height: 1.05;
    letter-spacing: 0;
}

.stat.accent {
    background: #fff7eb;
    border-color: #f1c987;
}

.period {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin: 0 0 16px;
    padding: 15px 18px;
}

.period h2,
.period p {
    margin: 0;
}

.period p {
    color: var(--muted);
    font-weight: 750;
}

.progress {
    flex: 1;
    height: 12px;
    min-width: 110px;
    border-radius: 999px;
    overflow: hidden;
    background: #e2e8f0;
}

.progress span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--brand), var(--amber));
}

.bars {
    display: grid;
    gap: 14px;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.bar-row span,
.consumer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-weight: 850;
}

.consumer-link {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ink);
    box-shadow: none;
    text-align: left;
}

.consumer-link:hover {
    filter: none;
    color: var(--brand);
}

.bar-row i,
.consumer-link i {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.bar-row b {
    font-variant-numeric: tabular-nums;
}

.bar-row em {
    grid-column: 1 / -1;
    height: 9px;
    border-radius: 99px;
    background: #edf2f7;
    overflow: hidden;
}

.bar-row em span {
    display: block;
    height: 100%;
}

.table {
    display: grid;
    gap: 2px;
}

.table > div {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 8px 0;
    border-bottom: 1px solid #edf1f5;
}

.usage-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    padding: 2px 0;
}

.reading-row {
    align-items: center;
}

.usage-copy {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.usage-name {
    display: block;
    font-size: 14px;
    line-height: 1.2;
}

.usage-meta {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.2;
}

.usage-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.usage-value {
    min-width: 88px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

.delete-button {
    width: 28px;
    min-width: 28px;
    height: 28px;
    min-height: 28px;
    margin: 0;
    padding: 0;
    border-radius: 999px;
    background: #f5f7fa;
    color: var(--bad);
    box-shadow: none;
    font-size: 14px;
    font-weight: 900;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #edf1f5;
}

.pagination-info {
    margin-right: auto;
    color: var(--muted);
}

.pagination a,
.pagination span {
    font-weight: 800;
}

.pagination-link,
.pagination-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: #f5f7fa;
    font-size: 13px;
}

.pagination-current {
    color: var(--ink);
}

.table span {
    color: var(--muted);
    font-weight: 750;
}

.muted {
    color: var(--muted);
    font-weight: 750;
}

canvas {
    width: 100%;
    max-width: 100%;
}

#usageChart {
    margin-top: 2px;
}

@media (max-width: 980px) {
    .setup-grid,
    .manage-grid,
    .auth-layout,
    .dashboard,
    .tables {
        grid-template-columns: 1fr;
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .shell {
        width: min(100% - 18px, 1180px);
        padding-top: 10px;
    }

    .topbar,
    .top-actions,
    .page-head,
    .hero,
    .period {
        align-items: stretch;
        flex-direction: column;
    }

    .hero-dashboard {
        padding: 18px;
    }

    .timeline-legend {
        grid-template-columns: 1fr;
    }

    .hero h1,
    .auth-copy h1,
    .hero-setup h1 {
        font-size: 36px;
    }

    .lead {
        font-size: 16px;
    }

    .forms,
    .stats {
        grid-template-columns: 1fr;
    }

    .action-row {
        justify-content: stretch;
    }

    .button-secondary {
        width: 100%;
    }

    .split {
        grid-template-columns: 1fr;
    }

    .compact {
        grid-template-columns: 1fr 76px;
    }

    .meter-switch {
        grid-template-columns: 1fr;
        min-width: 0;
        width: 100%;
    }

    .meter-switch label:only-child {
        grid-column: auto;
    }

    .main-nav {
        width: 100%;
    }

    .main-nav a {
        flex: 1;
        text-align: center;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }

    .stat strong {
        font-size: 28px;
    }

    .detail-stats,
    .detail-tabs,
    .chart-mode {
        grid-template-columns: 1fr;
    }

    .detail-toolbar {
        grid-template-columns: 1fr;
    }
}
