/* ========================================
   Contract Management System - Stylesheet
   EPC / Oil & Gas
   ======================================== */

:root {
    --sidebar-width: 260px;
    --sidebar-bg: #1a1d29;
    --sidebar-text: #a0a4b8;
    --sidebar-active: #4f6ef7;
    --sidebar-hover: #252836;
    --primary: #4f6ef7;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --body-bg: #f0f2f5;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    background-color: var(--body-bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.875rem;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    overflow-y: auto;
    z-index: 1040;
    transition: transform 0.3s ease;
}

.sidebar .nav-link {
    color: var(--sidebar-text);
    padding: 0.6rem 1.25rem;
    font-size: 0.85rem;
    border-left: 3px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar .nav-link.active {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--sidebar-active);
}

.sidebar .nav-link i {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
}

.nav-section {
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 1rem 1.25rem 0.4rem;
    list-style: none;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* Stat Cards */
.stat-card {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: var(--card-shadow);
    border: 1px solid #e5e7eb;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

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

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

.stat-card .stat-label {
    font-size: 0.78rem;
    color: #6b7280;
    font-weight: 500;
}

/* Cards */
.card {
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    box-shadow: var(--card-shadow);
}

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

/* Tables */
.table th {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6b7280;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.table td {
    vertical-align: middle;
    font-size: 0.85rem;
}

.table-hover tbody tr:hover {
    background-color: #f8f9ff;
}

/* Badges */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.35em 0.65em;
}

/* Badges inside a .detail-value (or marked .wrap-badge) wrap text instead of
   overflowing the column. Bootstrap defaults to white-space: nowrap, which
   causes long status labels like "Under Engineer Review (Sub-Clause 18.1.3)"
   to push outside their grid cell and overlap the next column. */
.detail-value .badge,
.wrap-badge {
    white-space: normal;
    text-align: left;
    line-height: 1.3;
    max-width: 100%;
}

/* Status colors */
.status-active, .status-approved, .status-paid, .status-completed, .status-agreed {
    background-color: #d1fae5;
    color: #065f46;
}

.status-draft, .status-pending, .status-identified {
    background-color: #e5e7eb;
    color: #374151;
}

.status-submitted, .status-received, .status-under_review, .status-notice_sent, .status-in_progress {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-overdue, .status-rejected, .status-terminated, .status-critical {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-negotiation, .status-suspended, .status-expiring_soon, .status-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.status-open {
    background-color: #dbeafe;
    color: #1e40af;
}

.status-mitigating {
    background-color: #fef3c7;
    color: #92400e;
}

.status-monitoring {
    background-color: #818cf8;
    color: #ffffff;
}

.status-occurred {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-closed {
    background-color: #e5e7eb;
    color: #374151;
}

/* Subcontract lifecycle statuses not covered above */
.status-tendering {
    background-color: #ddd6fe;
    color: #5b21b6;
}
.status-awarded {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Subcontract Payment statuses */
.status-certified {
    background-color: #dbeafe;
    color: #1e40af;
}
.status-disputed {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Bond / Insurance statuses */
.status-expired {
    background-color: #fee2e2;
    color: #991b1b;
}
.status-released {
    background-color: #d1fae5;
    color: #065f46;
}
.status-called {
    background-color: #fef3c7;
    color: #92400e;
}
.status-cancelled {
    background-color: #e5e7eb;
    color: #374151;
}
.status-renewed {
    background-color: #d1fae5;
    color: #065f46;
}

/* Claim & misc statuses not covered above */
.status-defects {
    background-color: #fef3c7;
    color: #92400e;
}
.status-withdrawn {
    background-color: #e5e7eb;
    color: #374151;
}
.status-impact_assessment_due {
    background-color: #fef3c7;
    color: #92400e;
}
.status-impact_assessment_submitted {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Safety net: any badge with a status-* class that isn't covered above gets a
   readable neutral colour instead of inheriting Bootstrap's invisible white.
   `:where()` keeps specificity at 0 so the explicit .status-active / etc.
   classes above still win. */
:where(.badge[class*="status-"]) {
    background-color: #e5e7eb;
    color: #374151;
}

/* Priority badges */
.priority-critical { background-color: #fee2e2; color: #991b1b; }
.priority-high { background-color: #ffedd5; color: #9a3412; }
.priority-medium { background-color: #fef3c7; color: #92400e; }
.priority-low { background-color: #d1fae5; color: #065f46; }

/* Risk matrix colors */
.risk-critical { background-color: #dc2626; color: #fff; }
.risk-high { background-color: #f97316; color: #fff; }
.risk-medium { background-color: #eab308; color: #000; }
.risk-low { background-color: #22c55e; color: #fff; }

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1, .page-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

/* Breadcrumb */
.breadcrumb {
    background: transparent;
    padding: 0;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

/* Forms */
.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: #374151;
}

.form-control, .form-select {
    border-radius: 0.5rem;
    border: 1px solid #d1d5db;
    font-size: 0.875rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(79, 110, 247, 0.15);
}

/* Buttons */
.btn {
    border-radius: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
}

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

.btn-primary:hover {
    background-color: #3d5bd9;
    border-color: #3d5bd9;
}

/* Legibility safety net: solid-coloured buttons and badges must always show
   white text — including when used on an <a> (link), where the theme's link
   colour would otherwise sit on a same-colour background and become invisible. */
.btn-primary, .btn-success, .btn-danger, .btn-info, .btn-secondary, .btn-dark,
a.btn-primary, a.btn-success, a.btn-danger, a.btn-info, a.btn-secondary, a.btn-dark,
.btn-primary:hover, .btn-success:hover, .btn-danger:hover, .btn-info:hover,
.btn-secondary:hover, .btn-dark:hover {
    color: #fff;
}
a.badge.bg-primary, a.badge.bg-success, a.badge.bg-danger,
a.badge.bg-info, a.badge.bg-secondary, a.badge.bg-dark {
    color: #fff;
    text-decoration: none;
}

/* Clickable workflow steps — jump to the Documents tab to record the step */
.wf-clickable { cursor: pointer; border-radius: 0.4rem; transition: background 0.15s; }
.wf-clickable:hover { background: #eef2ff; }

/* Contract detail tabs */
.nav-tabs .nav-link {
    color: #6b7280;
    font-weight: 500;
    font-size: 0.85rem;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0.75rem 1rem;
}

.nav-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

.nav-tabs .nav-link:hover {
    border-bottom-color: #d1d5db;
}

/* Financial summary */
.financial-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.financial-item:last-child {
    border-bottom: none;
    font-weight: 700;
    padding-top: 0.75rem;
    border-top: 2px solid #e5e7eb;
}

.financial-item .label {
    color: #6b7280;
}

.financial-item .amount {
    font-weight: 600;
    color: #1f2937;
}

.amount-positive { color: var(--success); }
.amount-negative { color: var(--danger); }

/* Detail sections */
.detail-section {
    margin-bottom: 1.5rem;
}

.detail-row {
    display: flex;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.detail-label {
    width: 200px;
    min-width: 200px;
    color: #6b7280;
    font-weight: 500;
    font-size: 0.85rem;
}

.detail-value {
    color: #1f2937;
    font-size: 0.85rem;
}

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d29 0%, #2d3148 100%);
}

.login-card {
    background: #fff;
    border-radius: 1rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card h2 {
    font-weight: 700;
    margin-bottom: 0.5rem;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 2rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #e5e7eb;
}

.timeline-item {
    position: relative;
    padding-bottom: 1.5rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.65rem;
    top: 0.25rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--primary);
}

.timeline-item.completed::before {
    background: var(--success);
    box-shadow: 0 0 0 2px var(--success);
}

.timeline-item.overdue::before {
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--danger);
}

/* Filter bar */
.filter-bar {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid #e5e7eb;
}

.filter-bar .form-control,
.filter-bar .form-select {
    font-size: 0.8rem;
    padding: 0.375rem 0.75rem;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .detail-row {
        flex-direction: column;
    }

    .detail-label {
        width: 100%;
        min-width: auto;
        margin-bottom: 0.25rem;
    }
}

/* Print */
@media print {
    .sidebar, .navbar, .btn, .filter-bar {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }
}

/* Scrollbar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 4px;
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-card, .card {
    animation: fadeIn 0.3s ease;
}

/* Autofill widget - flash highlight on fields the extractor just filled */
.autofill-flash {
    background-color: #fff3cd !important;
    transition: background-color 2s ease;
}
