/* Reset & Base Variables */
:root {
    --deep-navy: #0A192F;
    --emerald-green: #2ECC71;
    --soft-crimson: #E74C3C;
    --bg-color: #F4F7FA;
    --card-bg: #FFFFFF;
    --text-main: #1A1A1A;
    --text-muted: #6C757D;
    --border-color: #E9ECEF;
    --input-bg: #F8F9FA;
    
    --sidebar-bg: rgba(255, 255, 255, 0.7);
    --sidebar-border: rgba(10, 25, 47, 0.08);
    
    --border-radius: 20px;
    --shadow-soft: 0 10px 30px rgba(10, 25, 47, 0.05);
    --shadow-hover: 0 16px 40px rgba(10, 25, 47, 0.08);
    --transition: all 0.3s ease;
    
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* App Layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    padding: 2.5rem 1.5rem;
    box-shadow: 2px 0 20px rgba(0,0,0,0.02);
    z-index: 10;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
    color: var(--deep-navy);
}

.brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--deep-navy);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 12px;
}

.sidebar h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.5px;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: 12px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item:hover {
    background-color: rgba(10, 25, 47, 0.04);
    color: var(--deep-navy);
}

.nav-item.active {
    background-color: var(--deep-navy);
    color: white;
    box-shadow: 0 4px 15px rgba(10, 25, 47, 0.1);
}

/* Main Content Area */
.content-area {
    flex-grow: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding: 3rem;
    position: relative;
}

.mobile-header {
    display: none;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 3rem;
    padding-bottom: 3rem;
}

/* Typography */
h1, h2, h3, h4 {
    color: var(--deep-navy);
    font-weight: 600;
}

/* Cards */
.calculator-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.calculator-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.calculator-card h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 1rem;
}

/* Inputs */
.inputs {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Segmented Control */
.target-savings-control {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.segmented-control {
    display: flex;
    background-color: var(--input-bg);
    border-radius: 12px;
    padding: 4px;
    border: 1px solid var(--border-color);
}

.segment {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.segment.active {
    background-color: white;
    color: var(--deep-navy);
    box-shadow: 0 2px 8px rgba(10, 25, 47, 0.08);
}

.input-wrapper {
    position: relative;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

input, select {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background-color: var(--input-bg);
    color: var(--text-main);
    font-family: var(--font-main);
    transition: var(--transition);
    appearance: none;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--deep-navy);
    background-color: #fff;
    box-shadow: 0 0 0 4px rgba(10, 25, 47, 0.1);
}

/* Incomes & Expenses Rows */
.transactions-header, .incomes-header, .expenses-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.transactions-header h3, .incomes-header h3, .expenses-header h3, .target-savings-header h3 {
    font-size: 1.1rem;
    margin: 0;
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--deep-navy);
}

.expense-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: center;
}

.expense-row input, .expense-row select {
    flex: 1;
}

.expense-row select.item-type {
    flex: 0.6;
}

.btn-remove {
    background: none;
    border: none;
    color: var(--soft-crimson);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    border-radius: 50%;
    transition: var(--transition);
}

.btn-remove:hover {
    background-color: rgba(231, 76, 60, 0.1);
}

/* Outputs */
.outputs {
    background-color: var(--deep-navy);
    border-radius: 16px;
    padding: 1.5rem;
    color: white;
    margin-bottom: 1.5rem;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.result-row:last-child {
    border-bottom: none;
}

.result-row span {
    font-size: 0.95rem;
    color: rgba(255,255,255,0.8);
}

.result-row strong {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Colors for positive/negative */
.positive { color: var(--emerald-green) !important; }
.negative { color: var(--soft-crimson) !important; }

.badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.badge.profit { background-color: var(--emerald-green); color: white; }
.badge.loss { background-color: var(--soft-crimson); color: white; }
.badge.neutral { background-color: rgba(255,255,255,0.2); color: white; }

.warning-badge {
    background-color: rgba(231, 76, 60, 0.2);
    color: #ff8a80;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid var(--soft-crimson);
}

/* Insight & Educational */
.insight {
    font-size: 1rem;
    color: var(--deep-navy);
    font-style: italic;
    background-color: rgba(10, 25, 47, 0.05);
    padding: 1rem;
    border-left: 4px solid var(--deep-navy);
    border-radius: 4px 12px 12px 4px;
    margin-bottom: 1.5rem;
}

.educational-content {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border-color);
}

.educational-content h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.educational-content p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Buttons */
.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--deep-navy);
    color: white;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    transform: scale(1.05);
    background-color: #1a365d;
}

.btn-secondary {
    width: 100%;
    padding: 1rem;
    background-color: transparent;
    color: var(--deep-navy);
    border: 2px solid var(--deep-navy);
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background-color: var(--deep-navy);
    color: white;
}

.app-footer {
    text-align: center;
    padding-bottom: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.timeframe-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.timeframe-input-wrapper input {
    flex: 2;
}

.timeframe-input-wrapper select {
    flex: 1;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
    }
    
    /* 1. Structural Transformation (Navigation) */
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: auto;
        padding: 0;
        background: rgba(255, 255, 255, 0.85); /* Semi-transparent background */
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: none;
        border-top: 1px solid rgba(10, 25, 47, 0.08); /* Subtle top border */
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05); /* Shadow to distinguish */
        z-index: 1000;
    }
    
    .sidebar .brand {
        display: none;
    }
    
    .nav-menu {
        flex-direction: row;
        justify-content: space-around; /* Center icons */
        align-items: center;
        padding: 0.25rem 0 0.5rem 0; 
        margin: 0;
    }
    
    .nav-item {
        flex-direction: column;
        gap: 0.25rem;
        padding: 0.5rem;
        background: transparent !important; /* Override desktop active background */
        box-shadow: none !important;
        color: var(--text-muted);
        flex: 1;
        justify-content: center;
        align-items: center;
    }
    
    .nav-item span {
        font-size: 10px; /* Microscopic labels */
        display: block;
        line-height: 1;
    }
    
    .nav-item.active {
        color: var(--deep-navy) !important; /* Active icon color */
    }

    /* 2. Layout & Content Area */
    .content-area {
        padding: 0; /* Let container expand 100% */
        padding-bottom: 90px; /* Space for the bottom nav bar */
    }
    
    .container {
        width: 100%;
        gap: 1.5rem;
        padding: 0;
    }
    
    .calculator-card {
        padding: 16px; /* Consistent 16px padding to prevent touching edges */
        border-radius: 0; /* Remove rounded corners to fit 100% width smoothly */
        border-left: none;
        border-right: none;
        box-shadow: none; 
        border-bottom: 1px solid var(--border-color); /* Separate stacked cards */
    }
    
    /* Stacking Logic */
    .segmented-control {
        flex-direction: column; /* Stack Percentage vs Fixed Amount */
    }
    
    .rapid-entry-inputs {
        flex-wrap: wrap;
    }
    #re-amount, #re-category {
        flex: 1 1 40% !important;
    }
    #re-submit-btn {
        flex: 1 1 100% !important;
        width: 100% !important;
        border-radius: 12px !important;
    }

    /* 3. Touch-Target Optimization */
    input, select, .btn-icon, .btn-secondary, .segment {
        min-height: 48px; /* 48px minimum height for fat thumbs */
    }
    
    .segment {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .inputs {
        gap: 1.5rem; /* Increase vertical spacing between input groups */
    }

    .input-group {
        gap: 0.75rem;
    }

    /* 4. Typography & Scaling */
    .calculator-card h2 {
        font-size: 1.25rem; /* Down from 1.5rem (~16% smaller) */
    }
    
    .transactions-header h3, .incomes-header h3, .expenses-header h3, .target-savings-header h3 {
        font-size: 0.95rem; /* Down from 1.1rem */
    }

    input, select {
        font-size: 16px !important; /* Minimum 16px to prevent iOS auto-zoom */
    }

    /* Existing Mobile Overrides */
    .mobile-header {
        display: flex;
        padding: 1rem 16px;
        align-items: center;
        gap: 0.75rem;
        background: var(--card-bg);
        border-bottom: 1px solid var(--border-color);
        color: var(--deep-navy);
    }

    .mobile-header h2 { 
        margin: 0; 
        font-size: 1.25rem; 
    }

    .expense-row {
        flex-direction: column;
        gap: 0.5rem;
        position: relative;
        padding-top: 1.5rem;
        border-top: 1px solid var(--border-color);
    }
    
    .btn-remove {
        position: absolute;
        top: 0;
        right: 0;
        padding: 0;
        width: 48px; /* Touch target */
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Core Web Vitals Optimization (CLS) */
.outputs {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.result-row {
    min-height: 32px;
}

/* Embed Mode */
body.embed-mode {
    background-color: transparent !important;
}
body.embed-mode .sidebar, 
body.embed-mode .mobile-header,
body.embed-mode .educational-content,
body.embed-mode .app-footer {
    display: none !important;
}
body.embed-mode .content-area {
    padding: 0 !important;
    overflow: hidden !important;
}
body.embed-mode .container {
    max-width: 100% !important;
    gap: 0 !important;
    padding: 0 !important;
}
body.embed-mode .calculator-card {
    box-shadow: none !important;
    border-radius: 0 !important;
    border: none !important;
    padding: 16px !important;
    margin: 0 !important;
}
