/* =========================================================================
   TEMS / TJIC — Unified Design System
   Single source of truth for interactive (screen) UI.
   Report/print templates (app/templates/reports/*, email/*) keep their own
   print-optimized styles and are intentionally not governed by this sheet.
   ========================================================================= */

/* --- Design Tokens ------------------------------------------------------- */
:root {
    /* Typography */
    --tems-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                      "Helvetica Neue", Arial, sans-serif;
    --tems-font-mono: "SF Mono", "Fira Code", "Courier New", monospace;

    /* ICS Section Palette (used for buttons, accents, unit headers) */
    --ics-command:   #4b5563;   /* neutral dark gray   */
    --ics-command-hover: #374151;
    --ics-command-soft: #f3f4f6;

    --ics-planning:  #0d6efd;   /* blue */
    --ics-planning-hover: #0b5ed7;
    --ics-planning-soft: #e7f1ff;

    --ics-operations:#dc3545;   /* red */
    --ics-operations-hover: #bb2d3b;
    --ics-operations-soft: #fdecee;

    --ics-logistics: #ffc107;   /* yellow */
    --ics-logistics-hover: #e0a800;
    --ics-logistics-soft: #fff3cd;

    --ics-finance:   #198754;   /* green */
    --ics-finance-hover: #157347;
    --ics-finance-soft: #d1e7dd;

    --ics-safety:    #fd7e14;   /* orange */
    --ics-safety-hover: #e96b02;
    --ics-safety-soft: #ffe5d0;

    --ics-drill:     #7c3aed;   /* purple — drill design/exercise */
    --ics-drill-hover: #6d28d9;
    --ics-drill-soft: #ede9fe;

    /* Neutral surfaces */
    --surface-bg: #ffffff;
    --surface-muted: #f8f9fa;
    --surface-alt: #f3f4f6;
    --border-subtle: #e5e7eb;
    --border-default: #dee2e6;

    /* Semantic text */
    --text-body: #212529;
    --text-muted: #64748b;
    --text-on-dark: #f1f5f9;
}

/* --- Base Typography ---------------------------------------------------- */
body {
    font-family: var(--tems-font-sans);
    color: var(--text-body);
}

/* Headings share the sans stack so nothing drifts into a different face */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-family: var(--tems-font-sans);
    font-weight: 600;
}

/* Monospace utility for logs, coordinates, timers, ICS-214a */
.text-mono,
code, kbd, samp, pre {
    font-family: var(--tems-font-mono);
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 0.02em;
}

/* --- Bootstrap-Aligned Button Extensions ------------------------------- */
/* ICS-section buttons. Naming mirrors Bootstrap variants so .btn btn-X
   behaves visually like Bootstrap's own .btn btn-primary.               */

.btn-command {
    background-color: var(--ics-command);
    border-color: var(--ics-command);
    color: #fff;
}
.btn-command:hover, .btn-command:focus {
    background-color: var(--ics-command-hover);
    border-color: var(--ics-command-hover);
    color: #fff;
}

.btn-logistics {
    background-color: var(--ics-logistics);
    border-color: var(--ics-logistics);
    color: #000;
}
.btn-logistics:hover, .btn-logistics:focus {
    background-color: var(--ics-logistics-hover);
    border-color: var(--ics-logistics-hover);
    color: #000;
}

.btn-finance {
    background-color: var(--ics-finance);
    border-color: var(--ics-finance);
    color: #fff;
}
.btn-finance:hover, .btn-finance:focus {
    background-color: var(--ics-finance-hover);
    border-color: var(--ics-finance-hover);
    color: #fff;
}

.btn-ops {
    background-color: var(--ics-safety);
    border-color: var(--ics-safety);
    color: #fff;
}
.btn-ops:hover, .btn-ops:focus {
    background-color: var(--ics-safety-hover);
    border-color: var(--ics-safety-hover);
    color: #fff;
}

.btn-purple {
    background-color: var(--ics-drill);
    border-color: var(--ics-drill);
    color: #fff;
}
.btn-purple:hover, .btn-purple:focus {
    background-color: var(--ics-drill-hover);
    border-color: var(--ics-drill-hover);
    color: #fff;
}

/* Outline versions for secondary actions */
.btn-outline-command {
    color: var(--ics-command);
    border-color: var(--ics-command);
    background-color: transparent;
}
.btn-outline-command:hover {
    background-color: var(--ics-command);
    color: #fff;
}

/* Delete / mark-received helpers used in map popups and doc lists */
.btn-delete {
    color: #dc3545;
    border: 1px solid #dc3545;
    background: transparent;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-delete:hover {
    background-color: #dc3545;
    color: #fff;
}
.btn-mark-received {
    min-width: 120px;
}

/* --- Unit / Section Headers -------------------------------------------- */
.unit-header {
    background-color: var(--surface-alt);
    border-bottom: 2px solid var(--ics-command);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border-radius: 0.25rem 0.25rem 0 0;
}
.unit-header--command    { background-color: var(--ics-command-soft);    border-bottom-color: var(--ics-command); }
.unit-header--planning   { background-color: var(--ics-planning-soft);   border-bottom-color: var(--ics-planning); }
.unit-header--operations { background-color: var(--ics-operations-soft); border-bottom-color: var(--ics-operations); }
.unit-header--logistics  { background-color: var(--ics-logistics-soft);  border-bottom-color: var(--ics-logistics); }
.unit-header--finance    { background-color: var(--ics-finance-soft);    border-bottom-color: var(--ics-finance); }
.unit-header--safety     { background-color: var(--ics-safety-soft);     border-bottom-color: var(--ics-safety); }
.unit-header--drill      { background-color: var(--ics-drill-soft);      border-bottom-color: var(--ics-drill); }

/* Card accent bars (left border) */
.command-accent    { border-left: 4px solid var(--ics-command); }
.planning-accent   { border-left: 4px solid var(--ics-planning); }
.operations-accent { border-left: 4px solid var(--ics-operations); }
.logistics-accent  { border-left: 4px solid var(--ics-logistics); }
.finance-accent    { border-left: 4px solid var(--ics-finance); }
.safety-accent     { border-left: 4px solid var(--ics-safety); }
.drill-accent      { border-left: 4px solid var(--ics-drill); }

/* --- Status / Resource Badges ----------------------------------------- */
.status-ordered        { background-color: #6c757d; color: #fff; }
.status-available      { background-color: #28a745; color: #fff; }
.status-assigned       { background-color: #ffc107; color: #000; }
.status-out-of-service { background-color: #dc3545; color: #fff; }
.status-demobilized    { background-color: #17a2b8; color: #fff; }

.status-reserved    { background-color: #ffc107; color: #000; }
.status-confirmed   { background-color: #17a2b8; color: #fff; }
.status-occupied    { background-color: #28a745; color: #fff; }
.status-checked-out { background-color: #6c757d; color: #fff; }
.status-cancelled   { background-color: #dc3545; color: #fff; }

.status-in-use      { background-color: #28a745; color: #fff; }
.status-maintenance { background-color: #dc3545; color: #fff; }
.status-returned    { background-color: #6c757d; color: #fff; }

.status-planned     { background-color: #6c757d; color: #fff; }
.status-in-progress { background-color: #17a2b8; color: #fff; }
.status-completed   { background-color: #28a745; color: #fff; }

.status-active      { background-color: #28a745; color: #fff; }
.status-standby     { background-color: #ffc107; color: #000; }
.status-inactive    { background-color: #6c757d; color: #fff; }

.status-on-call      { background-color: #17a2b8; color: #fff; }
.status-dispatched   { background-color: #fd7e14; color: #fff; }
.status-unavailable  { background-color: #dc3545; color: #fff; }
.status-limited      { background-color: #ffc107; color: #000; }
.status-diversion    { background-color: #fd7e14; color: #fff; }
.status-closed       { background-color: #dc3545; color: #fff; }
.status-draft        { background-color: #6c757d; color: #fff; }

/* Trauma levels */
.trauma-level-i   { background-color: #dc3545; color: #fff; }
.trauma-level-ii  { background-color: #fd7e14; color: #fff; }
.trauma-level-iii { background-color: #ffc107; color: #000; }
.trauma-level-iv  { background-color: #17a2b8; color: #fff; }
.trauma-level-v   { background-color: #6c757d; color: #fff; }

/* Priority / decision badges */
.priority-critical { background-color: #dc3545; color: #fff; }
.priority-high     { background-color: #fd7e14; color: #fff; }
.priority-standard { background-color: #6c757d; color: #fff; }

.decision-proposed  { background-color: #ffc107; color: #000; }
.decision-approved  { background-color: #28a745; color: #fff; }
.decision-rescinded { background-color: #dc3545; color: #fff; }

.cat-strategic { background-color: #6f42c1; color: #fff; }
.cat-tactical  { background-color: #dc3545; color: #fff; }
.cat-resource  { background-color: #0d6efd; color: #fff; }
.cat-safety    { background-color: #fd7e14; color: #fff; }
.cat-financial { background-color: #198754; color: #fff; }
.cat-policy    { background-color: #6c757d; color: #fff; }

/* IAP status badges */
.iap-draft            { background-color: #6c757d; color: #fff; }
.iap-pending_approval { background-color: #ffc107; color: #000; }
.iap-approved         { background-color: #28a745; color: #fff; }
.iap-distributed      { background-color: #0d6efd; color: #fff; }

/* Concurrence indicators */
.concurrence-concurred { color: #28a745; }
.concurrence-non-concur { color: #dc3545; }
.concurrence-pending { color: #6c757d; }

/* Meeting timeline */
.meeting-past { opacity: 0.6; }
.meeting-next { border-left: 3px solid #28a745; background-color: #f0fff4; }

/* --- Resource / Card patterns ----------------------------------------- */
.resource-card {
    transition: box-shadow 0.2s ease;
}
.resource-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.group-indicator {
    border-left: 3px solid var(--ics-planning);
    padding-left: 10px;
}

/* --- Shared ICS content block ----------------------------------------- */
.ics-content-block {
    background-color: var(--surface-muted);
    border-left: 3px solid var(--ics-command);
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
    font-size: 0.85rem;
}
.ics-content-block.empty {
    color: var(--text-muted);
    font-style: italic;
    border-left-color: var(--border-default);
}

/* --- Page / Incident Header -------------------------------------------- */
.page-header {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
    color: #fff;
    padding: 0.6rem 1rem;
}
.page-header-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.page-header .sidebar-trigger {
    flex: 0 0 auto;
    padding: 0.25rem 0.6rem;
    line-height: 1.2;
}
.page-header .sidebar-trigger i { font-size: 1.1rem; }

.page-header-title {
    flex: 1 1 auto;
    min-width: 0;
}
.page-header h1 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.page-header .meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-top: 0.15rem;
    font-size: 0.8rem;
    opacity: 0.9;
}
.page-header .meta-id {
    font-family: var(--tems-font-mono);
    font-size: 0.75rem;
    opacity: 0.85;
}
.page-header .badge { font-size: 0.7rem; font-weight: 500; }
.page-header .phase-badge { color: #fff; }
.page-header .phase-design    { background-color: var(--ics-drill); }
.page-header .phase-execution { background-color: #f59e0b; }
.page-header .phase-hotwash,
.page-header .phase-complete  { background-color: #10b981; }

.page-header-actions {
    display: flex;
    gap: 0.4rem;
    flex: 0 0 auto;
    margin-left: auto;
}
.page-header-actions .btn { white-space: nowrap; }

/* --- Situation Status Bar (dashboard) -------------------------------- */
.situation-bar {
    background: linear-gradient(135deg, #1e3a5f 0%, #2c5282 100%);
    border-radius: 10px;
    color: #fff;
    overflow: hidden;
}
.situation-bar-item {
    padding: 1rem 1.25rem;
    border-right: 1px solid rgba(255, 255, 255, 0.15);
}
.situation-bar-item:last-child { border-right: none; }
.situation-bar-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
    margin-bottom: 0.35rem;
}
.situation-bar-value {
    font-size: 1.35rem;
    font-weight: 700;
}
.situation-bar-detail {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-top: 0.15rem;
}

/* Countdown timer (shared) */
.countdown-display {
    font-family: var(--tems-font-mono);
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffd700;
    margin-top: 0.25rem;
}
.countdown-display.countdown-imminent {
    color: #fc8181;
    animation: pulse-countdown 1s ease-in-out infinite;
}
@keyframes pulse-countdown {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* --- Tables ------------------------------------------------------------ */
.table-hover tbody tr:hover { background-color: rgba(0, 0, 0, 0.025); }

/* --- Incident Layout (sidebar + main) --------------------------------- */
.incident-layout {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
}

.incident-sidebar {
    background: #1e293b;
    min-height: calc(100vh - 100px);
    overflow-y: auto;
    flex: 0 0 220px;
    max-width: 220px;
}

/* Override Bootstrap's lg+ transparent background on offcanvas-lg element.
   Bootstrap uses !important to strip the offcanvas styling at lg+, so we
   restore our dark sidebar with !important at the same specificity.       */
@media (min-width: 992px) {
    .incident-sidebar.offcanvas-lg { background-color: #1e293b !important; }
    .incident-sidebar .offcanvas-body {
        background-color: #1e293b !important;
        flex-grow: 1;
        overflow-y: auto;
    }
}
.incident-sidebar .offcanvas-header {
    background: #0f172a;
    color: var(--text-on-dark);
    border-bottom: 1px solid #334155;
    padding: 0.75rem 1rem;
}
.incident-sidebar .offcanvas-title { color: var(--text-on-dark); }

.incident-sidebar .nav-section {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    padding: 0.9rem 0.85rem 0.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.incident-sidebar .nav-link {
    color: #cbd5e1;
    padding: 0.45rem 0.85rem;
    font-size: 0.85rem;
    border-left: 3px solid transparent;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    transition: background-color 0.1s, color 0.1s;
}
.incident-sidebar .nav-link:hover {
    background: #334155;
    color: var(--text-on-dark);
}
.incident-sidebar .nav-link.active {
    background: #334155;
    color: #ffffff;
    border-left-color: #3b82f6;
    font-weight: 600;
}
.incident-sidebar .nav-link i {
    width: 18px;
    text-align: center;
    margin-right: 0.5rem;
    font-size: 0.9rem;
}
.incident-sidebar .nav-link > span {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.incident-sidebar .nav-link .badge {
    font-size: 0.68rem;
    font-weight: 500;
    flex-shrink: 0;
}
.incident-sidebar .nav-divider {
    border-top: 1px solid #334155;
    margin: 0.5rem 0.85rem;
}
.incident-sidebar .sidebar-toggle {
    cursor: pointer;
    user-select: none;
}
.incident-sidebar .sidebar-toggle:hover { color: #f1f5f9 !important; }
.incident-sidebar .sidebar-toggle .chevron { transition: transform 0.2s; }
.incident-sidebar .section-items.collapsed { display: none; }

.incident-main {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--surface-bg);
}

/* --- Responsive: below lg — sidebar becomes offcanvas drawer --------- */
@media (max-width: 991.98px) {
    .incident-layout { display: block; }

    /* When offcanvas-lg is "inactive" (i.e. below lg), Bootstrap makes it
       slide from the edge. Give it our dark styling and a sensible width. */
    .incident-sidebar.offcanvas-lg {
        width: 280px;
        max-width: 85vw;
        min-height: 100vh;
        flex: 0 0 280px;
    }
    .incident-sidebar .nav-link { font-size: 0.95rem; padding: 0.6rem 1rem; }
    .incident-sidebar .nav-link i { font-size: 1rem; }
    .incident-sidebar .nav-section { font-size: 0.7rem; padding: 1rem 1rem 0.3rem; }
}

/* --- Responsive: mobile (< 768px) ------------------------------------ */
@media (max-width: 767.98px) {
    .situation-bar-item {
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.15);
        padding: 0.75rem 1rem;
    }
    .situation-bar-item:last-child { border-bottom: none; }
}

/* --- Responsive: phone (< 576px) ------------------------------------- */
@media (max-width: 575.98px) {
    .incident-main .p-4 { padding: 0.75rem !important; }

    /* Touch targets: 44px minimum per Apple HIG */
    .btn-sm { min-height: 44px; min-width: 44px; padding: 0.5rem 0.75rem; font-size: 0.85rem; }
    .form-control-sm, .form-select-sm { min-height: 44px; font-size: 1rem; }
    .form-control, .form-select { min-height: 44px; }

    [style*="min-width"] { min-width: unset !important; }

    .notification-row,
    .log-entry-row,
    .org-position-row {
        flex-wrap: wrap !important;
        gap: 0.25rem;
        padding: 0.75rem !important;
    }
    .notification-row > div,
    .log-entry-row > div,
    .org-position-row > div { min-width: unset !important; }

    .notification-row .notif-role { width: calc(100% - 44px); font-weight: 600; }
    .notification-row .notif-details { width: 100%; font-size: 0.82rem; }
    .notification-row .notif-action { width: 100%; margin-top: 0.25rem; }
    .notification-row .notif-action .btn { width: 100%; }

    .log-entry-row .log-timestamp { font-size: 0.8rem; }
    .log-entry-row .log-text { width: 100%; margin-top: 0.25rem; }
    .log-entry-row .log-reporter { width: 100%; text-align: left !important; font-size: 0.78rem; }
    .log-entry-row .log-delete { position: absolute; top: 0.5rem; right: 0.5rem; }

    .org-position-row .org-position-name { width: 100%; font-weight: 600; margin-bottom: 0.15rem; }
    .org-position-row .org-person-name { width: 100%; }
    .org-position-row .org-phone { width: calc(100% - 80px); }
    .org-position-row .org-action { width: 80px; }

    .mobile-card-table thead { display: none; }
    .mobile-card-table tbody tr {
        display: block;
        padding: 0.75rem;
        margin-bottom: 0.5rem;
        border: 1px solid var(--border-subtle);
        border-radius: 0.375rem;
        background: var(--surface-bg);
    }
    .mobile-card-table tbody tr:hover { background: var(--surface-muted); }
    .mobile-card-table td {
        display: block;
        padding: 0.15rem 0;
        border: none;
        text-align: left !important;
    }
    .mobile-card-table td:before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.7rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-right: 0.5rem;
    }
    .mobile-card-table td.mobile-primary {
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 0.25rem;
    }
    .mobile-card-table td.mobile-primary:before { display: none; }
    .mobile-card-table td.mobile-action {
        margin-top: 0.5rem;
        padding-top: 0.5rem;
        border-top: 1px solid #f1f5f9;
    }
    .mobile-card-table td.mobile-action .btn { width: 100%; min-height: 44px; }
    .mobile-card-table td.mobile-hide { display: none; }

    .report-edit-actions {
        position: sticky;
        bottom: 0;
        background: #fff;
        padding: 0.75rem;
        border-top: 1px solid var(--border-default);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        z-index: 10;
        margin: 0 -0.75rem;
    }

    h4 { font-size: 1.1rem; }
    h6 { font-size: 0.9rem; }

    .page-header { padding: 0.5rem 0.75rem; }
    .page-header-inner { gap: 0.5rem; row-gap: 0.4rem; }
    .page-header h1 { font-size: 1.05rem; }
    .page-header .meta { font-size: 0.75rem; gap: 0.3rem; }
    .page-header .meta-id { font-size: 0.7rem; }
    .page-header .badge { font-size: 0.65rem; padding: 0.25rem 0.5rem; }
    .page-header .sidebar-trigger {
        min-height: auto;
        min-width: auto;
        padding: 0.3rem 0.55rem;
    }
    .page-header-actions {
        flex-basis: 100%;
        justify-content: flex-end;
        margin-left: 0;
    }
    .page-header-actions .btn {
        font-size: 0.78rem;
        padding: 0.3rem 0.6rem;
        min-height: auto;
        min-width: auto;
    }
}
