/* ============================================================
   MoneyMap — Layout (layout.css)
   Responsive grid, containers, and structural layout rules.
   Mobile-first approach.
   ============================================================ */

/* ----------------------------------------------------------
   Reset & Base
---------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--color-text);
    background-color: var(--color-background);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ----------------------------------------------------------
   Container
---------------------------------------------------------- */
.container {
    width: 100%;
    max-width: var(--container-max-width);
    margin-inline: auto;
    padding-inline: var(--container-padding);
}

/* Wider padding on larger screens so content doesn't hug the edges */
@media (min-width: 768px) {
    .container {
        padding-inline: var(--space-8);
    }
}

@media (min-width: 1200px) {
    .container {
        padding-inline: var(--space-10);
    }
}

/* ----------------------------------------------------------
   Site Header
---------------------------------------------------------- */
.site-header {
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: var(--z-overlay);
    height: var(--header-height);
    display: flex;
    align-items: center;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}

.header-brand {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* ----------------------------------------------------------
   Site Footer
---------------------------------------------------------- */
.site-footer {
    margin-top: auto;
    padding-block: var(--space-6);
    border-top: 1px solid var(--color-border);
    background-color: var(--color-surface);
}

/* ----------------------------------------------------------
   Main Content
---------------------------------------------------------- */
main {
    flex: 1;
    padding-block: var(--space-8);
}

/* ----------------------------------------------------------
   Sections
---------------------------------------------------------- */
.section {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-bottom: var(--space-6);
}

.section-welcome {
    background-color: var(--color-surface-alt);
}

/* ----------------------------------------------------------
   Main Grid: Expenses + Visualization
   Mobile/tablet: single column (stacked)
   Desktop (≥1024px): two columns side-by-side, equal width
   Both sections keep their .section box styling.
   align-items: start so neither box stretches to match the other.
---------------------------------------------------------- */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}

@media (min-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr 1fr;
        align-items: start;   /* each column sizes to its own content; JS handles height sync */
    }
    .main-grid .section {
        margin-bottom: 0;
    }
    /* Expenses section is a flex column so form stays pinned and list can scroll */
    .section-expenses {
        display: flex;
        flex-direction: column;
        overflow: hidden;
        /* max-height is set dynamically by JS to match the visualization column */
    }
    .section-expenses .expense-form-wrapper {
        flex-shrink: 0;
    }
    .section-expenses .expense-list-wrapper {
        flex: 1;
        overflow-y: auto;
        min-height: 0;
        padding-right: var(--space-3);
    }
}

/* ----------------------------------------------------------
   Dashboard Grid (legacy — kept for potential future use)
   Mobile: single column
   Desktop: two equal columns
---------------------------------------------------------- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}

@media (min-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

/* Remove bottom margin from sections inside the grid
   so the grid gap controls spacing */
.dashboard-grid .section {
    margin-bottom: 0;
}

/* ----------------------------------------------------------
   Income Fields
   Mobile: stacked; tablet+: side by side
---------------------------------------------------------- */
.income-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

@media (min-width: 520px) {
    .income-fields {
        grid-template-columns: 1fr 1fr;
    }
}

/* ----------------------------------------------------------
   Expense Form Fields
   Mobile: stacked
   Tablet+: three columns
---------------------------------------------------------- */
.expense-form-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

@media (min-width: 600px) {
    .expense-form-fields {
        grid-template-columns: 1fr 1fr;
    }
    /* Amount spans full width on its own row when in 2-col */
    .expense-form-fields .form-group:last-child {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1200px) {
    .expense-form-fields {
        grid-template-columns: 1.2fr 2fr 1fr;
    }
    .expense-form-fields .form-group:last-child {
        grid-column: auto;
    }
}

/* ----------------------------------------------------------
   Metrics Grid
   Mobile: 2 columns
   Desktop: 2×2 grid
---------------------------------------------------------- */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

/* ----------------------------------------------------------
   Visualization Layout
   Mobile: stacked
   Tablet+: chart left, legend right
---------------------------------------------------------- */
.viz-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-8);
    align-items: center;
}

@media (min-width: 640px) {
    .viz-layout {
        grid-template-columns: 220px 1fr;
        gap: var(--space-8);
        align-items: start;
    }
}

/* ----------------------------------------------------------
   Expense List
   Cards stack on all sizes; row-style on wide screens
---------------------------------------------------------- */
.expense-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/* ----------------------------------------------------------
   Hidden attribute — ensure it always wins over display: flex/grid
   set by component classes (e.g. .alert, .viz-content).
---------------------------------------------------------- */
[hidden] {
    display: none !important;
}

/* ----------------------------------------------------------
   Utilities — visually hidden (for screen readers)
---------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip to main content link (keyboard nav) */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    background: var(--color-primary);
    color: var(--color-background);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-weight: var(--font-weight-semibold);
    z-index: var(--z-modal);
    text-decoration: none;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-4);
}
