/* Base reset and typography */
*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #1a1a1a;
    background: #f8f9fa;
}

/* Navigation */
.main-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2rem;
    padding: 0.75rem 2rem;
    background: #1e293b;
    color: #fff;
}
.nav-brand a {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.1rem;
}
.nav-links {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    margin: 0;
    padding: 0;
}
.nav-links a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background 0.15s;
}
.nav-links a:hover, .nav-links a.active {
    color: #fff;
    background: #334155;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

/* Flash messages */
.flash-messages { padding: 0 1.5rem; max-width: 1200px; margin: 1rem auto 0; }
.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.flash-success { background: #d1fae5; color: #065f46; }
.flash-error { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-info { background: #dbeafe; color: #1e40af; }
.flash-close { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: inherit; }

/* Cards */
.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.card-title { font-size: 1.1rem; font-weight: 600; margin: 0; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid #e5e7eb; vertical-align: top; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td:hover { overflow: visible; white-space: normal; word-break: break-word; position: relative; z-index: 1; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
th { font-weight: 600; color: #4b5563; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #f9fafb; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #e5e7eb; color: #1f2937; }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.3rem; font-size: 0.9rem; }
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
}
.form-control:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }
select.form-control { appearance: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.badge-draft { background: #e5e7eb; color: #374151; }
.badge-review { background: #fef3c7; color: #92400e; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-matured { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #c7d2fe; color: #3730a3; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-no-rollover { background: #fce7f3; color: #9d174d; }
.badge-repay-plan { background: #ffedd5; color: #9a3412; }

/* DSCR indicators */
.dscr-green { color: #065f46; background: #d1fae5; }
.dscr-yellow { color: #92400e; background: #fef3c7; }
.dscr-red { color: #991b1b; background: #fee2e2; }

/* Grid layouts */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* Stat cards */
.stat-card { text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: #1e293b; }
.stat-label { font-size: 0.8rem; color: #6b7280; margin-top: 0.25rem; }

/* Pagination */
.pagination { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.5rem; }
.pagination a, .pagination span {
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
}
.pagination a { background: #e5e7eb; color: #374151; }
.pagination a:hover { background: #d1d5db; }
.pagination .current { background: #2563eb; color: #fff; }

/* Footer */
.main-footer { text-align: center; padding: 1.5rem; color: #9ca3af; font-size: 0.8rem; }

/* Utility */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #6b7280; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }

/* Compliance Matrix Styles */
.matrix-cell {
    font-size: 1.4rem;
    line-height: 1;
}
.matrix-cell-green { color: #28a745; }
.matrix-cell-yellow { color: #ffc107; }
.matrix-cell-red { color: #dc3545; }
.matrix-cell-gray { color: #adb5bd; }
.matrix-cell-pre-system { color: #6c757d; font-style: italic; }

/* Table responsive wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Data table base styles */
.data-table {
    width: 100%;
    border-collapse: collapse;
}
.data-table th,
.data-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
}
.data-table th {
    font-weight: 600;
    color: #4b5563;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #f9fafb;
}
.data-table tr:hover td {
    background: #f3f4f6;
}

/* Signature status badge variants for matrix */
.badge-sent { background: #fef3c7; color: #92400e; }
.badge-signed { background: #dbeafe; color: #1e40af; }
.badge-countersigned { background: #c7d2fe; color: #3730a3; }
.badge-final { background: #d1fae5; color: #065f46; }
.badge-uploaded { background: #e0e7ff; color: #3730a3; }
.badge-generation_failed { background: #fee2e2; color: #991b1b; }

/* Tab navigation for document management */
.tab-nav {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 1rem;
    gap: 0;
}
.tab-nav a {
    padding: 0.6rem 1.2rem;
    text-decoration: none;
    color: #6b7280;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.tab-nav a:hover {
    color: #374151;
    border-bottom-color: #d1d5db;
}
.tab-nav a.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
}


/* ===== Hamburger Button (hidden on desktop) ===== */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 20px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
}

.nav-hamburger .hamburger-line {
    display: block;
    width: 100%;
    height: 2px;
    background-color: #fff;
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

/* ===== Responsive Navigation ===== */
@media (max-width: 1100px) {
    .main-nav {
        position: relative;
        flex-wrap: wrap;
    }

    .nav-hamburger {
        display: flex;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        gap: 0;
        width: 100%;
        background: #1e293b;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 1000;
        padding: 0.5rem 0;
        box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links a {
        display: block;
        padding: 0.6rem 1.5rem;
        border-radius: 0;
        color: #cbd5e1;
    }

    .nav-links a:hover,
    .nav-links a.active {
        background: #334155;
        color: #fff;
    }
}

/* ===== Responsive Tables ===== */
@media (max-width: 768px) {
    .container {
        padding: 0 0.75rem;
    }

    /* Make tables scroll horizontally instead of overflowing */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    /* Cards stack on mobile */
    .card {
        padding: 1rem;
    }

    /* Form rows stack on mobile */
    .form-row {
        flex-direction: column;
    }

    .form-row .form-group {
        width: 100%;
    }

    /* Grid layouts collapse to single column */
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    /* Page header adjusts */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .page-actions {
        width: 100%;
    }
}


/* Logout button in nav */
.nav-logout-btn {
    background: none;
    border: 1px solid #ef4444;
    color: #ef4444;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, color 0.15s;
}

.nav-logout-btn:hover {
    background: #ef4444;
    color: #fff;
}
