/* ============================================================
   MTMS — Mobile & responsive refinements
   Loaded after site.css so these rules win where they overlap.
   ============================================================ */

/* Never let a wide element force horizontal page scrolling on a phone */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Comfortable tap targets everywhere (Apple/Google guidance is 44px) */
@media (max-width: 991.98px) {
    .btn,
    .form-control,
    .form-select,
    .nav-link {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
    }

    /* Stop iOS from zooming when a field is focused (needs >= 16px) */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px;
    }
}

/* ============================================================
   Header / layout
   ============================================================ */
@media (max-width: 767.98px) {
    .mtms-content {
        padding: 0.85rem;
    }

    .mtms-header {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .page-title h1 {
        font-size: 1.05rem;
        line-height: 1.3;
        max-width: 52vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mtms-footer {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        font-size: 0.8rem;
    }

    /* Notification dropdown should not overflow the viewport */
    .notifications-dropdown {
        width: calc(100vw - 1.5rem);
        max-width: 340px;
    }

    h2 {
        font-size: 1.4rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }
}

/* ============================================================
   Tables → stacked cards on small screens
   Add class="table-stack" to a table and data-label="Column" to
   each <td>; on phones each row becomes a readable card.
   ============================================================ */
@media (max-width: 767.98px) {
    .table-stack thead {
        display: none;
    }

    .table-stack,
    .table-stack tbody,
    .table-stack tr,
    .table-stack td {
        display: block;
        width: 100%;
    }

    .table-stack tr {
        border: 1px solid #e9ecef;
        border-radius: 12px;
        margin-bottom: 0.75rem;
        padding: 0.5rem 0.25rem;
        background: #fff;
        box-shadow: 0 1px 4px rgba(16, 24, 40, 0.04);
    }

    .table-stack td {
        border: none !important;
        padding: 0.4rem 0.85rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        text-align: right;
    }

    /* Column name shown on the left of each stacked cell */
    .table-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        color: #6b7280;
        text-align: left;
        flex-shrink: 0;
    }

    /* Cells with no label (action columns) get the full width */
    .table-stack td[data-label=""]::before,
    .table-stack td:not([data-label])::before {
        content: "";
    }

    .table-stack td[data-label=""],
    .table-stack td:not([data-label]) {
        justify-content: flex-end;
    }

    /* A "no results" row should stay a normal full-width block */
    .table-stack td[colspan] {
        display: block;
        text-align: center;
    }

    .table-stack td[colspan]::before {
        content: "";
    }

    /* Inline forms inside action cells wrap instead of overflowing */
    .table-stack td form {
        flex-wrap: wrap;
        justify-content: flex-end;
    }
}

/* Tables that are NOT stacked still scroll rather than break the layout */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Stat cards / dashboards
   ============================================================ */
@media (max-width: 575.98px) {
    .stat-card {
        padding: 0.85rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Two stat tiles per row instead of one giant column */
    .row.g-3 > [class*="col-6"],
    .row.g-4 > [class*="col-6"] {
        padding-left: 0.4rem;
        padding-right: 0.4rem;
    }
}

/* ============================================================
   Forms & buttons
   ============================================================ */
@media (max-width: 575.98px) {
    /* Button groups in page headers go full width and stack */
    .d-flex.gap-2.flex-wrap > .btn,
    .d-flex.gap-3.flex-wrap > .btn {
        flex: 1 1 auto;
    }

    .card-footer .btn,
    form > .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .card-footer .btn:last-child,
    form > .btn:last-child {
        margin-bottom: 0;
    }

    dl.row dt,
    dl.row dd {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Long values (emails, codes) wrap instead of overflowing */
    .text-break,
    dd {
        overflow-wrap: anywhere;
    }
}

/* ============================================================
   Public pages (home, signup, login)
   ============================================================ */
@media (max-width: 767.98px) {
    .hero-section {
        min-height: auto;
        padding: 90px 0 70px;
    }

    .hero-section h1,
    .display-4 {
        font-size: 1.85rem;
    }

    .btn-hero {
        width: 100%;
        padding: 13px 20px;
        font-size: 1rem;
    }

    .signup-container,
    .login-card {
        margin-top: -40px;
    }

    .signup-hero {
        padding: 36px 0 76px;
    }

    .contact-card,
    .demo-section {
        padding: 22px !important;
    }

    .pricing-card {
        padding: 26px 20px;
    }

    .section-title {
        margin-top: 26px;
    }

    .plan-card,
    .pay-card {
        padding: 18px;
    }

    .summary-box {
        padding: 14px 16px;
    }
}

/* Print: hide navigation chrome so reports print cleanly */
@media print {
    .mtms-topnav,
    .mtms-header,
    .mtms-footer,
    .mtms-offcanvas,
    .btn {
        display: none !important;
    }

    .mtms-main,
    .mtms-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .card,
    .panel {
        border: 1px solid #ddd !important;
        box-shadow: none !important;
        break-inside: avoid;
    }
}

/* ============================================================
   Horizontal top navigation - responsive
   ============================================================ */
@media (max-width: 991.98px) {
    .topnav-inner {
        padding: 0.5rem 0.85rem;
    }

    .topnav-right .notifications-dropdown {
        width: calc(100vw - 1.5rem);
        max-width: 340px;
    }
}

@media (min-width: 992px) and (max-width: 1199.98px) {
    .topnav-link span {
        display: none;
    }

    .topnav-link i {
        font-size: 1.15rem;
    }

    .topnav-link.dropdown-toggle::after {
        margin-left: 0.15rem;
    }
}

/* ============================================================
   Live trip / in-progress indicator + map trigger
   ============================================================ */
@media (max-width: 575.98px) {
    .trip-card .trip-view-map {
        font-size: 0.75rem;
    }

    .live-map-modal .modal-dialog {
        margin: 0.5rem;
    }

    .live-map-container {
        height: 55vh !important;
    }
}
