/* Login Overlay Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    /* Very dark background to block view */
    z-index: 10000;
    /* Highest priority */
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(15px);
    transition: opacity 0.5s ease;
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
    /* remove from flow */
}

.login-box {
    width: 360px;
    padding: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.login-box h2 {
    color: white;
    margin-bottom: 5px;
}

.login-box p {
    color: #94a3b8;
    margin-bottom: 25px;
    font-size: 0.9em;
}

.login-input-group {
    margin-bottom: 15px;
    text-align: left;
}

.login-input-group label {
    display: block;
    color: #cbd5e1;
    margin-bottom: 5px;
    font-size: 0.85em;
}

.login-input-group input {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #475569;
    background: #1e293b;
    color: white;
    font-size: 1rem;
}

.login-input-group input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Login Overlay Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(15px);
    transition: opacity 0.5s ease;
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.login-box {
    width: 360px;
    padding: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.login-box h2 {
    color: white;
    margin-bottom: 5px;
}

.login-box p {
    color: #94a3b8;
    margin-bottom: 25px;
}

.login-input-group {
    margin-bottom: 15px;
    text-align: left;
}

.login-input-group label {
    display: block;
    color: #cbd5e1;
    margin-bottom: 5px;
    font-size: 0.85em;
}

.login-input-group input {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #475569;
    background: #1e293b;
    color: white;
    font-size: 1rem;
}

.login-input-group input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

:root {
    --primary: #0a2540;
    --primary-light: #1e3a5a;
    --accent: #00d4ff;
    --accent-hover: #00a3cc;
    --bg: #f6f9fc;
    --card-bg: #ffffff;
    --text: #424770;
    --text-dark: #1a1f36;
    --border: #e6ebf1;
    --success: #24b47e;
    --warning: #f5a623;
    --danger: #e15b5b;
    --font-main: 'Outfit', 'Inter', -apple-system, sans-serif;
    --shadow: 0 7px 14px rgba(50, 50, 93, 0.1), 0 3px 6px rgba(0, 0, 0, 0.08);
    --transition: all 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-main);
    line-height: 1.6;
    overflow-x: hidden;
}

.glass-header {
    background: rgba(10, 37, 64, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    padding: 1.5rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

.logo {
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo span {
    color: var(--accent);
}

.container {
    max-width: 1600px;
    margin: 1rem auto;
    padding: 0 2rem;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2rem;
}

/* Tab Navigation Area */
.tab-nav-wrapper {
    grid-column: 1 / -1;
    overflow-x: auto;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
}

.nav-tabs {
    display: flex;
    gap: 0.5rem;
    white-space: nowrap;
    padding: 0.25rem;
}

.nav-tab {
    padding: 0.6rem 1.2rem;
    background: #e2e8f0;
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: var(--transition);
    border: 1px solid transparent;
}

.nav-tab:hover {
    background: #cbd5e1;
}

.nav-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(10, 37, 64, 0.2);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Sidebar / Inputs Area */
.sidebar {
    position: sticky;
    top: 6rem;
    height: calc(100vh - 8rem);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    padding-bottom: 2rem;
    /* Add padding to ensure last item is not cut off */
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 13px 27px -5px rgba(50, 50, 93, 0.25), 0 8px 16px -8px rgba(0, 0, 0, 0.3);
}

h2 {
    font-size: 1.1rem;
    color: var(--text-dark);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text);
}

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-main);
    transition: var(--transition);
    font-size: 0.95rem;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--accent);
    color: var(--primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-block {
    width: 100%;
}

/* Main Content Area */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-bottom: 5rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.metric-card {
    text-align: center;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

/* Sub-tab Styling */
.sub-tab-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.sub-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.sub-tab-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

.mapping-table-wrapper {
    animation: fadeIn 0.3s ease;
}

.financial-input:focus {
    background: rgba(255, 255, 255, 0.08) !important;
    outline: none;
    border-radius: 4px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.metric-label {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Peer Search UI & Tables */
.peer-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.peer-table th,
.peer-table td {
    padding: 0.4rem 0.6rem;
    /* Compact padding */
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    /* Smaller font */
}

.peer-table th {
    background: #f8fafc;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #8898aa;
    font-weight: 600;
}

.peer-table th:first-child,
.peer-table td:first-child {
    min-width: 160px;
    /* Force width */
    max-width: 300px;
    white-space: nowrap;
    /* Prevent wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.peer-table th:nth-child(2),
.peer-table td:nth-child(2) {
    text-align: right !important;
}

.peer-table th:not(:first-child),
.peer-table td:not(:first-child) {
    text-align: right;
    min-width: 120px;
    /* Enhanced width for large numbers */
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeIn 0.5s forwards;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Sensitivity Analysis */
.sensitivity-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

.sens-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    background: white;
}

.sens-table th,
.sens-table td {
    border: 1px solid var(--border);
    padding: 0.6rem;
    text-align: center;
}

.sens-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-dark);
}

.sens-highlight {
    background: rgba(0, 212, 255, 0.1) !important;
    font-weight: 700;
}

/* Detailed Estimation Boards */
.est-board {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.est-header {
    background: var(--primary);
    color: white;
    padding: 1rem;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
}

.est-row-label {
    background: #f1f5f9;
    font-weight: 600;
    text-align: left !important;
    width: 250px;
}

.est-input-cell {
    padding: 0.25rem !important;
}

.est-input-field {
    width: 100%;
    border: none;
    padding: 0.5rem;
    text-align: right;
    font-family: inherit;
    font-size: 0.85rem;
    background: transparent;
}

.est-input-field:focus {
    background: #fff;
    outline: 2px solid var(--accent);
}

.est-total-row {
    background: #f1f5f9 !important;
    font-weight: 800 !important;
    font-size: 1.05rem !important;
    color: var(--primary) !important;
}

/* Financial Sub-tabs */
.fin-sub-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.fin-sub-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.fin-sub-tab:hover {
    background: #f1f5f9;
}

.fin-sub-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.upload-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.upload-section.active {
    display: block;
}

/* Modal Logic */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 1rem;
}

.modal-close {
    cursor: pointer;
    font-size: 1.5rem;
    color: #666;
}

.history-list {
    list-style: none;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.history-item:hover {
    background: #f9f9f9;
}

.history-info {
    flex: 1;
}

.history-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.history-date {
    font-size: 0.8rem;
    color: #888;
}

.history-actions {
    display: flex;
    gap: 0.5rem;
}

/* =========================================
   Mobile Optimization (Responsive Design)
   ========================================= */

@media (max-width: 768px) {
    /* Mobile Settings Toggle Button */
    .mobile-settings-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0.8rem;
        background: white;
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 1rem;
        font-weight: 600;
        color: var(--primary);
        cursor: pointer;
        gap: 0.5rem;
        box-shadow: var(--shadow);
    }
    
    .mobile-settings-toggle:active {
        background: #f1f5f9;
        transform: translateY(1px);
    }

    /* Layout Adjustments */
    .container {
        grid-template-columns: 1fr;
        padding: 0 1rem;
        gap: 1rem;
        display: flex;
        flex-direction: column;
    }

    .glass-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 1rem;
        position: relative;
    }

    .logo {
        font-size: 1.3rem;
        width: 100%;
        justify-content: space-between;
    }

    /* Header Actions: Grid Layout for Mobile */
    .header-actions {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        width: 100%;
    }

    .header-actions .btn {
        margin: 0 !important;
        font-size: 0.75rem;
        padding: 0.6rem 0.2rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        justify-content: center;
        width: 100%;
    }

    /* Sidebar logic */
    .sidebar {
        /* Hidden by default on mobile, toggled via class */
        display: none; 
        width: 100%;
        height: auto;
        position: static;
        z-index: 900;
        background: var(--bg);
        margin-bottom: 1rem;
        border-bottom: 1px solid var(--border);
        padding-bottom: 1rem;
    }

    .sidebar.active {
        display: flex;
        animation: fadeIn 0.3s ease;
    }

    /* Tabs scrollable */
    .tab-nav-wrapper {
        margin: 0 -1rem 0.5rem -1rem;
        padding: 0.5rem 1rem;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
    }

    .nav-tabs { 
        gap: 0.5rem; 
    }

    .nav-tab {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        border-radius: 20px; /* Pill shape for better touch */
        background: white;
        border: 1px solid var(--border);
        white-space: nowrap;
    }
    
    .nav-tab.active {
        background: var(--primary);
        border-color: var(--primary);
        color: white;
    }

    /* Cards */
    .card {
        padding: 1rem;
        border-radius: 8px;
    }

    h2 {
        font-size: 1.1rem;
    }

    /* Tables */
    .table-container,
    #dartResultContainer,
    #peerList,
    .est-board > div,
    #cogsContent, #variableContent, #fixedContent, #nwcContent, #laborResultContainer, #capexResultContainer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        display: block;
    }
    
    .peer-table {
        min-width: 600px; /* Ensure table doesn't squish too much */
    }

    /* Inputs */
    input, select, textarea {
        font-size: 16px; /* Prevent IOS zoom */
    }

    /* Modal */
    .modal-content {
        width: 90%;
        margin: 0 auto;
        padding: 1.5rem;
    }
}

@media (min-width: 769px) {
    .mobile-settings-toggle {
        display: none;
    }
}
