:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --bg: #f8fafc;
    --card: #ffffff;
    --border: #cbd5e1;
    --accent: #8b5cf6;
    --footer-bg: #1e293b;
    --footer-text: #94a3b8;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    margin: 0;
    padding: 0;
    color: #1e293b;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.container {
    max-width: 1300px;
    margin: auto;
    padding: 20px;
    flex: 1;
    width: 100%;
    box-sizing: border-box;
}

.card {
    background: var(--card);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    border: 1px solid #e2e8f0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
    align-items: end;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input,
select,
button {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

button {
    background: var(--primary);
    color: white;
    cursor: pointer;
    border: none;
    font-weight: 600;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button.secondary {
    background: var(--secondary);
}

button.accent {
    background: var(--accent);
}

button.danger {
    background: #ef4444;
    color: white;
    padding: 5px 10px;
    font-size: 0.8rem;
    height: 28px;
    align-self: center;
}

.borrower-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.tab {
    padding: 10px 20px;
    background: #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0px;
    font-size: 0.85rem;
}

th,
td {
    text-align: right;
    padding: 12px 8px;
    border-bottom: 1px solid #f1f5f9;
}

th {
    background: #f8fafc;
    color: #64748b;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: inset 0 -1px 0 #e2e8f0;
}

th:first-child,
td:first-child {
    text-align: left;
}

.liability-tag {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.curr {
    background: #fef3c7;
    color: #92400e;
}

.long {
    background: #dcfce7;
    color: #166534;
}

.section-header {
    border-bottom: 2px solid #f1f5f9;
    margin-bottom: 15px;
    padding-bottom: 5px;
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: bold;
}

.date-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    grid-column: span 2;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Dashboard Styles */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: var(--bg);
    border: 1px solid #e2e8f0;
    padding: 20px;
    border-radius: 8px;
}

.stat-card h5 {
    margin: 0 0 5px 0;
    color: #64748b;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
}

.edit-btn {
    background: #f59e0b;
    color: white;
    padding: 5px 10px;
    font-size: 0.8rem;
    margin-right: 5px;
}

.cancel-btn {
    background: #94a3b8;
    display: none;
}

.file-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

#fileInput {
    display: none;
}

/* Scrollable table container */
.table-scroll-container {
    max-height: 650px;
    /* Approximately 30 rows + header */
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #f1f5f9;
    border-radius: 8px;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 16px;
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 15px;
}

.close-btn {
    background: #f1f5f9;
    color: #64748b;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.doc-section {
    margin-bottom: 25px;
}

.doc-section h4 {
    color: var(--primary);
    margin-bottom: 10px;
}

.doc-section p,
.doc-section li {
    font-size: 0.95rem;
    color: #475569;
}

/* Footer Styles */
footer {
    background-color: var(--footer-bg);
    color: var(--footer-text);
    padding: 40px 20px 20px 20px;
    margin-top: 50px;
    font-size: 0.9rem;
}

.footer-content {
    max-width: 1300px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1.5fr;
    gap: 40px;
}

.footer-section h4 {
    color: #f8fafc;
    margin-bottom: 15px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.footer-section p {
    margin: 8px 0;
    line-height: 1.6;
}

.footer-section a {
    color: var(--footer-text);
    text-decoration: none;
    transition: color 0.2s;
    cursor: pointer;
}

.footer-section a:hover {
    color: #ffffff;
}

.footer-bottom {
    max-width: 1300px;
    margin: 40px auto 0 auto;
    padding-top: 20px;
    border-top: 1px solid #334155;
    text-align: center;
    font-size: 0.8rem;
}

@media (max-width: 768px) {

    /* Global Layout */
    .container {
        padding: 10px;
        width: 100%;
        max-width: 100%;
    }

    .card {
        padding: 15px;
        margin-bottom: 15px;
    }

    /* Header & Navigation */
    header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 15px !important;
    }

    header>div:first-child {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }

    .file-controls {
        flex-direction: column;
        width: 100%;
        align-items: stretch;
        gap: 10px;
    }

    .file-controls>div[style*="text-align: right"] {
        display: none !important;
        /* Hide file activity on mobile to save space */
    }

    .file-controls input[type="text"] {
        width: 100%;
        box-sizing: border-box;
        /* Ensure padding doesn't overflow width */
    }

    /* Stack buttons in file controls */
    .file-controls button {
        width: 100%;
    }

    .file-controls>div[style*="width: 2px"] {
        display: none;
        /* Hide separator */
    }

    /* Dashboard Grid */
    .dashboard-grid {
        grid-template-columns: 1fr;
        /* Stack stat cards */
        gap: 10px;
    }

    /* Inputs & Forms */
    .grid {
        grid-template-columns: 1fr !important;
        /* Force single column for all grids */
        gap: 15px;
    }

    .input-group {
        width: 100%;
    }

    /* Fix Calculation Engine inputs */
    div[style*="flex-direction: row"] {
        flex-direction: column;
    }

    div[style*="gap: 20px; align-items: end"] {
        flex-direction: column;
        align-items: stretch !important;
        gap: 15px !important;
    }

    #roiInputGroup,
    #emiInputGroup {
        max-width: 100% !important;
        flex: auto !important;
    }

    /* Calculation Mode Radio Buttons */
    div[style*="display: flex; gap: 20px; align-items: center"] {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    /* Borrower Tabs */
    .borrower-nav {
        margin-bottom: 15px;
        padding-bottom: 5px;
    }

    .tab {
        padding: 8px 15px;
        font-size: 0.85rem;
    }

    /* Tables */
    th,
    td {
        padding: 8px 5px;
        font-size: 0.75rem;
    }

    .section-header {
        font-size: 0.85rem;
    }

    /* Modal */
    .modal-content {
        padding: 20px;
        width: 95%;
        margin: 10px;
        max-height: 90vh;
    }

    .modal-header h3 {
        font-size: 1.1rem;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr;
        gap: 30px;
        text-align: center;
    }

    .footer-section {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
}