/* Modern Design System for Damin's Housebook */
:root {
    /* Color Palette - Refined Teal & Soft Grays */
    --primary-h: 183;
    --primary-s: 100%;
    --primary-l: 35%;

    --color-primary: hsl(var(--primary-h), var(--primary-s), var(--primary-l));
    --color-primary-light: hsl(var(--primary-h), var(--primary-s), 45%);
    --color-primary-dark: hsl(var(--primary-h), var(--primary-s), 25%);
    --color-primary-soft: hsl(var(--primary-h), 30%, 92%);
    /* Background tint */

    --color-background: #F8F9FB;
    --color-surface: #FFFFFF;

    --color-text-main: #111827;
    /* Darker for better contrast */
    --color-text-secondary: #6B7280;
    --color-text-tertiary: #9CA3AF;

    --color-border: #E5E7EB;
    --color-border-hover: #D1D5DB;

    /* Premium Shadows */
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.025);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
    --shadow-color-primary: 0 4px 14px 0 rgba(0, 118, 129, 0.25);
    /* Softer */

    /* Typography */
    --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --color-success-bg: #D1FAE5;
    --color-error: #EF4444;
    --color-error-bg: #FEE2E2;
    --color-warning: #F59E0B;
    --color-info: #3B82F6;

    /* Typography */
    --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Spacing */
    --space-2: 0.125rem;
    /* 2px */
    --space-4: 0.25rem;
    /* 4px */
    --space-8: 0.5rem;
    /* 8px */
    --space-12: 0.75rem;
    /* 12px */
    --space-16: 1rem;
    /* 16px */
    --space-20: 1.25rem;
    /* 20px */
    --space-24: 1.5rem;
    /* 24px */
    --space-32: 2rem;
    /* 32px */

    /* Radius */
    --radius-sm: 0.375rem;
    /* 6px */
    --radius-md: 0.5rem;
    /* 8px */
    --radius-lg: 0.75rem;
    /* 12px */
    --radius-xl: 1rem;
    /* 16px */

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-color-primary: 0 4px 14px 0 rgba(0, 118, 129, 0.39);

    /* Transitions */
    --transition-base: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: var(--font-family-base);
    background-color: var(--color-background);
    color: var(--color-text-main);
    margin: 0;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-20);
    padding-bottom: 80px;
    /* Space for specific fixed elements if any */
}

/* --- Header & Nav --- */
.header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
    padding: var(--space-16) 0;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.9);
}

.nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-24);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-primary);
    margin: 0;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: var(--space-8);
}

.nav__menu {
    display: flex;
    gap: var(--space-4);
    background: var(--color-background);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
}

.nav__item {
    padding: var(--space-8) var(--space-16);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-base);
    text-decoration: none;
    user-select: none;
    white-space: nowrap;
    /* Global fix for vertical text */
    flex-shrink: 0;
}

/* ... (Existing styles) ... */

/* --- Mobile Responsiveness --- */
@media (max-width: 1024px) {
    /* Increased breakpoint for reliability */

    /* Layout & Container */
    .container {
        padding: 12px;
        padding-bottom: 80px;
        width: 100%;
        box-sizing: border-box;
    }

    .header {
        padding: 8px 0;
    }

    /* Navigation: Stacked Column */
    .nav {
        flex-direction: column !important;
        gap: 12px;
        padding: 0 12px;
        height: auto !important;
    }

    .nav__title {
        width: 100%;
        justify-content: center;
        font-size: 1.25rem;
        margin-bottom: 4px;
    }

    .nav__menu {
        width: 100%;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        justify-content: flex-start;
        padding-bottom: 8px;
        /* Room for scrollbar */
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        background: transparent;
    }

    .nav__item {
        padding: 8px 14px;
        font-size: 0.9rem;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: 20px;
        box-shadow: var(--shadow-sm);
    }

    .nav__item--active {
        background: var(--color-primary);
        color: white;
        border-color: var(--color-primary);
    }

    /* Grids to Stack */
    .dashboard-grid,
    .form-grid,
    .settings-grid,
    .settlement-detail-grid,
    .stats-summary {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px;
    }

    /* Cards */
    .card__header {
        padding: 12px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        min-height: auto;
    }

    .card__header h2,
    .card__header h3 {
        font-size: 1.1rem;
    }

    .card__body {
        padding: 16px;
    }

    /* Transaction List - Card View */
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .data-table tr {
        margin-bottom: 12px;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        padding: 16px;
        background: var(--color-surface);
        display: grid !important;
        grid-template-columns: 1fr auto;
        /* Left content, Right Amount */
        grid-template-rows: auto auto auto auto;
        gap: 8px;
        position: relative;
    }

    #transactionList td {
        padding: 0;
        border: none;
        display: block;
        text-align: left;
    }

    /* 1. Date (Top Left) */
    #transactionList td:nth-child(1) {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        font-size: 0.85rem;
        color: var(--color-text-secondary);
        font-weight: 500;
    }

    /* 2. User (Top Right next to Date? No, maybe below) -> Let's put Amount Top Right */
    /* 4. Amount (Top Right) */
    #transactionList td:nth-child(4) {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
        /* Span 2 rows for emphasis */
        text-align: right;
        font-weight: 800;
        font-size: 1.2rem;
        align-self: start;
    }

    /* 3. Category (Row 2 Left) */
    #transactionList td:nth-child(3) {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
        margin-top: 4px;
    }

    /* 2. User (Inside Category badge? or next to it) -> Let's put it next to date */
    #transactionList td:nth-child(2) {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        margin-left: 90px;
        /* Offset from date approx */
        display: none;
        /* User name is less critical if context is known, or show small */
    }

    /* 5. Account (Hidden) */
    #transactionList td:nth-child(5) {
        display: none;
    }

    /* 6. Memo (Row 3 Full) */
    #transactionList td:nth-child(6) {
        grid-column: 1 / -1;
        grid-row: 3 / 4;
        font-size: 1rem;
        font-weight: 500;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px dashed var(--color-border);
        color: var(--color-text-main);
        line-height: 1.5;
    }

    /* 7. Actions (Row 4) */
    #transactionList td:nth-child(7) {
        grid-column: 1 / -1;
        grid-row: 4 / 5;
        margin-top: 8px;
        display: flex;
        justify-content: flex-end;
        gap: 12px;
    }

    /* Fix Settings Header */
    .settings-header-row {
        display: none !important;
    }

    .item-list-row {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
    }
}

.nav__item:hover {
    color: var(--color-text-main);
    background-color: rgba(0, 0, 0, 0.03);
}

.nav__item--active {
    background-color: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

/* --- Layout Components --- */
.card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border);
    margin-bottom: var(--space-24);
    overflow: hidden;
    transition: var(--transition-base);
}

.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card__header {
    padding: var(--space-20) var(--space-24);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to right, #ffffff, #fafafa);
}

.card__header h2,
.card__header h3 {
    margin: 0;
    font-size: 1.125rem;
    /* 18px */
    font-weight: 600;
    color: var(--color-text-main);
}

.card__body {
    padding: var(--space-24);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-20);
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-base);
    border: none;
    gap: var(--space-8);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.98);
}

.btn--primary {
    background: var(--color-primary);
    color: white;
    box-shadow: var(--shadow-color-primary);
}

.btn--primary:hover {
    background: var(--color-primary-hover);
    filter: brightness(110%);
    box-shadow: 0 6px 20px rgba(0, 118, 129, 0.4);
}

.btn--secondary {
    background: white;
    color: var(--color-text-main);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.btn--secondary:hover {
    background: var(--color-background);
    border-color: var(--color-border-hover);
}

.btn--active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    border: 1px solid transparent;
}

.btn--sm {
    padding: var(--space-8) var(--space-12);
    font-size: 0.85rem;
    border-radius: var(--radius-md);
}

/* --- Form Elements --- */
.form-grid {
    display: grid;
    gap: var(--space-20);
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.form-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.form-control {
    width: 100%;
    padding: var(--space-12) var(--space-16);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    background: var(--color-surface);
    color: var(--color-text-main);
    transition: var(--transition-base);
    box-sizing: border-box;
    font-family: var(--font-family-base);
}

.form-control:hover {
    border-color: var(--color-border-hover);
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

/* --- Tables --- */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: var(--space-8);
}

.data-table th {
    text-align: left;
    padding: var(--space-12) var(--space-16);
    color: var(--color-text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

.data-table td {
    padding: var(--space-16);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-main);
    font-size: 0.95rem;
    vertical-align: middle;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background-color: var(--color-background);
}

.data-table__amount--income {
    color: var(--color-success);
    font-weight: 600;
}

.data-table__amount--expense {
    color: var(--color-error);
    font-weight: 600;
}

/* --- Calendar --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--color-border);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}

.calendar-day-header {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-weight: 700;
    text-align: center;
    padding: var(--space-12);
    font-size: 0.9rem;
}

.calendar-day {
    background: var(--color-surface);
    min-height: 120px;
    padding: var(--space-8);
    transition: background-color 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.calendar-day:hover {
    background: #FAFBFC;
}

.calendar-day__date {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.calendar-day--today .calendar-day__date {
    background: var(--color-primary);
    color: white;
}

.calendar-day--other-month {
    background: var(--color-background);
    opacity: 0.6;
}

.calendar-card {
    border-radius: var(--radius-sm);
    padding: 3px 6px;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
}

.calendar-card--income {
    background: var(--color-success-bg);
    color: #065F46;
    /* darker green for text */
}

.calendar-card--expense {
    background: var(--color-error-bg);
    color: #991B1B;
    /* darker red for text */
}

.calendar-card--expected {
    opacity: 0.5;
    border: 1px dashed currentColor;
    background: transparent !important;
}

/* --- Stats & Modules --- */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-24);
}

.stat-box {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-24);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-8);
    transition: var(--transition-base);
}

.stat-box:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary-soft);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.2;
}

/* --- Modals --- */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--color-border);
    width: 90%;
    max-width: 500px;
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(20px) scale(0.98);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

/* Page Switch Animation */
.page {
    display: none;
}

.page.page--active {
    display: block;
    animation: fadeInPage 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeInPage {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- List Items --- */
ul.item-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

ul.item-list li {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-16);
    margin-bottom: var(--space-12);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition-base);
}

ul.item-list li:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.badge--success {
    background: var(--color-success-bg);
    color: #065F46;
}

.badge--error {
    background: var(--color-error-bg);
    color: #991B1B;
}

.badge--warning {
    background: #FEF3C7;
    color: #92400E;
}

.badge--info {
    background: #DBEAFE;
    color: #1E40AF;
}

/* --- Settlement Specific Modern UI --- */
.settlement-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
}

.settlement-header__user {
    margin-bottom: 0;
    width: 180px;
}

.settlement-header__period {
    flex: 1;
}

#settlement-period-display {
    font-size: 0.95rem;
    padding: 8px 16px;
    border-radius: 8px;
}

.settlement-summary-card {
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
    color: white;
    border-radius: var(--radius-xl);
    padding: var(--space-24);
    margin-bottom: var(--space-20);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.settlement-summary-card__info h4 {
    margin: 0;
    font-size: 0.85rem;
    opacity: 0.85;
    font-weight: 500;
}

.settlement-summary-card__amount {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
}

.settlement-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-12);
    margin-bottom: var(--space-24);
}

.settlement-stat-pill {
    background: var(--color-surface);
    padding: var(--space-12);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}

.settlement-stat-pill__label {
    font-size: 0.7rem;
    color: var(--color-text-secondary);
    font-weight: 600;
    text-transform: uppercase;
}

.settlement-stat-pill__value {
    font-weight: 700;
    font-size: 1rem;
}

/* Modal Content Adjustment */
.modal-content--large {
    max-width: 600px !important;
}

#settlement-detail-items-container {
    padding-right: 4px;
}

#settlement-detail-items-container::-webkit-scrollbar {
    width: 4px;
}

#settlement-detail-items-container::-webkit-scrollbar-track {
    background: transparent;
}

#settlement-detail-items-container::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

/* --- Settings Page Enhancements --- */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: var(--space-24);
}

.settings-section {
    margin-bottom: var(--space-32);
}

.settings-section h3 {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    margin-bottom: var(--space-16);
    font-size: 1.1rem;
    color: var(--color-primary);
}

.item-list-row {
    display: flex;
    align-items: center;
    gap: var(--space-12);
    padding: var(--space-8) var(--space-12);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-8);
    transition: var(--transition-base);
}

.item-list-row:hover {
    border-color: var(--color-primary-soft);
    box-shadow: var(--shadow-sm);
}

.drag-handle {
    cursor: grab;
    color: var(--color-text-tertiary);
    font-size: 1.2rem;
    user-select: none;
}

.drag-handle:active {
    cursor: grabbing;
}

.delete-btn {
    background: none;
    border: none;
    color: var(--color-text-tertiary);
    cursor: pointer;
    font-size: 1.1rem;
    padding: var(--space-4);
    border-radius: var(--radius-sm);
    transition: var(--transition-base);
}

.delete-btn:hover {
    color: var(--color-error);
    background-color: var(--color-error-bg);
}

.preset-input-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-8);
    margin-top: var(--space-16);
    padding: var(--space-16);
    background: var(--color-background);
    border-radius: var(--radius-lg);
    border: 1px dashed var(--color-border);
}

.preset-input-row .form-control {
    flex: 1 1 100px;
    min-width: 80px;
}

.preset-input-row .btn {
    flex: 0 0 auto;
}

.top-spending-item {
    transition: var(--transition-base);
}

.top-spending-item:hover {
    opacity: 0.8;
}

.settings-card-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    padding: 0;
    margin: 0;
    list-style: none;
}

.recurring-item-row {
    display: grid;
    grid-template-columns: 80px 100px 1fr 100px 60px 40px;
    gap: 8px;
    padding: 10px;
}

.preset-item-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1.5fr 1fr 40px;
    gap: 10px;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px dashed #eee;
}

.preset-card {
    margin-bottom: 24px;
    border: 1px solid var(--color-border);
    padding: 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.preset-card__header {
    padding: 16px;
    background: #fafafa;
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
}

.preset-card__body {
    padding: 16px;
    background: white;
}

#autosave-status {
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition-base);
}

.form-control--sm {
    padding: var(--space-4) var(--space-8);
    font-size: 0.85rem;
    height: auto;
}

.settings-header-row {
    display: grid;
    grid-template-columns: 80px 100px 1fr 100px 60px 40px;
    gap: 8px;
    padding: 0 10px 8px 10px;
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
    font-weight: 600;
}

/* --- Mobile Responsiveness --- */
/* --- Mobile Responsiveness --- */
/* --- Mobile Responsiveness (Modernized) --- */
@media (max-width: 1024px) {

    /* Typography Reductions */
    html {
        font-size: 14px;
        /* Base size reduction */
    }

    body {
        -webkit-text-size-adjust: none;
        /* Prevent auto-scaling */
    }

    /* Layout & Container */
    .container {
        padding: 8px;
        /* Further reduce container padding */
        padding-bottom: 90px;
        width: 100%;
        box-sizing: border-box;
    }

    .header {
        padding: 8px 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
    }

    /* Modern Pill Navigation */
    .nav {
        flex-direction: column !important;
        gap: 12px;
        padding: 0 12px;
        height: auto !important;
    }

    .nav__title {
        width: 100%;
        justify-content: flex-start;
        /* Left align for modern look */
        font-size: 1.25rem;
        margin-bottom: 4px;
        padding-left: 4px;
    }

    /* Flex Row with HIDDEN Scrollbar */
    .nav__menu {
        width: 100%;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        justify-content: flex-start;
        padding-bottom: 0 !important;
        /* Remove padding that might show scrollbar track */
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        background: transparent;

        /* Deep Scrollbar Hiding */
        scrollbar-width: none;
        /* Firefox */
        -ms-overflow-style: none;
        /* IE 10+ */
    }

    .nav__menu::-webkit-scrollbar {
        display: none;
        /* Chrome/Safari/Webkit */
        width: 0;
        height: 0;
        background: transparent;
    }

    .nav__item {
        padding: 8px 16px;
        font-size: 0.9rem;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: 50px;
        /* Pill Shape */
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        color: var(--color-text-secondary);
        font-weight: 500;
        flex-shrink: 0;
        display: inline-flex;
        align-items: center;
        transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    .nav__item--active {
        background: var(--color-text-main);
        /* Trendy Dark/Black Active State */
        color: white;
        border-color: var(--color-text-main);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        font-weight: 600;
        transform: scale(1.02);
    }

    /* Grids to Stack */
    .dashboard-grid,
    .form-grid,
    .settings-grid,
    .settlement-detail-grid,
    .stats-summary {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px;
    }

    /* Modern Cards */
    .card {
        border: none;
        /* Cleaner look */
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
        border-radius: 16px;
    }

    .card__header {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        min-height: auto;
        background: transparent;
        border-bottom: 1px solid var(--color-background);
    }

    .card__header h2,
    .card__header h3 {
        font-size: 1.15rem;
        font-weight: 700;
    }

    .card__body {
        padding: 16px;
    }

    /* Compact Mobile Calendar */
    .calendar-grid {
        gap: 1px;
        background: var(--color-border);
        border: 1px solid var(--color-border);
        border-radius: 12px;
    }

    .calendar-day-header {
        padding: 8px 0;
        font-size: 0.8rem;
    }

    .calendar-day {
        min-height: 55px !important;
        /* Fixed small height */
        padding: 4px !important;
        display: flex;
        /* Ensure flex for centering */
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    .calendar-day__date {
        width: 20px;
        height: 20px;
        font-size: 0.75rem;
        margin-bottom: 0;
        font-weight: 600;
    }

    /* Calendar Dots Container */
    .calendar-day__cards {
        display: flex;
        flex-direction: row;
        gap: 4px;
        justify-content: center;
        flex-wrap: wrap;
        width: 100%;
    }

    /* Simplified Dots */
    .calendar-card {
        display: block !important;
        font-size: 0;
        /* Hide text */
        width: 8px;
        height: 8px;
        padding: 0;
        margin: 0;
        min-width: 0;
        border: none;
        /* Reset border */
    }

    /* Income: Green Circle */
    .calendar-card--income {
        background-color: #10B981 !important;
        border-radius: 50%;
    }

    /* Expense: Red Rounded Square (Distinct Shape) */
    .calendar-card--expense {
        background-color: #EF4444 !important;
        border-radius: 2px;
        /* Soft Square */
    }

    /* Transaction List - Modern Card View */
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .data-table tr {
        margin-bottom: 12px;
        border: 1px solid var(--color-border);
        border-radius: 16px;
        /* Rounder */
        padding: 16px;
        background: var(--color-surface);
        display: grid !important;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto auto;
        row-gap: 6px;
        column-gap: 12px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    }

    #transactionList td {
        padding: 0;
        border: none;
        display: block;
        text-align: left;
    }

    /* 1. Date (Top Left) */
    #transactionList td:nth-child(1) {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        font-size: 0.8rem;
        color: var(--color-text-tertiary);
        font-weight: 500;
        margin-left: 0;
        /* Reset */
    }

    /* 4. Amount (Top Right) */
    #transactionList td:nth-child(4) {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
        text-align: right;
        font-weight: 800;
        font-size: 1.15rem;
        align-self: start;
        color: var(--color-text-main);
    }

    /* 3. Category (Row 2 Left) */
    #transactionList td:nth-child(3) {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
        margin-top: 2px;
    }

    /* 2. User (Hidden or Small) */
    #transactionList td:nth-child(2) {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
        margin-left: 85px;
        /* Next to date */
        font-size: 0.8rem;
        color: var(--color-text-main);
        font-weight: 600;
        display: block !important;
        /* Show user name */
    }

    /* 5. Account (Hidden) */
    #transactionList td:nth-child(5) {
        display: none;
    }

    /* 6. Memo (Row 3 Full) */
    #transactionList td:nth-child(6) {
        grid-column: 1 / -1;
        grid-row: 3 / 4;
        font-size: 0.95rem;
        font-weight: 400;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px dashed var(--color-border);
        color: var(--color-text-secondary);
        line-height: 1.4;
    }

    /* 7. Actions (Row 4) */
    #transactionList td:nth-child(7) {
        grid-column: 1 / -1;
        grid-row: 4 / 5;
        margin-top: 4px;
        display: flex;
        justify-content: flex-end;
        gap: 12px;
    }

    /* Stats Box Mobile */
    .stat-box {
        padding: 16px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .stat-label {
        font-size: 0.85rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* Fix Settings Header */
    .settings-header-row {
        display: none !important;
    }

    .item-list-row {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: 8px;
    }

    .item-list-row .form-control {
        width: 100%;
    }

    /* Dashboard Summary Table Mobile Labels */
    #monthly-summary-body td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 12px;
        border-bottom: 1px solid var(--color-background);
    }

    #monthly-summary-body td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-text-secondary);
        font-size: 0.85rem;
    }

    #monthly-summary-body tr {
        margin-bottom: 16px;
        border: 1px solid var(--color-border);
        border-radius: 12px;
        overflow: hidden;
        display: block !important;
    }

    /* Settlement Header Mobile */
    .settlement-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .settlement-header__user {
        width: 100%;
    }

    /* Settings Improvements - Reset and Force Vertical */
    .settings-section .item-list-row,
    .recurring-item-row,
    .preset-item-row {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        gap: 10px !important;
        padding: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .settings-section .item-list-row .form-control,
    .recurring-item-row .form-control,
    .preset-item-row .form-control,
    .preset-item-row select {
        width: 100% !important;
        flex: none !important;
        height: 40px !important;
        /* Larger touch target */
        font-size: 1rem !important;
        margin: 4px 0 !important;
    }

    .preset-item-row .delete-btn {
        width: 100% !important;
        padding: 10px !important;
        background: var(--color-error-bg) !important;
        color: var(--color-error) !important;
        border: 1px solid var(--color-error) !important;
        border-radius: 8px !important;
        margin-top: 8px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }

    .preset-item-row .delete-btn::after {
        content: " 삭제하기";
        font-size: 0.9rem;
        margin-left: 4px;
    }

    /* Fix right-shift and cut-off in settings */
    .settings-section ul,
    .settings-card-list {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        list-style: none !important;
        overflow-x: hidden;
    }

    .preset-input-row {
        padding: 12px;
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .settings-grid {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
    }

    .preset-card {
        padding: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .preset-card__header {
        padding: 12px !important;
        flex-wrap: wrap;
        gap: 8px;
    }

    .preset-card__header input {
        width: 100% !important;
        background: white !important;
        padding: 8px !important;
        border: 1px solid var(--color-border) !important;
    }

    .preset-card__body {
        padding: 6px !important;
    }

    #view-settings .card__body {
        padding: 8px !important;
    }

    .settings-section {
        padding: 0 !important;
        width: 100% !important;
        margin-bottom: 24px !important;
    }

    /* Force all form controls to be responsive */
    .form-control {
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Modal Adjustments for mobile */
    .modal-content {
        width: 95% !important;
        margin: 10px !important;
        max-height: 90vh;
        overflow-y: auto;
    }
}