:root {
    --primary-color: #3a86ff;
    --secondary-color: #8338ec;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #00f5d4;
    --danger-color: #ff006e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(circle at 20% 20%, rgba(58, 134, 255, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(131, 56, 236, 0.1) 0%, transparent 40%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.header-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-row.nav-row {
    justify-content: flex-start;
    gap: 2rem;
    flex-wrap: wrap;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--accent-color);
}

.grid-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.2rem;
}

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

label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

input,
select {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    border-radius: 0.5rem;
    padding: 0.6rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(58, 134, 255, 0.2);
}

.button-group {
    display: flex;
    gap: 0.8rem;
    margin-top: 1rem;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 0.5rem;
    padding: 0.6rem 1.2rem;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(58, 134, 255, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-accent {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
}

.btn-accent:hover {
    background: var(--accent-color);
    color: var(--bg-dark);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

th,
td {
    padding: 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.85rem;
}

th {
    color: var(--text-secondary);
    font-weight: 500;
}

.table-input {
    width: 100%;
    padding: 0.4rem;
    background: transparent;
    border: none;
}

.table-input:focus {
    background: rgba(255, 255, 255, 0.05);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade {
    animation: fadeIn 0.5s ease forwards;
}

/* Charts */
canvas {
    width: 100% !important;
    max-height: 250px;
    margin-top: 1rem;
}

/* ========================================= */
/* Responsive & Mobile Optimization          */
/* ========================================= */

/* Grid Layouts (Desktop Default) */
.results-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.periods-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    width: 100%;
}

/* Mobile Media Query */
@media (max-width: 768px) {
    body {
        padding: 1rem;
        background-attachment: fixed;
    }

    .container {
        padding: 0;
        width: 100%;
        overflow-x: hidden;
    }

    /* Header Adjustments */
    header {
        gap: 0.8rem;
        margin-bottom: 1.5rem;
        padding-bottom: 0.8rem;
    }

    .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
    }

    .header-row h1 {
        font-size: 1.3rem;
        line-height: 1.4;
        width: 100%;
    }

    .header-row h1 span {
        display: block;
        margin-left: 0 !important;
        margin-top: 0.3rem;
        font-size: 0.8rem !important;
        color: var(--text-secondary);
    }

    /* Navigation & Action Buttons */
    .header-row.nav-row {
        gap: 1rem;
        width: 100%;
        /* No horizontal scroll on parent, handle individually */
        flex-direction: column;
        align-items: flex-start;
    }

    /* Mode Switch - Horizontal Scroll if needed, or stack */
    .mode-switch {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        /* Allow wrapping for better visibility */
        gap: 0.5rem !important;
    }

    .mode-switch button {
        flex: 1 1 auto;
        /* Grow to fill */
        justify-content: center;
        padding: 0.5rem 1rem !important;
        font-size: 0.85rem !important;
        border-radius: 12px !important;
    }

    /* Action Buttons Group */
    .button-group {
        margin-left: 0 !important;
        margin-top: 0.5rem !important;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        /* 2 cols */
        gap: 0.6rem;
    }

    /* Make Evaluate button span full width if needed, or keep in grid */
    #btn-evaluate {
        grid-column: span 2;
        background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
        justify-content: center;
        padding: 0.8rem;
    }

    .button-group button {
        justify-content: center;
        padding: 0.6rem 0.5rem !important;
        font-size: 0.85rem !important;
        width: 100%;
        border-radius: 12px;
    }

    /* Content Layouts */
    .results-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
    }

    .periods-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
    }

    .grid-inputs {
        grid-template-columns: 1fr;
        /* Stack inputs */
        gap: 1rem;
    }

    /* Input Groups */
    .input-group label {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }

    input,
    select {
        font-size: 16px;
        /* Prevent zooming on iOS */
        padding: 0.8rem;
        /* Larger touch target */
        height: 48px;
        /* Standardize height */
    }

    /* Cards */
    .glass-card {
        padding: 1.2rem;
        margin-bottom: 1.2rem;
        border-radius: 16px;
    }

    .section-title {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    /* Tables */
    /* Add wrapper for horizontal scroll if not present */
    .glass-card table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    th,
    td {
        padding: 0.8rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Special Handling for Treasury/Bond Tables */
    #treasury-row input,
    #corporate-row input {
        width: 60px;
        text-align: center;
        padding: 0.4rem;
        height: auto;
        /* reset height for small inputs */
    }

    /* Hide less critical info or adjust */
    .footer-info {
        position: relative;
        margin-top: 2rem;
        bottom: auto;
        padding-bottom: 2rem;
    }

    /* Touch optimization */
    button {
        min-height: 44px;
    }
}