/* NemarQ - Custom Styles */

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    background: #F4F6FA;
    color: #1F2937;
}

.navbar-brand i { font-size: 1.3rem; }

/* Login Page */
.login-container {
    max-width: 420px;
    margin: 80px auto;
}

.login-card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}

.login-header {
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
    color: white;
    border-radius: 12px 12px 0 0;
    padding: 2rem;
    text-align: center;
}

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

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

.stat-card .stat-icon {
    font-size: 2.5rem;
    opacity: 0.8;
}

.stat-card .stat-value {
    /* E2(a): headline metric numbers — min 36px. */
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.1;
}

/* Q&A Section */
.qa-container {
    max-width: 900px;
    margin: 0 auto;
}

.qa-answer {
    background: #f8f9fa;
    border-left: 4px solid #0d6efd;
    padding: 1.5rem;
    border-radius: 0 8px 8px 0;
    margin-top: 1rem;
}

[dir="rtl"] .qa-answer {
    border-left: none;
    border-right: 4px solid #0d6efd;
    border-radius: 8px 0 0 8px;
}

.qa-sources {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #dee2e6;
}

.qa-history-item {
    border-left: 3px solid #dee2e6;
    padding-left: 1rem;
    margin-bottom: 1.5rem;
}

[dir="rtl"] .qa-history-item {
    border-left: none;
    border-right: 3px solid #dee2e6;
    padding-left: 0;
    padding-right: 1rem;
}

/* Quiz Section */
.quiz-question-card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    margin-bottom: 1.5rem;
}

.quiz-option {
    padding: 0.75rem 1rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-option:hover {
    border-color: #0d6efd;
    background: #f0f4ff;
}

.quiz-option.selected {
    border-color: #0d6efd;
    background: #e7f0ff;
}

.quiz-option.correct {
    border-color: #198754;
    background: #d1e7dd;
}

.quiz-option.incorrect {
    border-color: #dc3545;
    background: #f8d7da;
}

/* Score Badge */
.score-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
}

.score-pass {
    background: #d1e7dd;
    color: #0f5132;
}

.score-fail {
    background: #f8d7da;
    color: #842029;
}

/* Document List */
.doc-card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: transform 0.2s;
}

.doc-card:hover {
    transform: translateY(-1px);
}

.file-icon {
    font-size: 2rem;
}

.file-icon.pdf { color: #dc3545; }
.file-icon.docx { color: #0d6efd; }
.file-icon.xlsx { color: #198754; }
.file-icon.txt { color: #6c757d; }

/* Loading Spinner */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    display: none;
}

.loading-overlay.active {
    display: flex;
}

/* Tables — enterprise standard */
.table thead th,
.table > thead > tr > th {
    background: #1B3A6B;
    color: #FFFFFF;
    font-weight: 700;
    letter-spacing: .25px;
    border-bottom: 0;
    text-transform: uppercase;
    font-size: .78rem;
    padding: .75rem .9rem;
}
.table tbody td,
.table > tbody > tr > td {
    background-color: #FFFFFF;
    border-bottom: 1px solid #E8ECF0;
    border-top: 0;
    padding: .75rem .9rem;
    vertical-align: middle;
}
.table > tbody > tr:nth-child(even) > td { background-color: #F8FAFC; }

/* B2: hover must only change background. Bootstrap 5 applies a 9999px inset
   box-shadow via --bs-table-bg-state on hover which overlays cell content
   and can wash out figures (especially badges and code chips). Override the
   shadow and force text colour to stay legible. */
.table > tbody > tr:hover > td,
.table-hover > tbody > tr:hover > td,
.table-hover > tbody > tr:hover > * {
    background-color: #EEF2FF !important;
    box-shadow: none !important;
    color: #1A1A1A !important;
    --bs-table-bg-state: transparent !important;
    --bs-table-color-state: inherit !important;
}
/* Inner spans / badges / code keep their own colour — never inherit hover override */
.table-hover > tbody > tr:hover > td > .badge,
.table-hover > tbody > tr:hover > td > code,
.table-hover > tbody > tr:hover > td > a.btn,
.table-hover > tbody > tr:hover > td > span.badge,
.table-hover > tbody > tr:hover > td .badge,
.table-hover > tbody > tr:hover > td code {
    color: revert !important;
}
.table { border-collapse: separate; border-spacing: 0; }
.table tbody tr:last-child td { border-bottom: 0; }

/* Tables typically render inside .pp-section / .card — round the corners */
.card .table, .pp-section .table { margin-bottom: 0; }

/* Action buttons inside tables — small, outline, right-aligned by default */
.table td .btn-sm,
.table td .btn-action {
    padding: .25rem .55rem;
    font-size: .78rem;
    border-radius: 6px;
}
.table td.actions, .table th.actions { text-align: right; }
[dir="rtl"] .table td.actions, [dir="rtl"] .table th.actions { text-align: left; }

/* Cards — enterprise white card */
.card {
    background: #FFFFFF;
    border: none;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card > .card-body { padding: 1.5rem; }
.card > .card-header {
    background: #FFFFFF;
    border-bottom: 1px solid #E8ECF0;
    padding: 1rem 1.5rem;
    font-weight: 600;
    color: #1B3A6B;
}

/* Status badges / RAG (Bootstrap badge override) */
.badge.status-compliant,
.badge.status-active {
    background: #E8F5EE !important;
    color: #1A5C38 !important;
}
.badge.status-partial,
.badge.status-review {
    background: #FFF8E1 !important;
    color: #7A4F00 !important;
}
.badge.status-noncompliant,
.badge.status-overdue {
    background: #FFF0F0 !important;
    color: #7A1A1A !important;
}
.badge.status-notstarted,
.badge.status-draft {
    background: #F4F6FA !important;
    color: #4A4A4A !important;
}

/* Generic Bootstrap badge re-skin to soft chips for known colour cues */
.bg-success.badge, .badge.bg-success {
    background-color: #E8F5EE !important;
    color: #1A5C38 !important;
}
.bg-warning.badge, .badge.bg-warning,
.badge.bg-warning.text-dark {
    background-color: #FFF8E1 !important;
    color: #7A4F00 !important;
}
.bg-danger.badge, .badge.bg-danger {
    background-color: #FFF0F0 !important;
    color: #7A1A1A !important;
}
.badge.bg-secondary {
    background-color: #F4F6FA !important;
    color: #4A4A4A !important;
}

/* Form labels and inputs */
.form-label {
    color: #4A4A4A;
    font-weight: 500;
    font-size: .875rem;
    margin-bottom: .35rem;
}
.form-control, .form-select {
    border-color: #D0D7E3;
    border-radius: 8px;
    color: #1F2937;
}
.form-control:focus, .form-select:focus {
    border-color: #1B3A6B;
    box-shadow: 0 0 0 3px rgba(27,58,107,.15);
}
.input-group-text {
    background: #F4F6FA;
    border-color: #D0D7E3;
    color: #4A4A4A;
}

/* Quiz Builder - Dynamic Questions */
.question-block {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    position: relative;
}

.question-block .remove-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

[dir="rtl"] .question-block .remove-btn {
    right: auto;
    left: 0.5rem;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h5 {
    color: #495057;
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1.25rem;
}

/* Framework pill badges (brief 3B.5) */
.fw-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.fw-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1.4;
    white-space: nowrap;
    border: 1px solid transparent;
}

.fw-pill-coso              { background: #1a2e5c; color: #fff; }    /* navy */
.fw-pill-iia-critical      { background: #dc3545; color: #fff; }    /* red */
.fw-pill-iia-significant   { background: #ffc107; color: #212529; } /* amber */
.fw-pill-iia-moderate      { background: #0d6efd; color: #fff; }    /* blue */
.fw-pill-iia-minor         { background: #6c757d; color: #fff; }    /* grey */
.fw-pill-basel             { background: #fd7e14; color: #fff; }    /* amber */
.fw-pill-fatf              { background: #20c997; color: #fff; }    /* teal */
.fw-pill-cbuae             { background: #198754; color: #fff; }    /* green */
.fw-pill-icaap             { background: #6f42c1; color: #fff; }    /* purple */
.fw-pill-raci              { background: transparent; color: #dc3545;
                              border-color: #dc3545; }              /* red outline */
.fw-pill-neutral           { background: #e9ecef; color: #495057;
                              border-color: #ced4da; }

/* Governance Health Score card (brief 3B.1) */
.health-score-card {
    border: none;
    border-radius: 14px;
    color: #fff;
    box-shadow: 0 4px 18px rgba(0,0,0,0.10);
}
.health-score-card.score-high   { background: linear-gradient(135deg, #198754, #146c43); }
.health-score-card.score-mid    { background: linear-gradient(135deg, #fd7e14, #d06300); color: #212529; }
.health-score-card.score-low    { background: linear-gradient(135deg, #dc3545, #a71d2a); }
.health-score-card .score-num    { font-size: 3.5rem; font-weight: 700; line-height: 1; }
.health-score-card .score-label  { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.8px; opacity: 0.9; }
.health-score-card .component    { background: rgba(255,255,255,0.18); border-radius: 8px;
                                   padding: 0.5rem 0.75rem; }
.health-score-card .component .cval  { font-size: 1.25rem; font-weight: 600; }
.health-score-card .component .clabel{ font-size: 0.75rem; opacity: 0.9; }

/* Heatmap cells (brief 3B.2) */
.heatmap-cell {
    aspect-ratio: 1;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    color: #212529;
    text-decoration: none;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 4px;
    transition: transform 0.1s, box-shadow 0.1s;
    cursor: pointer;
}
.heatmap-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 2;
    position: relative;
}
.heatmap-zone-green  { background: #d1e7dd; }
.heatmap-zone-amber  { background: #fff3cd; }
.heatmap-zone-red    { background: #f8d7da; }

/* Document cards colour-coding (brief 3B.4) */
.doc-version-badge    { background: #1a2e5c; color: #fff; font-size: 0.75rem;
                         padding: 3px 8px; border-radius: 10px; font-weight: 600; }
.doc-status-active    { background: #198754; color: #fff; }
.doc-status-review    { background: #ffc107; color: #212529; }
.doc-status-draft     { background: #6c757d; color: #fff; }
.doc-status-superseded{ background: #dc3545; color: #fff; }

.doc-review-fresh     { color: #198754; font-weight: 600; }
.doc-review-due       { color: #fd7e14; font-weight: 600; }
.doc-review-overdue   { color: #dc3545; font-weight: 600; }

.doc-class-public       { background: #6c757d; color: #fff; }
.doc-class-internal     { background: #0d6efd; color: #fff; }
.doc-class-confidential { background: #fd7e14; color: #fff; }
.doc-class-restricted   { background: #dc3545; color: #fff; }

/* Classification badges for the P&P Library (Policy=navy, Procedure=blue, SOP=teal) */
.doc-type-policy    { background: #1a2e5c; color: #fff; }
.doc-type-procedure { background: #0d6efd; color: #fff; }
.doc-type-sop       { background: #0d9488; color: #fff; }

/* Institution type badge (brief 3B.6) */
.institution-type-badge {
    background: #fff; color: #1a2e5c;
    border-radius: 6px; padding: 4px 10px;
    font-weight: 700; letter-spacing: 0.3px;
    font-size: 0.8rem;
}
.institution-type-badge .subtype {
    font-weight: 500; opacity: 0.75; margin-left: 4px;
}

/* B1: AI Insights finding card readability — enforce dark body text. */
.finding-card .card-body,
.finding-card .card-body p,
.finding-card .card-body li,
.finding-card .card-body blockquote,
.finding-card .card-body strong {
    color: #1A1A1A;
}
/* sub-text muted rows: keep subdued but meet WCAG AA on white (4.5:1) */
.finding-card .card-body .text-muted,
.finding-card .card-body .small.text-muted,
.finding-card .card-body small {
    color: #4A5568 !important;
}
/* Issue / rationale / remediation body text */
.finding-card .card-body .finding-remediation,
.finding-card .card-body .finding-quote,
.finding-card .card-body .finding-quote blockquote {
    color: #1A1A1A;
}
/* Styled quote block — clearly readable, left-bordered */
.finding-card .finding-quote blockquote {
    border-left: 3px solid #1A2E5C;
    padding: 6px 12px;
    margin: 6px 0 0;
    background: #F4F6FA;
    font-style: italic;
    color: #1A1A1A;
    line-height: 1.5;
    font-size: 0.95rem;
}
/* Remediation — coloured accent but dark text, not yellow-on-white */
.finding-card .card-body .finding-remediation {
    background: #FFF8E1;
    border-left: 3px solid #B7791F;
    padding: 4px 10px;
    border-radius: 4px;
    display: inline-block;
    color: #1A1A1A;
}
/* Recommended-control (risks tab) reuses the same pattern — keep dark text */
.finding-card-risk .card-body .text-danger {
    color: #9B1C1C !important;
}
/* Recommendation on automation cards — darker green, readable on white */
.finding-card-automation .card-body .text-success {
    color: #0F5132 !important;
}
/* CBUAE ref chip — dark text on a subtle background, clearly readable */
.finding-card .cbuae-ref {
    background: #E8F2EC;
    color: #0F5132;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid #B8D8C2;
}
/* Policy-clause reference link — dark, clearly readable, no browser-default blue */
.finding-card .policy-clause-link {
    text-decoration: none;
    color: #1A1A1A;
}
.finding-card .policy-clause-link code {
    background: #EEF2F7;
    color: #1A2E5C;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
    border: 1px solid #D6DDE8;
    font-size: 0.85rem;
}
.finding-card .policy-clause-link:hover code {
    background: #E0E7F1;
    text-decoration: none;
}
/* Framework pills inside finding cards — keep existing colours but bump
   contrast for neutral/outline variants where they sit on white. */
.finding-card .fw-pill-neutral {
    color: #2C2C2C;
    background: #E8ECF2;
    border-color: #C5CED9;
}
/* Ensure body text on the insights page is never rendered lighter than 2C2C2C */
.finding-card .card-body { font-size: 0.95rem; line-height: 1.55; }


/* B8: friendly error page styling — replaces raw Werkzeug tracebacks. */
.error-card { border: 1px solid #D6DDE8; border-radius: 12px; }
.error-card .error-code {
    font-size: 4rem; font-weight: 700; color: #1A2E5C;
    letter-spacing: 2px; line-height: 1; margin-bottom: 12px;
}
.error-card code { background: #EEF2F7; color: #1A2E5C; padding: 2px 8px;
                   border-radius: 4px; font-weight: 600; }

/* B2: Policy-clause modal styling (replaces the old black alert popup). */
#policyClauseModal .modal-content {
    border-radius: 10px;
    border: 1px solid #D6DDE8;
}
#policyClauseModal .modal-header {
    background: #EEF2F7;
    color: #1A2E5C;
    border-bottom: 1px solid #D6DDE8;
}
#policyClauseModal .modal-title { font-weight: 700; }
#policyClauseModal .modal-body { color: #1A1A1A; }
.policy-clause-modal-ref {
    display: inline-block;
    background: #EEF2F7;
    color: #1A2E5C;
    padding: 6px 12px;
    border: 1px solid #D6DDE8;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
}
.policy-clause-modal-quote {
    border-left: 3px solid #1A2E5C;
    padding: 8px 14px;
    margin: 0;
    background: #F4F6FA;
    font-style: italic;
    color: #1A1A1A;
    border-radius: 0 4px 4px 0;
}

/* B3: containment rules so finding card content never breaks outside the
   card at any viewport width (tested at 1280px and 1920px). */
.finding-card,
.finding-card .card-body { overflow-wrap: break-word; }
.finding-card .card-body h5,
.finding-card .card-body p,
.finding-card .card-body blockquote,
.finding-card .card-body li,
.finding-card .card-body code,
.finding-card .card-body span {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}
/* Header row: allow the title block and badge block to share a line on wide
   screens but wrap onto separate rows rather than push the badges beyond
   the card's right edge. */
.finding-card .card-body > .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: .5rem;
}
.finding-card .card-body > .d-flex.justify-content-between > h5,
.finding-card .card-body > .d-flex.justify-content-between > .flex-grow-1 {
    flex: 1 1 260px;
    min-width: 0;
}
.finding-card .card-body > .d-flex.justify-content-between > div:last-child {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: flex-end;
}
/* Framework-pill row: allow wrapping and prevent long CBUAE refs from
   stretching the card wider than its column. */
.finding-card .fw-pills { flex-wrap: wrap; max-width: 100%; }
.finding-card .fw-pill { max-width: 100%; white-space: normal; }
/* The policy-clause chip should wrap rather than horizontally overflow. */
.finding-card .policy-clause-link code { white-space: normal; word-break: break-word; }
/* Insights top banner (source type) also used d-flex without wrap. */
.alert.d-flex.align-items-center { flex-wrap: wrap; }
.alert.d-flex.align-items-center > div { min-width: 0; flex: 1 1 auto; overflow-wrap: anywhere; }

/* ============================================================
   E2: General UI enhancement pass (Corporater comparison).
   ============================================================ */

/* E2(a): accent bar on top of dashboard metric cards by metric colour.
   stat-card already uses Bootstrap bg-* utilities — we layer a coloured
   top bar so the category is identifiable at a glance. */
.stat-card { position: relative; overflow: hidden; }
.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.35);
}
.stat-card.bg-primary::before { background: #0d6efd; }
.stat-card.bg-success::before { background: #198754; }
.stat-card.bg-warning::before { background: #f59f00; }
.stat-card.bg-danger::before  { background: #dc3545; }
.stat-card.bg-info::before    { background: #0dcaf0; }
.stat-card.bg-secondary::before { background: #6c757d; }

/* E2(b): risk heatmap — visible cell borders, bold large numbers, and a
   subtle "High Risk / Medium Risk / Low Risk" label as background text. */
.heatmap-cell {
    border: 1.5px solid rgba(0, 0, 0, 0.18);
    font-size: 1.05rem;        /* ~16.8px — meets "min 16px" */
    font-weight: 700;
    position: relative;
    min-height: 64px;
}
.heatmap-zone-red    { background: #f8d7da; }
.heatmap-zone-amber  { background: #fff3cd; }
.heatmap-zone-green  { background: #d1e7dd; }
.heatmap-zone-red::after,
.heatmap-zone-amber::after,
.heatmap-zone-green::after {
    position: absolute;
    bottom: 4px; right: 6px;
    font-size: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.35;
    pointer-events: none;
}
.heatmap-zone-red::after   { content: 'High Risk'; color: #721c24; }
.heatmap-zone-amber::after { content: 'Medium Risk'; color: #856404; }
.heatmap-zone-green::after { content: 'Low Risk'; color: #155724; }

/* E2(c): finding cards consistent padding, badge separation, readable body. */
.finding-card .card-body { padding: 1rem 1.25rem; font-size: 0.95rem; }
.finding-card .fw-pills { gap: 6px 8px; margin-top: 10px; }
.finding-card .fw-pill { margin-right: 0; }     /* gap handles spacing */

/* Buttons — enterprise standard */
.btn { border-radius: 8px; font-weight: 600; }
.btn-sm { border-radius: 6px; }

.btn-primary {
    background-color: #1B3A6B;
    border-color: #1B3A6B;
    color: #FFFFFF;
    box-shadow: none;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active,
.btn-primary:focus-visible {
    background-color: #152D54;
    border-color: #152D54;
    color: #FFFFFF;
    box-shadow: none;
}
.btn-secondary,
.btn-outline-primary,
.btn-outline-secondary {
    background-color: #FFFFFF;
    border-color: #1B3A6B;
    color: #1B3A6B;
}
.btn-secondary:hover,
.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active,
.btn-outline-secondary:hover {
    background-color: #1B3A6B;
    border-color: #1B3A6B;
    color: #FFFFFF;
}
.btn-danger {
    background-color: #DC3545;
    border-color: #DC3545;
    color: #FFFFFF;
}
.btn-danger:hover, .btn-danger:focus, .btn-danger:active {
    background-color: #BB2D3B;
    border-color: #BB2D3B;
    color: #FFFFFF;
}

/* Form "action" button group at the bottom of forms — keep gap consistent. */
form .d-flex.gap-2 .btn { min-width: 120px; }

/* Server-rendered draft markdown (drafts/view.html). The Python markdown
   library emits bare <table> elements, so style them directly here to give
   the RACI matrix a bordered, striped, Bootstrap-like look. */
.draft-rendered-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.draft-rendered-content table th,
.draft-rendered-content table td {
    border: 1px solid #dee2e6;
    padding: 0.5rem;
    text-align: left;
}
.draft-rendered-content table th {
    background-color: #f8f9fa;
    font-weight: 600;
}
.draft-rendered-content table tr:nth-child(even) {
    background-color: #f8f9fa;
}
