/*
 * Site-wide responsive layer, loaded last by base.html.
 *
 * Every rule is inside a small-screen media query, so desktop layouts are
 * untouched. Page templates carry their own <style> blocks (loaded after
 * this file), so selectors are prefixed with `body` for enough specificity,
 * and !important is used only where templates set inline styles.
 *
 * Covers the shared building blocks: page headers (Back / title / action
 * button), the .container-fire / .container-plant-m page cards, Bootstrap
 * accordions used by the long forms, card/section headers, Select2 and
 * DataTables, plus media that would otherwise overflow the screen.
 */

/* ---------- Page banners (all widths) ----------
 * Nine pages (pending alerts, control-room pages, submitted/edit lists,
 * create user, gap analysis) draw their banner as `.page-header` straight
 * inside .wrap with position: fixed, centred on the window. It ignored the
 * sidebar (sliding underneath it), and the page compensated with a 100–200px
 * top margin and an inner scroll box under `html, body { overflow: hidden }`.
 * Pages whose header lives inside their own container are not matched.
 * The site navbar is position: fixed, so the banner starts below it;
 * base.html keeps --fw-nav-h set to the navbar's real height (it is shorter
 * on phones and grows when the mobile menu opens). */
body .wrap > .page-header {
    position: relative !important; top: auto !important; left: auto !important; transform: none !important;
    width: auto !important; max-width: none !important;
    margin: calc(var(--fw-nav-h, 72px) + 20px) clamp(12px, 2.5vw, 40px) 18px !important; padding: 18px 24px !important;
    display: flex !important; flex-wrap: wrap; align-items: center; gap: 12px 18px;
    border: 0 !important; border-radius: 20px !important; overflow: hidden; z-index: 1;
    background: linear-gradient(120deg, #e64a19 0%, #f4511e 45%, #fb923c 100%) !important;
    box-shadow: 0 14px 34px rgba(244, 81, 30, 0.28) !important;
}
body .wrap > .page-header::after {
    content: '\f06d'; font-family: 'Font Awesome 5 Free'; font-weight: 900; position: absolute; right: 24px; top: 50%;
    transform: translateY(-50%) rotate(-8deg); font-size: 96px; color: rgba(255, 255, 255, 0.12); pointer-events: none;
}
body .wrap > .page-header > * { position: relative; z-index: 1; }
body .wrap > .page-header .page-title {
    flex: 1 1 auto; margin: 0 !important; text-align: center !important; color: #fff !important;
    font-size: clamp(20px, 2.4vw, 28px) !important; font-weight: 800 !important; letter-spacing: -0.01em;
    display: flex; align-items: center; justify-content: center; gap: 12px; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}
/* Title centred on the banner itself, not in the space left over by the
   Back button: three columns, Back on the left, title in the middle, and
   any action button on the right. Phones stack instead (see below). */
@media (min-width: 768px) {
    body .wrap > .page-header { display: grid !important; grid-template-columns: 1fr minmax(0, max-content) 1fr; }
    body .wrap > .page-header > * { grid-row: 1; grid-column: 3; justify-self: end; }
    body .wrap > .page-header > .back-button,
    body .wrap > .page-header > .button-group { grid-column: 1; justify-self: start; }
    body .wrap > .page-header > .page-title { grid-column: 2; justify-self: center; }
    /* Pages that wrap Back + title in their own row already centre the title */
    body .wrap > .page-header > .header-top-row { grid-column: 1 / -1; justify-self: stretch; }
}
body .wrap > .page-header .page-title > i:first-child {
    width: 44px; height: 44px; flex: none; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.2); font-size: 20px;
}
body .wrap > .page-header .back-button {
    height: 42px; padding: 0 16px !important; border-radius: 12px !important; display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255, 255, 255, 0.18) !important; border: 1px solid rgba(255, 255, 255, 0.5) !important; color: #fff !important;
    box-shadow: none !important; font-weight: 700; text-decoration: none !important; backdrop-filter: blur(4px);
}
body .wrap > .page-header .back-button:hover { background: rgba(255, 255, 255, 0.3) !important; transform: none; }
/* Undo the space these pages reserved for the fixed banner */
body .wrap > .page-header ~ .content-wrapper,
body .wrap > .page-header ~ .container-report,
body .wrap > .page-header ~ .container-create { margin-top: 0 !important; max-height: none !important; overflow: visible !important; }
html:has(.wrap > .page-header), body:has(.wrap > .page-header) { height: auto !important; overflow: auto !important; }

/* ---------- Tablets and small laptops ---------- */
@media (max-width: 991.98px) {
    /* Map libraries draw on canvas and manage their own tile images */
    body img:not(.leaflet-tile):not(.ol-image), body video, body iframe { max-width: 100%; }
    body .page-header .page-title { font-size: clamp(20px, 3.4vw, 28px); }
    body .page-header .d-flex.justify-content-between,
    body .card-header,
    body .section-header { flex-wrap: wrap; gap: 10px; }
    body .select2-container { max-width: 100%; }
    body .dataTables_wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---------- Phones ---------- */
@media (max-width: 767.98px) {
    /* Nested Bootstrap containers + page cards each added side padding,
       leaving forms a narrow strip in the middle of the phone. */
    body .container.my-5 { margin-top: 12px !important; margin-bottom: 12px !important; }
    body .container-fire,
    body .container-plant-m { padding: 12px !important; margin-left: 0 !important; margin-right: 0 !important;
        border-radius: 14px; max-width: 100%; }
    body .container-fire .container,
    body .container-plant-m .container,
    body .page-header .container { padding-left: 0; padding-right: 0; }

    /* Page header: title on its own row, Back and the action button
       side by side underneath, instead of three squeezed columns. */
    body .page-header { padding: 14px !important; border-radius: 14px; }
    body .page-header .d-flex.justify-content-between { flex-wrap: wrap; gap: 10px; }
    body .page-header .page-title { order: -1; flex: 1 1 100%; margin: 0 0 2px !important;
        font-size: 22px !important; line-height: 1.25; text-align: center; }
    body .page-header .back-button,
    body .page-header .save-button,
    body .page-header .btn { flex: 1 1 0; min-width: 0; min-height: 44px; display: inline-flex;
        align-items: center; justify-content: center; gap: 6px; white-space: nowrap; font-size: 14px; }

    /* Accordion section bars on the long forms */
    body .accordion-button { padding: 12px 14px !important; font-size: 15px; text-align: left; line-height: 1.3; }
    body .accordion-button .svg-icon,
    body .accordion-button img { width: 30px; height: 30px; margin-right: 10px !important; flex: none; }
    body .accordion-body { padding: 14px 12px !important; }

    /* Form fields: full width and comfortable to tap */
    body .form-control,
    body .form-select { min-height: 44px; font-size: 15px; }
    body .select2-container { width: 100% !important; }
    body .select2-container .select2-selection--single { min-height: 44px; display: flex; align-items: center; }
    body label { overflow-wrap: anywhere; }

    /* Rows of buttons wrap instead of running off the screen */
    body .action-buttons,
    body .form-actions,
    body .btn-group-responsive { display: flex; flex-wrap: wrap; gap: 10px; }
    body .action-buttons > .btn,
    body .form-actions > .btn { flex: 1 1 140px; }

    /* Wide tables scroll inside their card rather than widening the page */
    body .table-responsive,
    body .dataTables_wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    body .dataTables_wrapper .dataTables_filter,
    body .dataTables_wrapper .dataTables_length { float: none; text-align: left; margin-bottom: 8px; }
    body .dataTables_wrapper .dataTables_filter input { width: 100%; margin-left: 0; }

    /* Modals use nearly the full screen */
    body .modal-dialog { margin: 10px; }

    /* Banner on phones: compact, title first, Back underneath */
    body .wrap > .page-header { margin: calc(var(--fw-nav-h, 60px) + 12px) 10px 14px !important; padding: 14px 16px !important; border-radius: 16px !important; }
    body .wrap > .page-header::after { font-size: 64px; right: 10px; }
    body .wrap > .page-header { justify-content: center; }
    body .wrap > .page-header .page-title { justify-content: center; text-align: center !important; font-size: 19px !important; }
    body .wrap > .page-header .page-title > i:first-child { width: 36px; height: 36px; font-size: 16px; border-radius: 11px; }
    body .wrap > .page-header .back-button { flex: 0 0 auto; height: 38px; }
}

/* ---------- Narrow phones ---------- */
@media (max-width: 575.98px) {
    /* The grey sub-title next to accordion titles ("Preliminary Information")
       crowds the bar at this width; the section title alone is enough. */
    body .accordion-button .text-muted { display: none; }
    body .page-header .page-title { font-size: 20px !important; }
    body h1 { font-size: 22px; }
    body h2 { font-size: 19px; }
}
