:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --bg-start: #ffffff;
    --surface: #ffffff;
    --surface-panel: rgba(255, 255, 255, 0.88);
    --surface-elevated: #ffffff;
    --surface-soft: #f0f4f8;
    --text: #15171a;
    --text-soft: #344054;
    --muted: #667085;
    --line: #d8dee7;
    --line-soft: rgba(216, 222, 231, 0.9);
    --sidebar-bg: rgba(255, 255, 255, 0.78);
    --primary: #2563eb;
    --primary-dark: #1746a2;
    --green: #16845b;
    --red: #c24137;
    --amber: #b7791f;
    --danger-bg: #fff1ef;
    --danger-line: #ffd5d0;
    --success-bg: #ecfdf5;
    --success-line: #bbf7d0;
    --warning-bg: #fff8eb;
    --warning-line: #fed7aa;
    --track: #e5eaf1;
    --shadow: 0 18px 48px rgba(31, 41, 55, 0.10);
    --radius: 8px;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f141b;
    --bg-start: #151b24;
    --surface: #171e28;
    --surface-panel: rgba(23, 30, 40, 0.9);
    --surface-elevated: #1d2632;
    --surface-soft: #222d3a;
    --text: #eef3f8;
    --text-soft: #c9d3df;
    --muted: #93a2b3;
    --line: #334052;
    --line-soft: rgba(51, 64, 82, 0.88);
    --sidebar-bg: rgba(18, 24, 33, 0.86);
    --primary: #6ea8ff;
    --primary-dark: #3f7ddd;
    --green: #5fd0a5;
    --red: #ff8b82;
    --amber: #f3c36b;
    --danger-bg: rgba(194, 65, 55, 0.14);
    --danger-line: rgba(255, 139, 130, 0.34);
    --success-bg: rgba(22, 132, 91, 0.15);
    --success-line: rgba(95, 208, 165, 0.34);
    --warning-bg: rgba(183, 121, 31, 0.16);
    --warning-line: rgba(243, 195, 107, 0.36);
    --track: #293544;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    overflow-x: hidden;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg) 38%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-shell {
    width: min(100%, 456px);
}

.auth-panel,
.panel,
.metric-card {
    background: var(--surface-panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.auth-panel {
    padding: clamp(24px, 6vw, 42px);
}

.brand-lockup {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 750;
    color: var(--text);
}

.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 8px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--text), var(--primary));
    font-size: 0.95rem;
    font-weight: 850;
}

.auth-copy {
    margin: 42px 0 24px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 8px;
    font-size: clamp(2rem, 7vw, 3.4rem);
    line-height: 0.98;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 0;
    font-size: 1.05rem;
    letter-spacing: 0;
}

.auth-copy p:last-child {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.6;
}

.form-stack,
.form-grid {
    display: grid;
    gap: 16px;
}

.form-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
}

.form-grid.compact {
    gap: 12px;
}

.full {
    grid-column: 1 / -1;
}

label {
    display: grid;
    gap: 7px;
}

label span {
    color: var(--text-soft);
    font-size: 0.88rem;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    color: var(--text);
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input:focus,
select:focus {
    border-color: rgba(37, 99, 235, 0.65);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    color: #ffffff;
    background: var(--primary);
    box-shadow: 0 12px 28px rgba(37, 99, 235, 0.23);
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    color: var(--text);
    background: var(--surface-elevated);
    border-color: var(--line);
}

.button-danger {
    color: var(--red);
    background: var(--danger-bg);
    border-color: var(--danger-line);
}

.auth-switch {
    margin: 20px 0 0;
    color: var(--muted);
    text-align: center;
}

.auth-switch a,
.panel-heading a {
    color: var(--primary);
    font-weight: 800;
}

.alert {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 700;
    transition: opacity 0.25s ease;
}

.alert-error {
    color: var(--red);
    background: var(--danger-bg);
    border: 1px solid var(--danger-line);
}

.alert-success {
    color: var(--green);
    background: var(--success-bg);
    border: 1px solid var(--success-line);
}

.alert.is-fading {
    opacity: 0.72;
}

.app-shell {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    gap: 18px;
    padding: 18px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--line-soft);
    backdrop-filter: blur(18px);
}

.nav-list {
    display: grid;
    gap: 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    min-height: 42px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-weight: 750;
    text-align: left;
}

.nav-item:hover,
.nav-item.active {
    color: var(--text);
    background: var(--surface-soft);
}

.nav-item.muted {
    margin-top: auto;
    color: var(--muted);
}

.theme-toggle {
    display: grid;
    width: 42px;
    min-height: 42px;
    place-items: center;
    align-self: flex-start;
    padding: 0;
    cursor: pointer;
    color: var(--text);
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    font-size: 1.12rem;
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--surface-soft);
}

.sidebar .theme-toggle {
    margin-top: auto;
}

.sidebar .theme-toggle + .nav-item.muted {
    margin-top: 0;
}

.theme-toggle-floating {
    position: fixed;
    top: 18px;
    right: 18px;
    display: grid;
    width: 42px;
    min-height: 40px;
    place-items: center;
    padding: 0;
    color: var(--text);
    background: var(--surface-panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    font-size: 1.12rem;
    font-weight: 800;
    line-height: 1;
    z-index: 20;
}

.mobile-menu-btn,
.sidebar-overlay {
    display: none;
}

.content {
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: clamp(18px, 2.4vw, 32px);
}

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

.topbar h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.8rem);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.insight-card {
    display: grid;
    align-content: start;
    gap: 12px;
}

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

.mini-metrics div {
    display: grid;
    gap: 5px;
    padding: 12px;
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.mini-metrics span,
.insight-card small {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.mini-metrics strong,
.insight-value {
    color: var(--text);
    font-size: 1.28rem;
    font-weight: 850;
}

.compact-alert {
    margin-bottom: 0;
    padding: 10px 12px;
    font-size: 0.86rem;
}

.metric-card {
    display: grid;
    gap: 8px;
    min-height: 128px;
    padding: clamp(16px, 2vw, 20px);
}

.metric-card.highlight {
    color: #ffffff;
    background: linear-gradient(135deg, #15171a, #2452b8);
    border-color: transparent;
}

.metric-card span,
.metric-card small {
    color: inherit;
    opacity: 0.72;
}

.metric-card strong {
    font-size: clamp(1.45rem, 3vw, 2.2rem);
    letter-spacing: 0;
}

.positive {
    color: var(--green);
}

.negative {
    color: var(--red);
}

.two-column {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 390px), 1fr));
    gap: 18px;
}

.align-start {
    align-items: start;
}

.panel {
    min-width: 0;
    padding: 20px;
}

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

.panel-heading span {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.list,
.goal-list {
    display: grid;
    gap: 10px;
}

.list-row,
.goal-item {
    padding: 14px;
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

.list-row div,
.goal-title {
    display: grid;
    gap: 4px;
}

.list-row span,
.goal-item small {
    color: var(--muted);
    font-size: 0.9rem;
}

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

.goal-title span {
    color: var(--primary);
    font-weight: 850;
}

.progress-track {
    height: 9px;
    margin: 12px 0 8px;
    overflow: hidden;
    background: var(--track);
    border-radius: 999px;
}

.progress-track span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--green));
    border-radius: inherit;
}

.goal-adjust-form {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto auto;
    gap: 8px;
    align-items: end;
    margin-top: 14px;
}

.goal-adjust-form label {
    gap: 5px;
}

.goal-adjust-form input {
    min-height: 40px;
}

.goal-adjust-form .button {
    min-height: 40px;
    padding: 8px 12px;
}

.investment-chart {
    display: grid;
    grid-template-columns: minmax(110px, 140px) minmax(0, 1fr);
    gap: 18px;
    align-items: center;
}

.donut-chart {
    position: relative;
    display: grid;
    width: min(140px, 100%);
    aspect-ratio: 1;
    place-items: center;
    border-radius: 50%;
    background: var(--track);
}

.donut-chart::after {
    position: absolute;
    width: 58%;
    aspect-ratio: 1;
    content: "";
    background: var(--surface-elevated);
    border-radius: 50%;
}

.donut-chart span {
    position: relative;
    z-index: 1;
    color: var(--text);
    font-weight: 850;
}

.chart-list,
.bar-list {
    display: grid;
    gap: 10px;
}

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

.chart-row small {
    grid-column: 2;
    color: var(--muted);
    font-weight: 650;
}

.chart-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.bar-row {
    display: grid;
    gap: 8px;
    padding: 13px;
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.bar-row div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bar-row span {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 650;
}

.bar-track {
    height: 9px;
    overflow: hidden;
    background: var(--track);
    border-radius: 999px;
}

.bar-track span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--green));
    border-radius: inherit;
}

.monthly-chart {
    display: grid;
    min-height: 180px;
    grid-template-columns: repeat(12, minmax(28px, 1fr));
    gap: 8px;
    align-items: end;
    padding-top: 10px;
}

.month-bar {
    display: grid;
    min-height: 150px;
    align-items: end;
    gap: 8px;
}

.month-bar span {
    display: block;
    min-height: 8px;
    background: linear-gradient(180deg, var(--primary), var(--green));
    border-radius: 8px 8px 3px 3px;
}

.month-bar small {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 750;
    text-align: center;
}

.empty-state {
    margin: 0;
    color: var(--muted);
    text-align: center;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 6px 10px;
    color: var(--text-soft);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 750;
}

.chip.income {
    color: var(--green);
    background: var(--success-bg);
    border-color: var(--success-line);
}

.chip.expense {
    color: var(--red);
    background: var(--danger-bg);
    border-color: var(--danger-line);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.check-row {
    display: flex;
    min-height: 46px;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

.admin-list {
    display: grid;
    gap: 14px;
}

.admin-account {
    display: grid;
    gap: 14px;
    padding: 14px;
    background: var(--surface-elevated);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.admin-account-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.admin-account-title div {
    display: grid;
    gap: 4px;
}

.admin-account-title span,
td small {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 650;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text-soft);
    background: var(--surface-soft);
    font-size: 0.78rem;
    font-weight: 850;
}

.badge.active,
.badge.paid {
    color: var(--green);
    background: var(--success-bg);
    border-color: var(--success-line);
}

.badge.blocked,
.badge.canceled {
    color: var(--red);
    background: var(--danger-bg);
    border-color: var(--danger-line);
}

.badge.expired,
.badge.pending {
    color: var(--amber);
    background: var(--warning-bg);
    border-color: var(--warning-line);
}

.inline-form {
    display: inline-flex;
    margin: 2px 4px 2px 0;
}

.inline-form .button {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.85rem;
}

table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
}

th,
td {
    padding: 12px 9px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
}

td {
    color: var(--text-soft);
    font-weight: 650;
}

.text-right {
    text-align: right;
}

@media (max-width: 980px) {
    body.sidebar-open {
        overflow: hidden;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .mobile-menu-btn {
        position: fixed;
        top: 14px;
        left: 14px;
        z-index: 80;
        display: grid;
        width: 44px;
        height: 44px;
        place-items: center;
        gap: 4px;
        padding: 11px;
        background: var(--surface-panel);
        border: 1px solid var(--line);
        border-radius: 8px;
        box-shadow: var(--shadow);
    }

    .mobile-menu-btn span {
        display: block;
        width: 20px;
        height: 2px;
        background: var(--text);
        border-radius: 999px;
    }

    .sidebar-overlay {
        position: fixed;
        inset: 0;
        z-index: 60;
        display: block;
        pointer-events: none;
        background: rgba(0, 0, 0, 0.58);
        opacity: 0;
        transition: opacity 0.22s ease;
    }

    .sidebar-overlay.open {
        pointer-events: auto;
        opacity: 1;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 70;
        width: min(82vw, 300px);
        height: 100dvh;
        flex-direction: column;
        align-items: stretch;
        gap: 18px;
        overflow-y: auto;
        padding: 22px 18px;
        border-right: 1px solid var(--line-soft);
        border-bottom: 0;
        box-shadow: 22px 0 60px rgba(0, 0, 0, 0.28);
        transform: translateX(-100%);
        transition: transform 0.24s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .nav-list {
        display: grid;
        gap: 8px;
        min-width: 0;
    }

    .nav-item {
        width: 100%;
        min-height: 44px;
        justify-content: flex-start;
        padding: 10px 12px;
        text-align: left;
    }

    .theme-toggle {
        width: 42px;
    }

    .sidebar .theme-toggle {
        margin-top: 0;
    }

    .nav-item.muted {
        margin-top: auto;
    }

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

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

    .two-column {
        grid-template-columns: 1fr;
    }

    .content {
        padding: 72px 18px 28px;
    }
}

@media (max-width: 640px) {
    body {
        background: var(--bg);
    }

    .auth-page {
        padding: 14px;
    }

    .auth-panel,
    .panel,
    .metric-card {
        box-shadow: none;
    }

    .content {
        padding: 70px 12px 24px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar .button {
        width: 100%;
    }

    .metrics-grid,
    .form-grid,
    .mini-metrics {
        grid-template-columns: 1fr;
    }

    .metric-card {
        min-height: 112px;
    }

    .sidebar {
        width: min(86vw, 292px);
        gap: 14px;
    }

    .sidebar .brand-lockup span:last-child {
        display: inline;
    }

    .nav-list {
        display: grid;
        grid-template-columns: 1fr;
    }

    .nav-item {
        justify-content: flex-start;
        min-width: 0;
        text-align: left;
    }

    .list-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .goal-adjust-form {
        grid-template-columns: 1fr;
    }

    .investment-chart {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .chart-list {
        width: 100%;
    }

    .bar-row div:first-child {
        align-items: flex-start;
        flex-direction: column;
    }

    .monthly-chart {
        overflow-x: auto;
        grid-template-columns: repeat(12, 38px);
    }

    .panel {
        padding: 14px;
    }

    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .table-wrap {
        margin-inline: -4px;
        padding-bottom: 4px;
    }

    table {
        min-width: 560px;
        font-size: 0.88rem;
    }

    th,
    td {
        padding: 10px 8px;
    }
}

@media (max-width: 420px) {
    .topbar h1 {
        font-size: 2rem;
    }
}
