@import url('https://fonts.googleapis.com/css2?family=Chivo:wght@300;400;700;900&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 240 5.9% 10%;
    --radius: 0.25rem;
    --success: 160 84% 39%;
    --warning: 38 92% 50%;
    --info: 217 91% 60%;
}

body.theme-dark {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
}

* {
    box-sizing: border-box;
    border-color: hsl(var(--border));
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.2s ease, color 0.2s ease;
}

html {
    color-scheme: light;
}

body.theme-dark {
    color-scheme: dark;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Chivo', sans-serif;
}

code,
pre,
.font-mono,
.stat-value {
    font-family: 'JetBrains Mono', monospace;
}

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

img {
    max-width: 100%;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: hsl(var(--muted-foreground) / 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: hsl(var(--muted-foreground) / 0.5);
}

.app-shell {
    display: flex;
    min-height: 100vh;
    background: hsl(var(--background));
    color: hsl(var(--foreground));
}

.sidebar {
    width: 16rem;
    min-width: 16rem;
    border-right: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--background) / 0.95);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 4rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.sidebar-logo,
.login-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: var(--radius);
}

.sidebar-eyebrow,
.eyebrow,
.topbar-eyebrow,
.sidebar-meta {
    margin: 0;
    font-size: 0.72rem;
    color: hsl(var(--muted-foreground));
}

.sidebar-brand h1,
.login-brand h1,
.topbar h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 900;
    letter-spacing: -0.03em;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    font-size: 0.92rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.nav-link.active {
    border-color: hsl(var(--border) / 0.6);
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.nav-link:hover {
    background: hsl(var(--muted) / 0.7);
    color: hsl(var(--foreground));
}

.sidebar-footer {
    border-top: 1px solid hsl(var(--border) / 0.5);
    padding: 1rem;
    text-align: center;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.main-shell {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    min-height: 4rem;
    padding: 0 1.5rem;
    border-bottom: 1px solid hsl(var(--border) / 0.5);
    background: hsl(var(--background) / 0.9);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.topbar-actions,
.button-row,
.inline-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.7rem;
    border: 1px solid hsl(var(--border) / 0.6);
    border-radius: var(--radius);
    background: hsl(var(--card));
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: hsl(var(--muted));
    font-size: 0.8rem;
    font-weight: 700;
}

.user-chip-name,
.user-chip-role {
    margin: 0;
    line-height: 1.2;
}

.user-chip-name {
    font-size: 0.87rem;
    font-weight: 600;
}

.user-chip-role {
    font-size: 0.72rem;
    color: hsl(var(--muted-foreground));
}

.content-shell {
    flex: 1;
    padding: 1rem 1.5rem 2rem;
    animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-card {
    width: min(480px, 100%);
    display: grid;
    gap: 1rem;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-bottom: 0.25rem;
}

.panel,
.stat-card,
.table-wrap {
    border: 1px solid hsl(var(--border) / 0.6);
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
}

.panel,
.stat-card {
    border-radius: var(--radius);
}

.panel {
    padding: 1.25rem;
}

.table-wrap {
    border-radius: var(--radius);
    overflow: hidden;
}

.muted,
.helper-text,
.panel-head p,
.section-head p,
.stat-muted {
    color: hsl(var(--muted-foreground));
}

.flash {
    margin-bottom: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    border: 1px solid hsl(var(--border));
    background: hsl(var(--card));
    font-size: 0.94rem;
    font-weight: 600;
}

.flash-success {
    color: hsl(var(--success));
}

.flash-error {
    color: hsl(var(--destructive));
}

.flash-warning {
    color: hsl(var(--warning));
}

.auth-flash {
    width: min(480px, 100%);
}

.grid {
    display: grid;
    gap: 1.5rem;
}

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

.grid-3 {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4,
.stat-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.page-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.split-layout {
    display: grid;
    gap: 1.5rem;
    align-items: start;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

.stat-card {
    padding: 1rem;
    transition: all 0.2s ease-in-out;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.stat-card:nth-child(1) {
    background: hsl(146 64% 97%);
    border-color: hsl(141 79% 85%);
}

.stat-card:nth-child(2) {
    background: hsl(354 100% 97%);
    border-color: hsl(351 95% 89%);
}

.stat-card:nth-child(3) {
    background: hsl(0 0% 98%);
    border-color: hsl(var(--border));
}

.stat-card:nth-child(4) {
    background: hsl(214 100% 97%);
    border-color: hsl(214 95% 86%);
}

body.theme-dark .stat-card:nth-child(1),
body.theme-dark .stat-card:nth-child(2),
body.theme-dark .stat-card:nth-child(3),
body.theme-dark .stat-card:nth-child(4) {
    background: hsl(var(--card));
    border-color: hsl(var(--border));
}

.panel-title,
.section-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.stat-value {
    margin: 0.4rem 0 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.form-grid {
    display: grid;
    gap: 1rem;
}

.label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.input,
.select,
.textarea {
    width: 100%;
    padding: 0.68rem 0.85rem;
    border-radius: calc(var(--radius) - 1px);
    border: 1px solid hsl(var(--input));
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    font: inherit;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: 2px solid hsl(var(--ring) / 0.18);
    border-color: hsl(var(--ring));
}

.textarea {
    min-height: 104px;
    resize: vertical;
}

.checkbox-row,
.checkbox-list {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.checkbox-list label,
.checkbox-row label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: hsl(var(--foreground));
    font-size: 0.92rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: calc(var(--radius) - 1px);
    border: 1px solid transparent;
    padding: 0.65rem 0.95rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.button-primary {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.button-primary:hover {
    opacity: 0.92;
}

.button-secondary {
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    border-color: hsl(var(--border) / 0.6);
}

.button-secondary:hover {
    background: hsl(var(--accent));
    color: hsl(var(--accent-foreground));
}

.button-danger {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.button-danger:hover {
    opacity: 0.92;
}

.button-link {
    background: transparent;
    padding: 0;
    border: 0;
    color: hsl(var(--primary));
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid hsl(var(--border) / 0.7);
    text-align: left;
    vertical-align: top;
    font-size: 0.92rem;
}

th {
    background: hsl(240 4.8% 97.2%);
    color: hsl(var(--muted-foreground));
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-size: 0.74rem;
    font-weight: 700;
}

body.theme-dark th {
    background: hsl(240 4% 12% / 0.92);
}

tbody tr:hover {
    background: hsl(240 4.8% 95.9% / 0.45);
}

body.theme-dark tbody tr:hover {
    background: hsl(240 4% 16% / 0.72);
}

.badge {
    display: inline-block;
    padding: 0.24rem 0.55rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

.badge-success {
    background: rgb(220 252 231);
    color: rgb(21 128 61);
}

.badge-danger {
    background: rgb(254 226 226);
    color: rgb(185 28 28);
}

.badge-warning {
    background: rgb(254 243 199);
    color: rgb(180 83 9);
}

.badge-primary {
    background: rgb(237 233 254);
    color: rgb(109 40 217);
}

body.theme-dark .badge-success,
body.theme-dark .badge-danger,
body.theme-dark .badge-warning,
body.theme-dark .badge-primary {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

.chart-list {
    display: grid;
    gap: 0.85rem;
}

.chart-row {
    display: grid;
    gap: 0.8rem;
    align-items: center;
    grid-template-columns: 96px 1fr minmax(160px, auto);
}

.chart-track {
    height: 14px;
    display: flex;
    overflow: hidden;
    border-radius: 999px;
    background: hsl(var(--muted));
}

.chart-income {
    background: linear-gradient(90deg, #10b981, #34d399);
}

.chart-expense {
    background: linear-gradient(90deg, #f43f5e, #fb7185);
}

.list {
    margin: 0;
    padding-left: 1.1rem;
}

.list li + li {
    margin-top: 0.45rem;
}

.table-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.empty-state {
    padding: 1.8rem;
    text-align: center;
    color: hsl(var(--muted-foreground));
}

.section-head,
.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.section-head p,
.panel-head p {
    max-width: 62ch;
}

.danger-zone {
    border-color: hsl(var(--destructive) / 0.35);
}

@media (max-width: 1120px) {
    .grid-4,
    .stat-grid,
    .page-grid,
    .split-layout,
    .grid-3 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: static;
        width: 100%;
        min-width: 0;
        height: auto;
    }

    .topbar {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
    }

    .content-shell {
        padding: 1rem;
    }

    .grid-2,
    .chart-row {
        grid-template-columns: 1fr;
    }

    .section-head,
    .panel-head,
    .button-row,
    .topbar-actions {
        flex-direction: column;
        align-items: stretch;
    }
}
