:root {
    --font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;

    --bg: #07111f;
    --bg-elevated: rgba(12, 24, 40, 0.9);
    --bg-panel: rgba(16, 31, 52, 0.92);
    --bg-panel-strong: rgba(20, 39, 64, 0.98);
    --bg-input: rgba(7, 18, 31, 0.88);

    --text: #e8f1ff;
    --text-soft: #aebfd6;
    --text-muted: #7d93b1;

    --border: rgba(110, 160, 255, 0.16);
    --border-strong: rgba(110, 160, 255, 0.28);

    --primary: #40c4ff;
    --primary-strong: #00a8ff;
    --primary-soft: rgba(64, 196, 255, 0.14);

    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.12);

    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, 0.12);

    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, 0.12);

    --info: #38bdf8;
    --info-soft: rgba(56, 189, 248, 0.12);

    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.32);
    --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.22);
    --shadow-sm: 0 8px 18px rgba(0, 0, 0, 0.14);

    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;

    --sidebar-width: 290px;
    --content-max: 1480px;
}

html[data-theme="light"] {
    --bg: #f4f8fc;
    --bg-elevated: rgba(255, 255, 255, 0.95);
    --bg-panel: rgba(255, 255, 255, 0.96);
    --bg-panel-strong: rgba(255, 255, 255, 1);
    --bg-input: #ffffff;

    --text: #0f172a;
    --text-soft: #334155;
    --text-muted: #64748b;

    --border: rgba(15, 23, 42, 0.08);
    --border-strong: rgba(15, 23, 42, 0.16);

    --primary: #0284c7;
    --primary-strong: #0369a1;
    --primary-soft: rgba(2, 132, 199, 0.08);

    --success: #16a34a;
    --success-soft: rgba(22, 163, 74, 0.1);

    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.1);

    --warning: #d97706;
    --warning-soft: rgba(217, 119, 6, 0.1);

    --info: #0284c7;
    --info-soft: rgba(2, 132, 199, 0.1);

    --shadow-lg: 0 18px 40px rgba(15, 23, 42, 0.10);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.08);
    --shadow-sm: 0 6px 14px rgba(15, 23, 42, 0.06);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background:
        radial-gradient(circle at top right, rgba(0, 168, 255, 0.10), transparent 30%),
        radial-gradient(circle at bottom left, rgba(64, 196, 255, 0.08), transparent 28%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 18px;
}

.auth-shell {
    width: 100%;
    max-width: 520px;
}

.auth-card {
    background: linear-gradient(180deg, var(--bg-panel-strong), var(--bg-panel));
    border: 1px solid var(--border);
    border-radius: 28px;
    box-shadow: var(--shadow-lg);
    padding: 32px;
    backdrop-filter: blur(16px);
}

.auth-brand {
    margin-bottom: 24px;
}

.auth-brand h1 {
    margin: 10px 0 10px;
    font-size: clamp(2rem, 4vw, 2.5rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.auth-subtext {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.6;
}

.auth-form {
    display: grid;
    gap: 18px;
}

.auth-footer-links {
    margin-top: 22px;
    text-align: center;
    color: var(--text-soft);
}

.auth-footer-links p {
    margin: 0;
}

.app-body {
    min-height: 100vh;
}

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 18px;
    background: linear-gradient(180deg, rgba(7, 18, 31, 0.96), rgba(8, 20, 35, 0.98));
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

html[data-theme="light"] .sidebar {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 1));
}

.sidebar-top,
.sidebar-bottom {
    display: grid;
    gap: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    background: var(--primary-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: 0.08em;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.brand-text {
    display: grid;
    gap: 4px;
}

.brand-text strong {
    font-size: 1rem;
}

.brand-text span {
    font-size: 0.86rem;
    color: var(--text-muted);
}

.sidebar-nav {
    display: grid;
    gap: 8px;
}

.nav-link {
    display: block;
    padding: 12px 14px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: var(--text-soft);
    transition: 0.2s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border);
    color: var(--text);
}

html[data-theme="light"] .nav-link:hover {
    background: rgba(15, 23, 42, 0.03);
}

.nav-link.active {
    background: var(--primary-soft);
    border-color: var(--border-strong);
    color: var(--text);
    font-weight: 600;
}

.user-panel {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
}

html[data-theme="light"] .user-panel {
    background: rgba(15, 23, 42, 0.02);
}

.user-label,
.user-email {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.user-name {
    margin: 8px 0 4px;
    font-size: 1rem;
    font-weight: 600;
}

.logout-form,
.mobile-logout-form,
.inline-form {
    margin: 0;
}

.main-content {
    padding: 28px;
    width: 100%;
    max-width: var(--content-max);
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 8px 0 0;
    font-size: clamp(2rem, 3vw, 2.6rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.eyebrow {
    margin: 0;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.75rem;
    font-weight: 700;
}

.hero-panel,
.panel,
.stat-card {
    background: linear-gradient(180deg, var(--bg-panel-strong), var(--bg-panel));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(14px);
}

.hero-panel {
    padding: 28px;
    margin-bottom: 22px;
    overflow: hidden;
    position: relative;
}

.hero-panel::after {
    content: "";
    position: absolute;
    inset: auto -80px -80px auto;
    width: 240px;
    height: 240px;
    background: radial-gradient(circle, rgba(64, 196, 255, 0.18), transparent 65%);
    pointer-events: none;
}

.hero-panel-content {
    position: relative;
    z-index: 1;
    max-width: 760px;
}

.hero-panel h2 {
    margin: 10px 0 12px;
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    line-height: 1.05;
    letter-spacing: -0.03em;
}

.hero-panel p:last-child {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.7;
    max-width: 700px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.stat-card {
    padding: 22px;
}

.stat-label {
    margin: 0 0 10px;
    color: var(--text-muted);
    font-size: 0.88rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stat-card h3 {
    margin: 0 0 8px;
    font-size: clamp(1.5rem, 2.4vw, 2.1rem);
    letter-spacing: -0.03em;
}

.stat-subtext {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.6;
}

.content-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
}

.content-grid.single-column {
    grid-template-columns: 1fr;
}

.panel {
    padding: 22px;
}

.panel-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-header h2 {
    margin: 8px 0 0;
    font-size: 1.35rem;
    letter-spacing: -0.02em;
}

.text-link {
    font-weight: 600;
    white-space: nowrap;
}

.filter-panel {
    margin-bottom: 22px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.form-group {
    display: grid;
    gap: 8px;
}

.form-group-full {
    grid-column: 1 / -1;
}

label {
    font-weight: 600;
    color: var(--text-soft);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-input);
    color: var(--text);
    padding: 13px 14px;
    outline: none;
    transition: 0.2s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.field-help {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.field-error {
    margin: 0;
    color: #ff8f8f;
    font-size: 0.9rem;
    font-weight: 500;
}

html[data-theme="light"] .field-error {
    color: #b91c1c;
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 4px;
}

.btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    filter: brightness(1.04);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #ffffff;
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    filter: brightness(1.03);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.04);
}

html[data-theme="light"] .btn-ghost:hover {
    background: rgba(15, 23, 42, 0.04);
}

.btn-sm {
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.9rem;
}

.btn-block {
    width: 100%;
}

.alert {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 18px;
}

.alert p {
    margin: 0;
    line-height: 1.6;
}

.alert-success {
    background: var(--success-soft);
    border-color: rgba(34, 197, 94, 0.28);
    color: var(--text);
}

.alert-error {
    background: var(--danger-soft);
    border-color: rgba(239, 68, 68, 0.28);
    color: var(--text);
}

.alert-warning {
    background: var(--warning-soft);
    border-color: rgba(245, 158, 11, 0.28);
    color: var(--text);
}

.alert-info {
    background: var(--info-soft);
    border-color: rgba(56, 189, 248, 0.28);
    color: var(--text);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: transparent;
}

.data-table thead {
    background: rgba(255, 255, 255, 0.03);
}

html[data-theme="light"] .data-table thead {
    background: rgba(15, 23, 42, 0.03);
}

.data-table th,
.data-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table th {
    font-size: 0.86rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

html[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(15, 23, 42, 0.025);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.badge-income {
    background: var(--success-soft);
    border-color: rgba(34, 197, 94, 0.28);
    color: var(--text);
}

.badge-expense {
    background: var(--danger-soft);
    border-color: rgba(239, 68, 68, 0.28);
    color: var(--text);
}

.budget-list {
    display: grid;
    gap: 16px;
}

.budget-item {
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    background: rgba(255, 255, 255, 0.025);
}

html[data-theme="light"] .budget-item {
    background: rgba(15, 23, 42, 0.02);
}

.budget-item-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}

.budget-item-top h3 {
    margin: 0 0 6px;
    font-size: 1.08rem;
}

.budget-item-top p {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.5;
}

.budget-remaining {
    font-weight: 700;
    white-space: nowrap;
    color: var(--success);
}

.budget-remaining.over-budget {
    color: var(--danger);
}

.progress-bar {
    height: 12px;
    width: 100%;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border);
}

html[data-theme="light"] .progress-bar {
    background: rgba(15, 23, 42, 0.06);
}

.progress-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--primary-strong));
}

.budget-item-actions {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
}

.empty-state {
    border: 1px dashed var(--border-strong);
    border-radius: 18px;
    padding: 28px 20px;
    background: rgba(255, 255, 255, 0.02);
    text-align: center;
}

html[data-theme="light"] .empty-state {
    background: rgba(15, 23, 42, 0.02);
}

.empty-state h3 {
    margin: 0 0 10px;
    font-size: 1.15rem;
}

.empty-state p {
    margin: 0;
    color: var(--text-soft);
    line-height: 1.65;
    max-width: 520px;
    margin-inline: auto;
}

.theme-toggle-wrap {
    display: flex;
    justify-content: flex-start;
}

.theme-toggle {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s ease;
}

.theme-toggle:hover {
    background: var(--primary-soft);
    border-color: var(--border-strong);
}

.theme-toggle-text {
    display: inline-block;
}

.muted-text {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.mobile-topbar,
.mobile-nav {
    display: none;
}

.mobile-topbar {
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 30;
}

.mobile-brand {
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.mobile-menu-toggle {
    appearance: none;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: transparent;
    color: var(--text);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 600;
}

.mobile-nav {
    padding: 14px 18px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    grid-template-columns: 1fr;
    gap: 10px;
}

.mobile-nav.is-open {
    display: grid;
}

@media (max-width: 1180px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .content-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 960px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .mobile-topbar {
        display: flex;
    }

    .main-content {
        padding: 20px 18px 28px;
    }
}

@media (max-width: 720px) {
    .auth-card,
    .panel,
    .hero-panel,
    .stat-card {
        padding: 18px;
        border-radius: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group-full,
    .form-actions {
        grid-column: auto;
    }

    .page-header h1,
    .auth-brand h1,
    .hero-panel h2 {
        line-height: 1.12;
    }

    .budget-item-top {
        flex-direction: column;
        align-items: flex-start;
    }

    .table-wrap {
        border-radius: 14px;
    }
}

.chat-card {
    max-width: 900px;
    margin: 20px auto;
    padding: 20px;
}

.chat-status {
    margin-bottom: 12px;
    font-size: 0.95rem;
    color: #1f4d7a;
}

.chat-box {
    height: 420px;
    overflow-y: auto;
    border: 1px solid #d8dee8;
    border-radius: 10px;
    background: #f8fafc;
    padding: 15px;
    margin-bottom: 18px;
}

.chat-message {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
}

.chat-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #555;
    flex-wrap: wrap;
}

.chat-text {
    line-height: 1.5;
    color: #222;
    word-wrap: break-word;
}

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-form textarea {
    width: 100%;
    resize: vertical;
    min-height: 110px;
    padding: 12px;
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    font: inherit;
}

.chat-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.chat-form button {
    background: #1f4d7a;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    cursor: pointer;
}

.chat-form button:hover {
    background: #163a5c;
}

.chat-card {
    max-width: 900px;
    margin: 0 auto;
}