/* ============================================================
   TMS Forge — Custom Styles
   Bootstrap 5 is loaded first; these are overrides & additions.
   ============================================================ */

:root {
    --tms-primary: #2E7D32;          /* TMS brand green — accent color */
    --tms-primary-light: #43A047;    /* lighter green for hover states */
    --tms-accent: #e67e22;           /* warm amber accent */
    --tms-dark: #212529;             /* charcoal — navbar, table headers */
    --tms-dark-secondary: #343a40;   /* slightly lighter charcoal */
}

/* --- Body & Typography --- */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f5f6f8;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}
main { flex: 1; }

/* --- Navbar branding --- */
.navbar {
    background: linear-gradient(135deg, #1B3A20 0%, #264D2E 100%) !important;
    border-bottom: 3px solid var(--tms-primary);
}
.navbar-brand { font-weight: 700; letter-spacing: 0.02em; }

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid #dee2e6;
    flex-wrap: wrap;
    gap: 0.75rem;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0;
    color: var(--tms-dark);
}
.page-header .subtitle { color: #6c757d; font-size: 0.95rem; }
.page-header-actions { display: flex; gap: 0.5rem; align-items: flex-start; flex-wrap: wrap; }

/* --- Cards: colored top border, better headers --- */
.card {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    margin-bottom: 1rem;
}
.card-header {
    background: #fff;
    border-bottom: 2px solid var(--tms-primary);
    padding: 0.75rem 1rem;
}
.card-header h2, .card-header h5 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--tms-primary);
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* --- Tables --- */
.table {
    margin-bottom: 0;
}
.table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #fff;
    background: var(--tms-dark);
    border-color: var(--tms-dark);
    font-weight: 600;
    padding: 0.6rem 0.75rem;
}
.table td {
    padding: 0.6rem 0.75rem;
    vertical-align: middle;
}
.table-hover tbody tr:hover { background-color: #e8f5e9; }
.table a { color: var(--tms-primary-light); font-weight: 600; text-decoration: none; }
.table a:hover { color: var(--tms-primary); text-decoration: underline; }

/* --- Buttons: accent color for primary --- */
.btn-primary {
    background-color: var(--tms-primary) !important;
    border-color: var(--tms-primary) !important;
}
.btn-primary:hover {
    background-color: var(--tms-primary-light) !important;
    border-color: var(--tms-primary-light) !important;
}
.btn-outline-secondary:hover {
    background-color: #e8f5e9;
    border-color: var(--tms-primary-light);
    color: var(--tms-primary);
}

/* --- TMS Status Badges --- */
.badge {
    font-weight: 600;
    font-size: 0.72rem;
    padding: 0.35em 0.65em;
    border-radius: 0.25rem;
}
.badge-preconstruction { background-color: #cff4fc !important; color: #055160 !important; }
.badge-active          { background-color: #d1e7dd !important; color: #0f5132 !important; }
.badge-punch_list      { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-closeout        { background-color: #e2d9f3 !important; color: #432874 !important; }
.badge-complete        { background-color: #d1e7dd !important; color: #0f5132 !important; }
.badge-warranty        { background-color: #f8d7da !important; color: #842029 !important; }
.badge-in_progress     { background-color: #cff4fc !important; color: #055160 !important; }
.badge-approved        { background-color: #d1e7dd !important; color: #0f5132 !important; }
.badge-draft           { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-in_review       { background-color: #e2d9f3 !important; color: #432874 !important; }
.badge-superseded      { background-color: #e9ecef !important; color: #495057 !important; }
.badge-inactive        { background-color: #e9ecef !important; color: #495057 !important; }
.badge-issued          { background-color: #cfe2ff !important; color: #084298 !important; }
.badge-acknowledged    { background-color: #e2d9f3 !important; color: #432874 !important; }
.badge-in_process      { background-color: #cff4fc !important; color: #055160 !important; }
.badge-partial_receipt { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-received        { background-color: #d1e7dd !important; color: #0f5132 !important; }
.badge-closed          { background-color: #e9ecef !important; color: #495057 !important; }
.badge-cancelled       { background-color: #f8d7da !important; color: #842029 !important; }
.badge-submitted       { background-color: #cfe2ff !important; color: #084298 !important; }
.badge-paid            { background-color: #d1e7dd !important; color: #0f5132 !important; }
.badge-archived        { background-color: #e9ecef !important; color: #495057 !important; }
.badge-identified           { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-proposal_in_progress { background-color: #cff4fc !important; color: #055160 !important; }
.badge-proposal_submitted   { background-color: #cfe2ff !important; color: #084298 !important; }
.badge-billed               { background-color: #e9ecef !important; color: #495057 !important; }
.badge-rejected             { background-color: #f8d7da !important; color: #842029 !important; }
.badge-pending_review       { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-not_started   { background-color: #e9ecef !important; color: #495057 !important; }
.badge-on_hold       { background-color: #fff3cd !important; color: #664d03 !important; }
.badge-schedule-critical { background-color: #f8d7da !important; color: #842029 !important; font-size: 0.65rem; }

/* --- Stat Cards --- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    border: none;
    border-radius: 0.5rem;
    padding: 1rem 0.75rem;
    text-align: center;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
    border-top: 3px solid var(--tms-primary);
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: 0 3px 8px rgba(0,0,0,.15); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--tms-primary); }
.stat-label {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.15rem;
    font-weight: 600;
}

/* --- Detail Page --- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.detail-list { display: flex; flex-direction: column; }
.dl-row { display: flex; justify-content: space-between; padding: 0.6rem 0; border-bottom: 1px solid #f1f3f5; }
.dl-row:last-child { border-bottom: none; }
.dl-row dt { font-weight: 600; color: #495057; font-size: 0.85rem; }
.dl-row dd { color: #212529; font-size: 0.9rem; margin-bottom: 0; }

.dates-row { display: flex; gap: 2rem; flex-wrap: wrap; }
.date-item { display: flex; flex-direction: column; }
.date-label {
    font-size: 0.7rem;
    color: #6c757d;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.date-value { font-size: 1rem; color: #212529; margin-top: 0.15rem; font-weight: 500; }

/* --- Module Links (Project Detail) --- */
.module-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.5rem; }
.module-link {
    padding: 0.75rem 1rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    color: #6c757d;
    background: #f8f9fa;
    text-decoration: none;
    transition: all 0.2s;
    text-align: center;
    font-weight: 600;
}
a.module-link {
    color: var(--tms-primary);
    border-color: var(--tms-primary);
    border-left: 3px solid var(--tms-primary);
    background: #fff;
    cursor: pointer;
    text-align: left;
}
a.module-link:hover {
    background: #e8f5e9;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
    text-decoration: none;
}

/* --- Login Page --- */
.login-container { max-width: 420px; margin: 4rem auto; }
.login-container .card-header { text-align: center; border-bottom: none; }
.login-container .card-header h2, .login-container .card-header h4 {
    color: #fff !important;
    text-transform: none !important;
}
.login-container .btn { width: 100%; }

/* --- Filter Bar --- */
.filter-bar { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filter-btn {
    padding: 0.35rem 0.85rem;
    border: 1px solid #dee2e6;
    border-radius: 50rem;
    font-size: 0.8rem;
    color: #495057;
    background: #fff;
    text-decoration: none;
    transition: all 0.15s;
    font-weight: 500;
}
.filter-btn:hover { border-color: var(--tms-primary); color: var(--tms-primary); text-decoration: none; }
.filter-btn.active { background: var(--tms-primary); color: #fff; border-color: var(--tms-primary); }

/* --- Forms --- */
.form-label { font-weight: 600; font-size: 0.85rem; color: #495057; }
.form-control:focus, .form-select:focus {
    border-color: var(--tms-primary-light);
    box-shadow: 0 0 0 0.2rem rgba(46, 125, 50, 0.15);
}
.form-hint { font-size: 0.75rem; color: #6c757d; margin-top: 0.25rem; }

/* --- Checkbox / misc --- */
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; flex-direction: row; padding-top: 1.5rem; }
.checkbox-label input[type="checkbox"] { width: auto; }
.meta-info { font-size: 0.8rem; color: #adb5bd; margin-top: 1.5rem; text-align: right; }

/* --- Schedule Table Rows --- */
.schedule-row-critical { background: #fff5f5 !important; }
.schedule-row-summary { background: #f0f4f8 !important; font-weight: 600; }
.schedule-row-overdue td:first-child { border-left: 3px solid #dc3545; }

/* --- Alerts --- */
.alert { border: none; border-radius: 0.5rem; }

/* --- Project Sidebar --- */
.main-with-sidebar { min-height: calc(100vh - 56px - 52px); }

.project-sidebar {
    width: 220px;
    min-width: 220px;
    background: #fff;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 56px;  /* below navbar */
    height: calc(100vh - 56px);
    overflow-y: auto;
}

.sidebar-header {
    padding: 1rem 0.875rem 0.75rem;
    border-bottom: 3px solid var(--tms-primary);
    background: linear-gradient(135deg, #1B3A20 0%, #264D2E 100%);
    color: #fff;
}
.sidebar-project-number {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.85;
}
.sidebar-project-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #495057;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
}
.sidebar-link:hover {
    background: #e8f5e9;
    color: var(--tms-primary);
    text-decoration: none;
}
.sidebar-link.active {
    background: #e8f5e9;
    color: var(--tms-primary);
    font-weight: 700;
    border-left-color: var(--tms-primary);
}
.sidebar-link i {
    font-size: 0.9rem;
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9e9e9e;
    padding: 0.625rem 0.875rem 0.125rem;
    margin-top: 0.25rem;
}

.sidebar-footer {
    border-top: 1px solid #dee2e6;
    padding: 0.5rem 0;
}
.sidebar-back {
    color: #6c757d !important;
    font-size: 0.75rem;
}
.sidebar-back:hover {
    color: var(--tms-primary) !important;
}

/* Sidebar toggle for small screens (< 992px / Bootstrap lg breakpoint) */
@media (max-width: 991.98px) {
    .project-sidebar {
        position: fixed;
        left: -240px;
        top: 56px;
        z-index: 1040;
        width: 220px;
        min-width: 220px;
        height: calc(100vh - 56px);
        transition: left 0.25s ease;
        box-shadow: none;
    }
    .project-sidebar.sidebar-open {
        left: 0;
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 1035;
    }
    .sidebar-overlay.active {
        display: block;
    }
}
@media (min-width: 992px) {
    .sidebar-overlay { display: none !important; }
}

.sidebar-toggle-btn {
    position: fixed;
    left: 8px;
    top: 64px;
    z-index: 1030;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    color: var(--tms-primary);
    padding: 4px 8px;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    transition: opacity 0.2s;
}
.sidebar-toggle-btn:hover {
    background: #e8f5e9;
}

.sidebar-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1rem;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    margin-top: 2px;
}
.sidebar-close-btn:hover {
    color: #fff;
}

.project-main-content {
    min-width: 0;  /* prevent flex child overflow */
    max-width: 1200px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .detail-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .page-header { flex-direction: column; }
    .module-links { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 991.98px) {
    /* Sidebar hidden on < lg screens via d-none d-lg-block */
    .project-main-content { max-width: 100%; }
}

/* --- Navbar Logo --- */
.navbar-brand img.brand-logo {
    height: 24px;
    margin-right: 0.4rem;
    vertical-align: middle;
    filter: brightness(0) invert(1);  /* ensure white */
}

/* --- Pay App Validation --- */
tr.validation-error { background-color: #fef2f2 !important; }
tr.validation-warning { background-color: #fffbeb !important; }
.validation-popover { max-width: 400px; }
.validation-popover .popover-header { font-size: 0.85rem; padding: 0.4rem 0.75rem; }
.validation-popover .popover-body { padding: 0.5rem 0.75rem; }
