/* === Base === */
html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 16px; } }

body {
    margin-bottom: 60px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #212529;
    background-color: #f8f9fa;
}

/* === Skip Link (Accessibility) === */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0d6efd;
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 9999;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}
.skip-link:focus {
    top: 0;
    outline: 3px solid #ffc107;
    outline-offset: 2px;
}

/* === Screen Reader Only === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === Focus Styles (WCAG AA) === */
*:focus-visible {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 3px solid #0d6efd;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25);
}

/* === Navbar === */
.navbar {
    background-color: #1a3a5c !important;
}
.navbar-brand {
    font-weight: 700;
    font-size: 1.4rem;
    color: #fff !important;
    letter-spacing: 1px;
}
.navbar .nav-link {
    color: rgba(255, 255, 255, 0.85) !important;
    font-weight: 500;
    padding: 0.5rem 1rem;
    min-height: 44px;
    display: flex;
    align-items: center;
}
.navbar .nav-link:hover, .navbar .nav-link:focus {
    color: #fff !important;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
.navbar .nav-link.active {
    color: #fff !important;
    border-bottom: 2px solid #ffc107;
}

/* === Touch Targets (44x44 minimum) === */
.btn, .form-control, .form-select, .nav-link {
    min-height: 44px;
}
.btn {
    padding: 0.5rem 1.25rem;
    font-weight: 500;
}

/* === Footer === */
.footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    background-color: #fff;
    line-height: 50px;
    font-size: 0.875rem;
    z-index: 100;
    text-align: center;
}

/* === Status Badges === */
.badge-draft { background-color: #6c757d; color: #fff; }
.badge-finalized { background-color: #198754; color: #fff; }
.badge-printed { background-color: #0d6efd; color: #fff; }

/* Print layout containers — hidden on screen, shown in print */
.print-layout-container { display: none; }
.print-map-container { display: none; }

/* === Map Container === */
.map-container {
    position: relative;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
#plan-map {
    width: 100%;
    height: 70vh;
    min-height: 500px;
}
@media (max-width: 767px) {
    #plan-map { height: 50vh; min-height: 350px; }
}
@media (min-width: 1200px) {
    #plan-map { height: 75vh; }
}

/* Floating legend overlay */
.map-legend {
    position: absolute;
    bottom: 24px;
    left: 12px;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.75rem;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
.legend-line {
    display: inline-block;
    width: 24px;
    height: 4px;
    border-radius: 2px;
    vertical-align: middle;
    margin-right: 6px;
}

/* Mode badge overlay */
.map-mode-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 1000;
    font-size: 0.8rem;
}

/* === Zone Color Coding (for map legend and UI) === */
.zone-advance-warning { color: #DD6F20; }
.zone-transition { color: #e65100; }
.zone-buffer { color: #c62828; }
.zone-activity { color: #1565c0; }
.zone-termination { color: #2e7d32; }

/* === Device markers === */
.device-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 16px;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
.device-marker.modified {
    border-color: #ff5722;
    box-shadow: 0 0 8px rgba(255, 87, 34, 0.6);
}

/* Diamond-shaped marker for advance warning signs (mimics real road warning signs) */
.device-marker-diamond {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #DD6F20;
    border: 2px solid #000;
    transform: rotate(45deg);
    border-radius: 3px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.device-marker-diamond i {
    transform: rotate(-45deg);
}
.device-marker-diamond.modified {
    border-color: #ff5722;
    box-shadow: 0 0 8px rgba(255, 87, 34, 0.6);
}

/* Rectangular "END ROAD WORK" termination sign */
.device-marker-rect-sign {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #DD6F20;
    border: 2px solid #000;
    border-radius: 2px;
    padding: 2px 6px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.35);
    white-space: nowrap;
}
.device-marker-rect-sign span {
    font-family: 'Arial Narrow', Arial, Helvetica, sans-serif;
    font-size: 9px;
    font-weight: 900;
    color: #000;
    text-align: center;
    line-height: 1.1;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.device-marker-rect-sign.modified {
    border-color: #ff5722;
    box-shadow: 0 0 8px rgba(255, 87, 34, 0.6);
}

/* Pending edit indicator on markers during batch editing */
.pending-edit .device-marker,
.pending-edit .device-marker-diamond,
.pending-edit .device-marker-rect-sign {
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ff9800, 0 0 12px rgba(255, 152, 0, 0.7);
    animation: pending-pulse 1.5s ease-in-out infinite;
}
@keyframes pending-pulse {
    0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 6px #ff9800, 0 0 12px rgba(255, 152, 0, 0.7); }
    50% { box-shadow: 0 0 0 3px #fff, 0 0 0 8px #ff9800, 0 0 20px rgba(255, 152, 0, 0.5); }
}

/* btn-close-sm for smaller close buttons in badges */
.btn-close-sm {
    font-size: 0.5rem;
    padding: 0.15rem;
    vertical-align: middle;
}

/* === Cards (mobile-friendly plan list) === */
.plan-card {
    border-left: 4px solid #1a3a5c;
    transition: transform 0.15s ease;
}
.plan-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* === Forms === */
.form-group { margin-bottom: 1.25rem; }
.form-label { font-weight: 600; margin-bottom: 0.375rem; }
.help-text { font-size: 0.8125rem; color: #6c757d; margin-top: 0.25rem; }

/* === Speed Limit Confirmation === */
.speed-confirm-panel {
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 1rem;
}

/* === Modification Disclaimer Banner === */
.modification-banner {
    background-color: #f8d7da;
    border: 2px solid #dc3545;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}
.modification-banner i { color: #dc3545; }

/* === Responsive table for device list === */
@media (max-width: 767px) {
    .table-responsive-cards td {
        display: block;
        text-align: left;
        padding: 0.25rem 0.5rem;
    }
    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        display: inline-block;
        width: 40%;
    }
    .table-responsive-cards thead { display: none; }
    .table-responsive-cards tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        padding: 0.5rem;
    }
}

/* === Create page map (reuses .map-container) === */
#preview-map {
    width: 100%;
    height: 50vh;
    min-height: 400px;
}
@media (min-width: 1200px) {
    #preview-map { height: 55vh; }
}

/* Pin placement toolbar — floats at bottom of map */
.map-pin-toolbar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    border-top: 1px solid #dee2e6;
    padding: 8px 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* === Zone segment tooltips === */
.zone-tooltip {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

/* === Print disclaimer (hidden on screen) === */
.print-disclaimer {
    display: none;
}

/* === Help Panel === */
.help-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    max-width: 90vw;
    height: 100vh;
    background: #1a3a5c;
    color: #e9ecef;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease;
}
.help-panel.open {
    right: 0;
}
.help-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}
.help-panel-header h2 {
    color: #fff;
}
.help-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}
.help-panel-body::-webkit-scrollbar {
    width: 6px;
}
.help-panel-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Help search */
.help-search-wrap .input-group-text {
    color: #adb5bd;
    border-color: rgba(255, 255, 255, 0.2);
}
.help-search-wrap .form-control {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.help-search-wrap .form-control::placeholder {
    color: #adb5bd;
}
.help-search-wrap .form-control:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
    box-shadow: none;
}

/* Help sections */
.help-section {
    margin-bottom: 1.25rem;
}
.help-section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8da4bf;
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
}

/* Topic links */
.help-topic-link {
    display: flex;
    align-items: center;
    padding: 0.625rem 0.75rem;
    color: #d1dbe6;
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.15s ease;
    font-size: 0.9rem;
    min-height: 44px;
}
.help-topic-link:hover, .help-topic-link:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}
.help-topic-link i:first-child {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
    color: #8da4bf;
}
.help-topic-link .fa-chevron-right {
    font-size: 0.65rem;
    color: #6c8fad;
}

/* Topic content */
.help-topic-title {
    color: #fff;
    font-size: 1.15rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.help-content-inner {
    font-size: 0.875rem;
    line-height: 1.65;
}
.help-content-inner h4 {
    color: #b8cfe0;
    font-size: 0.95rem;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}
.help-content-inner p {
    color: #c9d6e2;
}
.help-content-inner ul, .help-content-inner ol {
    padding-left: 1.25rem;
    color: #c9d6e2;
}
.help-content-inner li {
    margin-bottom: 0.35rem;
}
.help-content-inner strong {
    color: #e9ecef;
}
.help-content-inner .table {
    color: #d1dbe6;
    font-size: 0.85rem;
    --bs-table-bg: transparent;
    --bs-table-color: #d1dbe6;
    --bs-table-striped-bg: rgba(255,255,255,0.04);
    --bs-table-striped-color: #d1dbe6;
    border-color: rgba(255, 255, 255, 0.1);
}
.help-content-inner .table th, .help-content-inner .table td {
    border-color: rgba(255, 255, 255, 0.1);
    padding: 0.4rem 0.6rem;
    color: #d1dbe6;
}
.help-content-inner .table strong {
    color: #e9ecef;
}
.help-content-inner .alert {
    font-size: 0.85rem;
}
.help-content-inner code {
    color: #ffc107;
    background: rgba(255, 193, 7, 0.1);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
}

/* Help steps (numbered) */
.help-steps {
    margin: 1rem 0;
}
.help-step {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.help-step-num {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: #0d6efd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    margin-top: 2px;
}
.help-step p {
    margin-bottom: 0;
    font-size: 0.85rem;
}

/* Tip box */
.help-tip {
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 6px;
    padding: 0.75rem;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #f0d68a;
}

/* Example block */
.help-example {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}
.help-example code {
    background: none;
    color: #8dd3c7;
}

/* Accordion in help panel */
.help-content-inner .accordion-item {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}
.help-content-inner .accordion-button {
    background: rgba(255, 255, 255, 0.05);
    color: #d1dbe6;
    font-size: 0.875rem;
    padding: 0.65rem 0.85rem;
}
.help-content-inner .accordion-button:not(.collapsed) {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    box-shadow: none;
}
.help-content-inner .accordion-button::after {
    filter: brightness(0) invert(0.8);
}
.help-content-inner .accordion-body {
    background: rgba(0, 0, 0, 0.1);
    color: #c9d6e2;
    font-size: 0.85rem;
}

/* Backdrop */
.help-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1999;
}

/* Body shift when help is open (desktop only) */
@media (min-width: 992px) {
    .help-backdrop { display: none !important; }
}

/* Help trigger button in navbar */
.help-trigger-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 6px;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    cursor: pointer;
    transition: all 0.15s ease;
}
.help-trigger-btn:hover, .help-trigger-btn:focus-visible {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

/* Breadcrumb back button */
.help-breadcrumb .btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: #b8cfe0;
    font-size: 0.8rem;
}
.help-breadcrumb .btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Contextual help buttons ("?" next to section headers) */
.help-context-btn {
    opacity: 0.6;
    font-size: 1rem;
    line-height: 1;
    min-height: auto;
}
.help-context-btn:hover, .help-context-btn:focus-visible {
    opacity: 1;
}

/* === Print styles === */
@media print {
    /* Hide help panel in print */
    .help-panel, .help-backdrop, .help-trigger-btn { display: none !important; }
    /* Hide non-essential UI */
    .navbar, .footer, .btn, .skip-link, .map-legend,
    .map-mode-badge, .map-pin-toolbar, nav[aria-label="Plan actions"],
    .modification-banner, .badge, .modal, .modal-backdrop { display: none !important; }

    body { background: #fff; margin-bottom: 0; font-size: 10px; color: #000; }
    .container-fluid { padding: 0 !important; }

    /* Hide the interactive Leaflet map — tiles won't render in print */
    .map-container { display: none !important; }

    /* Show the map overview capture as page 2 */
    .print-map-container {
        display: flex !important;
        flex-direction: column;
        width: 100%;
        height: 100vh;
        border: none;
        margin: 0;
        padding: 0;
        page-break-after: always;
    }
    .print-map-header {
        font-size: 12px;
        font-weight: 600;
        text-align: center;
        padding: 6px 0 4px;
        border-bottom: 2px solid #333;
        flex-shrink: 0;
    }
    .print-map-container img {
        width: 100%;
        flex: 1;
        min-height: 0;
        object-fit: fill;
        display: block;
    }

    /* Show the Traffic Control Layout SVG — full first page for field crews */
    .print-layout-container {
        display: flex !important;
        flex-direction: column;
        width: 100%;
        height: 100vh;
        border: none;
        margin: 0;
        padding: 0;
        page-break-after: always;
    }
    .print-layout-header {
        font-size: 12px;
        font-weight: 600;
        text-align: center;
        padding: 6px 0 4px;
        border-bottom: 2px solid #333;
        flex-shrink: 0;
    }
    .print-layout-container svg {
        width: 100% !important;
        height: auto !important;
        max-height: 90vh;
        flex: 1;
        display: block;
    }

    .print-legend {
        background: #f8f9fa;
        border-top: 1px solid #999;
        padding: 4px 10px;
        font-size: 9px;
        text-align: center;
        flex-shrink: 0;
    }
    .print-legend span { margin: 0 8px; white-space: nowrap; }
    .legend-swatch {
        display: inline-block;
        width: 16px;
        height: 4px;
        border-radius: 2px;
        vertical-align: middle;
        margin-right: 3px;
    }

    /* Hide the on-screen field guide (already printed via print-layout-container) */
    .field-guide-container { display: none !important; }

    /* Hide icons in print — text only */
    i.fa-solid, i.fa-regular, i.fas, i.far { display: none !important; }

    /* Headings */
    h1 { font-size: 14px; margin-bottom: 4px !important; }
    h2 { font-size: 11px; margin-bottom: 2px !important; }

    /* Compact tables */
    .table { font-size: 9px; border-collapse: collapse; }
    .table th, .table td { padding: 1px 4px !important; border: 1px solid #999 !important; }
    .table th { background: #e9ecef !important; font-weight: bold; }
    .table-striped tbody tr:nth-of-type(odd) { background: #f8f9fa !important; }
    .table-warning { background: #fff3cd !important; }

    /* Status column — show text instead of hidden badge */
    .print-status-text { display: inline !important; }

    /* Cards — flatten */
    .card { border: none !important; box-shadow: none !important; }
    .card-body { padding: 0 !important; }
    .card-header { padding: 4px 8px !important; font-size: 10px; }

    /* Force device placements into compact table layout (override mobile card styles) */
    .table-responsive-cards thead { display: table-header-group !important; }
    .table-responsive-cards tr { display: table-row !important; margin: 0 !important; border: none !important; border-radius: 0 !important; padding: 0 !important; }
    .table-responsive-cards td { display: table-cell !important; text-align: left; padding: 1px 4px !important; }
    .table-responsive-cards td::before { display: none !important; }

    /* Keep rows together */
    tr { page-break-inside: avoid; }

    /* Collapse modification detail rows in print */
    .collapse { display: none !important; }

    /* Condense spacing */
    .mb-3, .mb-4, .mb-5 { margin-bottom: 6px !important; }

    /* Disclaimer */
    .print-disclaimer {
        display: block !important;
        border: 2px solid #000;
        padding: 8px 12px;
        margin-top: 12px;
        font-size: 11px;
        text-align: center;
        page-break-inside: avoid;
        background: #fff3cd;
    }
    .print-disclaimer i { display: inline !important; }

    /* Page breaks */
    .page-break-before { page-break-before: always; }

    /* Field guide prints as-is — SVG is vector, no capture needed */
    .field-guide-container { page-break-inside: avoid; }
    .field-guide-container .d-flex { display: block !important; }
    .field-guide-container .badge { display: none !important; }
}

/* === Field Guide View === */
.field-guide-container .card {
    border: 2px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Zoom toolbar */
.fg-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: #f1f3f5;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.8rem;
}
.fg-zoom-label {
    min-width: 3em;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    color: #495057;
}
.fg-toolbar .btn {
    min-height: 30px;
    padding: 2px 8px;
    font-size: 0.75rem;
}

/* Scrollable viewport */
.fg-viewport {
    overflow: auto;
    max-height: 70vh;
    min-height: 300px;
    background: #fdfdfd;
    position: relative;
}
.fg-inner {
    transform-origin: top center;
    margin: 0 auto;
}
.field-guide-svg {
    display: block;
}
.fg-sign {
    cursor: default;
}
.fg-sign:hover rect,
.fg-sign:hover path {
    filter: brightness(1.1);
}
