/* =================================================================
   YZ OTS Portal — global mobile-first responsive helpers
   Loaded by _Layout.cshtml. Safe baseline rules for all pages,
   including those with Layout=null that import this file explicitly.
   ================================================================= */

/* ── Base mobile friendly defaults ─────────────────────────────── */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    /* `hidden` on its own makes <body> a scroll container, which silently kills
       `position: sticky` on every descendant — including the .side-nav rail this
       file pins at >=992px, and every .ta-side-nav. `clip` contains horizontal
       overflow WITHOUT creating a scroll container, so sticky survives.
       The `hidden` line stays first as a fallback: a browser without `clip`
       keeps today's behaviour rather than reverting to a page-wide scroller. */
    overflow-x: hidden;
    overflow-x: clip;
}

/* Ensure images and embedded maps never overflow their containers */
img, video, iframe, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* ── Tables: horizontal scroll instead of squashing ────────────── */
/* Wrapper names here are the ones markup actually uses — `grep -rhoE
   'class="[^"]*(wrap|scroll)[^"]*"' Pages/` puts .tbl-wrap (150) and
   .tbl-scroll (138) far ahead, with a long tail of per-module names
   (.slo-tablewrap, .bc-tablewrap, .ca-table-wrap, .sr-table-wrap,
   .pa-table-wrap, .sp-grid-scroll, .table-wrapper). Only some are styled by
   distribution-design.css, and Layout=null pages never load that file, so the
   scrolling guarantee has to live in this baseline.

   These are added to the SCROLLER list only, deliberately not to the
   min-width/white-space list below: forcing `white-space: nowrap` onto every
   table inside .tbl-scroll would change desktop rendering across ~138 pages,
   whereas granting overflow-x can only help. */
.table-responsive,
.table-wrap,
.tbl-wrap,
.tbl-scroll,
.table-wrapper,
.slo-tablewrap,
.bc-tablewrap,
.ca-table-wrap,
.sr-table-wrap,
.pa-table-wrap,
.sp-grid-scroll,
.data-wrap,
.panel-body > table,
.dash-main > table,
form > table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table,
.table-wrap table,
.data-wrap table,
.panel-body > table,
.dash-main > table,
form > table {
    width: 100%;
    min-width: 560px; /* keeps columns readable; horizontal scroll on tiny screens */
    white-space: nowrap;
}

/* Make table cells more touch-friendly on small screens */
@media (max-width: 768px) {
    table th,
    table td {
        padding: 8px 10px !important;
        font-size: 0.82rem !important;
    }
}

/* ── Forms: stack columns on narrow screens ────────────────────── */
.fgrid,
.fgrid-2,
.fgrid-3,
.fgrid-4,
.fgrid-5,
.form-row,
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

@media (min-width: 576px) {
    .fgrid-2 { grid-template-columns: repeat(2, 1fr); }
    .fgrid-3 { grid-template-columns: repeat(2, 1fr); }
    .fgrid-4 { grid-template-columns: repeat(2, 1fr); }
    .fgrid-5 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 992px) {
    .fgrid-3 { grid-template-columns: repeat(3, 1fr); }
    .fgrid-4 { grid-template-columns: repeat(4, 1fr); }
    .fgrid-5 { grid-template-columns: repeat(5, 1fr); }
}

/* Ensure form inputs are easy to tap */
input, select, textarea, button, .btn, a.btn {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 44px;
}

@media (min-width: 768px) {
    input, select, textarea, button, .btn, a.btn {
        font-size: inherit;
    }
}

/* ── Dashboard shells and sidebars ─────────────────────────────── */
.dash-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.side-nav,
.sidebar-panel,
.left-rail,
.right-rail {
    width: 100%;
    height: auto;
    position: relative;
    order: 0;
}

.dash-main {
    padding: 16px;
    overflow-x: hidden;
    flex: 1;
}

@media (min-width: 992px) {
    .dash-shell {
        display: grid;
        grid-template-columns: 64px 1fr;
    }

    .dash-shell.has-sidebar {
        grid-template-columns: 64px 260px 1fr;
    }

    .side-nav,
    .sidebar-panel,
    .left-rail {
        position: sticky;
        top: 0;
        height: 100vh;
        width: auto;
    }

    .dash-main {
        padding: 28px 36px;
    }
}

/* ── KPI/stat strips ───────────────────────────────────────────── */
.kpi-strip,
.stats-row,
.kpi-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 576px) {
    .kpi-strip,
    .stats-row,
    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 992px) {
    .kpi-strip,
    .stats-row,
    .kpi-row {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ── Panels / cards ─────────────────────────────────────────────── */
.panel,
.card {
    border-radius: 12px;
    margin-bottom: 16px;
}

.panel-head,
.card-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
}

.panel-body,
.card-body {
    padding: 16px;
}

@media (min-width: 768px) {
    .panel-body,
    .card-body {
        padding: 22px;
    }
}

/* ── Buttons and action rows ───────────────────────────────────── */
.btn-row,
.action-row,
.panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn,
button,
a.btn {
    min-height: 44px;
    padding: 10px 16px;
    align-items: center;
    justify-content: center;
}

/* ── Map frames ──────────────────────────────────────────────────── */
.yz-map-frame,
.map-frame,
[id$="-map"],
#map,
#dist-map,
#fleet-map,
#route-map,
#profile-map {
    width: 100% !important;
    min-height: 320px !important;
    height: min(600px, 60vh) !important;
    border-radius: 12px;
}

@media (min-width: 768px) {
    .yz-map-frame,
    .map-frame,
    [id$="-map"],
    #map,
    #dist-map,
    #fleet-map,
    #route-map,
    #profile-map {
        min-height: 420px !important;
        height: min(800px, calc(100vh - 200px)) !important;
    }
}

/* Map controls need to be easy to tap on touch */
.yz-map-ctrl-btn,
.mapboxgl-ctrl button,
.leaflet-control-zoom a {
    width: 40px !important;
    height: 40px !important;
    font-size: 1rem !important;
}

/* ── Pagination bars ───────────────────────────────────────────── */
.pgn-bar,
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 14px;
}

.pgn-info {
    width: 100%;
    text-align: center;
    font-size: 0.78rem;
}

/* ── Utility helpers ─────────────────────────────────────────────── */
.hide-mobile { display: none !important; }
@media (min-width: 768px) {
    /* `initial` resolves to `inline`, not the element's own display, so any
       .hide-mobile that was block/flex collapsed on desktop. `revert` restores
       the value the cascade would have given it. */
    .hide-mobile { display: revert !important; }
    .hide-desktop { display: none !important; }
}

.text-center-mobile { text-align: center; }
@media (min-width: 768px) {
    .text-center-mobile { text-align: inherit; }
}

.stack-mobile { display: flex; flex-direction: column; }
@media (min-width: 768px) {
    .stack-mobile { flex-direction: row; }
}
