/* ── Portal Styles ──
   Brand colors are set via CSS custom properties injected by header.php
   from config/app.php. The fallbacks below match the default config values.
*/
:root {
    --sidebar-width: 250px;
    --primary: #1a3a5c;
    --primary-light: #2c5282;
    --primary-dark: #0f2440;
    --accent: #e8740c;
    --accent-hover: #cf6700;
    --body-bg: #f4f6f9;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--body-bg);
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    min-height: 100vh;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
    transition: margin 0.3s;
}

.sidebar .nav-link {
    padding: 10px 16px;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.sidebar .nav-link:hover {
    color: #fff !important;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
}

.sidebar .nav-link.active {
    color: #fff !important;
    background: var(--accent) !important;
}

.sidebar-header {
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar.collapsed {
    margin-left: calc(var(--sidebar-width) * -1);
}

/* ── Avatar ── */
.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
}

/* ── Cards ── */
.stat-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #eee;
    font-weight: 600;
}

/* ── Tables ── */
.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #6c757d;
    border-top: none;
}

.table td {
    vertical-align: middle;
}

/* ── Buttons ── */
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
}

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

/* ── Login Page ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
    max-width: 420px;
    width: 100%;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

/* ── Public Application Form ── */
.application-form {
    max-width: 900px;
    margin: 0 auto;
}

.application-form .section-header {
    background: var(--primary);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.application-form .section-header h5 {
    margin: 0;
    font-size: 1rem;
}

.form-section {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.application-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 30px;
}

.application-header img {
    max-height: 60px;
    margin-bottom: 15px;
}

/* ── Badge ── */
.badge {
    font-weight: 500;
    padding: 5px 10px;
    font-size: 0.75rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        margin-left: calc(var(--sidebar-width) * -1);
        position: fixed;
        z-index: 1050;
    }
    .sidebar.show {
        margin-left: 0;
    }
    #page-content-wrapper {
        width: 100% !important;
    }
}

/* ── Modal: contract template ── */
#tplModal .modal-body {
    max-height: 70vh;
    overflow-y: auto;
}
@media (max-height: 700px) {
    #tplModal .modal-body {
        max-height: 60vh;
    }
}

/* ── Pagination ── */
.pagination .page-link {
    color: var(--primary);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ── Loading Overlay ── */
#page-loader {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(244,246,249,0.85);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
}

#page-loader.active {
    display: flex;
    animation: loaderFadeIn 0.15s ease-out;
}

@keyframes loaderFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.loader-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.loader-spinner .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--primary, #1a3a5c);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.loader-spinner .spinner-text {
    font-size: 0.85rem;
    color: #6c757d;
    letter-spacing: 0.02em;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Component / card loading state */
.is-loading {
    position: relative;
    pointer-events: none;
}

.is-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.7);
    border-radius: inherit;
    z-index: 10;
}

.is-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid #e0e0e0;
    border-top-color: var(--primary, #1a3a5c);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    z-index: 11;
}

/* ── PDF confidential ── */
.confidential-notice {
    border-top: 2px solid #dc3545;
    padding-top: 10px;
    margin-top: 20px;
    font-size: 0.75rem;
    color: #dc3545;
    text-align: center;
}

/* ──────────────────────────────────────────────────────────────────────────
   Mobile-friendly tables: stack rows vertically instead of side-scrolling.
   Applied to any .table-responsive > .table on screens narrower than 768px.
   Each <td> shows its column header as a label (auto-populated by app.js).
   Opt out per-table by adding the .table-keep class.
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    .table-responsive > .table:not(.table-keep) {
        display: block;
    }
    .table-responsive > .table:not(.table-keep) thead {
        display: none;
    }
    .table-responsive > .table:not(.table-keep) tbody,
    .table-responsive > .table:not(.table-keep) tr {
        display: block;
        width: 100%;
    }
    .table-responsive > .table:not(.table-keep) tr {
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 0.5rem;
        margin-bottom: 0.75rem;
        padding: 0.25rem 0;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }
    .table-responsive > .table:not(.table-keep) td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.75rem;
        border: none;
        border-bottom: 1px dashed rgba(0, 0, 0, 0.06);
        padding: 0.5rem 0.85rem;
        text-align: right;
        word-break: break-word;
    }
    .table-responsive > .table:not(.table-keep) td:last-child {
        border-bottom: none;
    }
    .table-responsive > .table:not(.table-keep) td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        text-align: left;
        margin-right: 0.5rem;
        flex-shrink: 0;
        max-width: 45%;
    }
    .table-responsive > .table:not(.table-keep) td[data-label=""]::before,
    .table-responsive > .table:not(.table-keep) td:not([data-label])::before {
        content: "";
        display: none;
    }
    /* Don't squish action button groups */
    .table-responsive > .table:not(.table-keep) td .btn,
    .table-responsive > .table:not(.table-keep) td .btn-group,
    .table-responsive > .table:not(.table-keep) td .input-group {
        flex-shrink: 0;
    }
    /* Suppress horizontal scroll once stacked */
    .table-responsive {
        overflow-x: visible;
    }
}
