:root {
    /* Light Mode Defaults */
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent-color: #0284c7;
    --accent-glow: rgba(2, 132, 199, 0.15);
    --border-color: #e2e8f0;
    --success-color: #16a34a;
    --highlight-bg: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);

    --font-family: 'Outfit', sans-serif;
    --radius-lg: 16px;
    --radius-md: 8px;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f172a;
        --sidebar-bg: #1e293b;
        --card-bg: #334155;
        --text-primary: #f8fafc;
        --text-secondary: #94a3b8;
        --accent-color: #38bdf8;
        --accent-glow: rgba(56, 189, 248, 0.3);
        --border-color: #475569;
        --success-color: #22c55e;
        --highlight-bg: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    }
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.app-header {
    height: 60px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
    /* Match sidebar or darker */
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--accent-color);
}

/* Main Layout */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.input-wrapper {
    position: relative;
}

input[type="number"],
input[type="date"] {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.2s;
}

input[type="number"]:focus,
input[type="date"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent-color);
    cursor: pointer;
}

/* Rate Type Toggle */
.rate-type-toggle {
    display: flex;
    background-color: var(--bg-color);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.rate-type-toggle input[type="radio"] {
    display: none;
}

.toggle-btn {
    flex: 1;
    text-align: center;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.rate-type-toggle input[type="radio"]:checked+.toggle-btn {
    background-color: var(--accent-color);
    color: white;
    font-weight: 500;
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

select {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.total-rate-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background-color: var(--bg-color);
    border-radius: var(--radius-md);
    margin-top: 8px;
    border: 1px dashed var(--border-color);
}

.total-rate-display span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.total-rate-display strong {
    color: var(--accent-color);
}

/* Results Area */
.results-area {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow-md);
}

.card h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.card .value {
    font-size: 1.8rem;
    font-weight: 700;
}

.card.highlight {
    background: var(--highlight-bg);
    border: none;
}

.card.highlight h3,
.card.highlight .value {
    color: white;
}

/* Generic Box for Charts/Tables */
.generic-box {
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.generic-box h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Bar Chart */
.bar-chart-wrapper {
    display: flex;
    height: 24px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--bg-color);
    margin-top: 8px;
}

.bar-segment {
    height: 100%;
    transition: width 0.5s ease-out;
}

.bar-segment.principal {
    background-color: var(--accent-color);
}

.bar-segment.interest {
    background-color: #ff5252;
}

.legend {
    display: flex;
    gap: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot.principal {
    background-color: var(--accent-color);
}

.dot.interest {
    background-color: #ff5252;
}

/* Table */
.table-header-ui {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-secondary {
    padding: 8px 16px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background-color: var(--border-color);
}

.table-wrapper {
    overflow-x: auto;
    max-height: 400px;
    /* Internal scroll */
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

th,
td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background-color: var(--bg-color);
    position: sticky;
    top: 0;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

td {
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Navigation Menu */
.nav-menu {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.nav-link {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-primary);
    background-color: var(--bg-color);
}

.nav-link.active {
    color: var(--accent-color);
    background-color: rgba(2, 132, 199, 0.05);
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    margin-left: auto;
    border-radius: var(--radius-md);
}

/* Responsive */
@media (max-width: 900px) {
    body {
        overflow-y: auto;
        height: auto;
    }

    .app-container {
        height: auto;
        min-height: 100vh;
    }

    .app-header {
        position: sticky;
        top: 0;
        justify-content: space-between;
        padding: 0 16px;
        background-color: var(--sidebar-bg);
    }

    .menu-toggle {
        display: block;
    }

    .nav-menu {
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background-color: var(--sidebar-bg);
        flex-direction: column;
        padding: 16px;
        gap: 8px;
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        display: none;
        z-index: 100;
        margin-left: 0;
    }

    .nav-menu.open {
        display: flex;
        animation: slideDown 0.3s ease-out;
    }

    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .nav-link {
        width: 100%;
        padding: 12px 16px;
    }

    /* Force Vertical Layout: Sidebar on top, Results Area bottom */
    .main-content,
    .app-view.active {
        display: flex !important;
        flex-direction: column !important;
        overflow: visible !important;
        height: auto !important;
    }

    .sidebar {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
        overflow: visible !important;
        padding: 24px 16px !important;
        flex: none !important;
    }

    .results-area {
        width: 100% !important;
        padding: 24px 16px !important;
        overflow: visible !important;
        flex: none !important;
    }

    .summary-cards {
        grid-template-columns: 1fr;
    }

    .table-wrapper {
        max-height: none;
        /* Allow natural expansion on mobile */
    }

    .logo span {
        font-size: 1.1rem;
    }
}

/* App Views */
.app-view {
    display: none;
    flex: 1;
    overflow: hidden;
    /* Maintain layout integrity */
    flex-direction: row;
    /* Default layout assuming sidebar + content */
    height: 100%;
}

.app-view.active {
    display: flex;
}

/* Specific view adjustments if needed */
.app-dashboard-view {
    padding: 32px;
    flex-direction: column;
    overflow-y: auto;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    background-color: var(--sidebar-bg);
    /* Ensure it sits nicely */
    flex-shrink: 0;
}

.app-footer a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 48px;
    height: 48px;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    transform: translateY(-5px);
    background-color: var(--text-primary);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

@media (max-width: 600px) {
    .back-to-top {
        bottom: 20px;
        right: 20px;
        width: 44px;
        height: 44px;
    }

}
