/* content/css/responsive.css
   Mobile layout pass. Loaded after every other stylesheet so these
   rules win by source order. Target viewport: 360px - 768px.
   ------------------------------------------------------------------ */

@media (max-width: 768px) {

    /* ---- Page shell ---- */
    body .main { padding: 16px 12px; }

    .cart-header { gap: 12px; margin-bottom: 16px; }
    .cart-header .cart-title { font-size: 1.05rem; }
    .form-btn-wrap { width: 100%; }
    .form-btn-wrap .form-back-btn,
    .cart-header .form-btn-wrap button { flex: 1 1 auto; justify-content: center; }

    /* ---- Topbar / ticker ---- */
    .nav-topbar { gap: 10px; padding: 0 14px; }
    .nav-topbar .nav-breadcrumb .nav-path { display: none; }
    .nav-topbar .nav-title {
        font-size: .9rem;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .nav-topbar .nav-user-name { display: none; }
    .nav-topbar .nav-user { padding: 4px; }
    .nav-topbar .nav-user .user-chevron { display: none; }
    .nav-dropdown .nav-dropdown-menu.user { width: 210px; }
    .nav-ticker { padding: 0 14px; }

    /* ---- Stat cards ---- */
    .stats-row { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
    .stat-card { padding: 14px; gap: 10px; }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 1rem; }
    .stat-card .stat-value { font-size: 1.1rem; }

    /* ---- Cart / checkout / summary ---- */
    .cart-wrap { gap: 16px; }
    .cart-wrap .cart-card:not(:last-child) { margin-bottom: 14px; }
    .cart-wrap .cart-summary { position: static; top: auto; }
    .cart-wrap .cart-summary-header {
        padding: 14px 16px; gap: 12px; font-size: .9rem; flex-wrap: wrap;
    }
    .cart-wrap .cart-summary-body { padding: 16px; }

    /* Order No status block (ordersRead.php / ordersItems.php) ->
       icon centered above the title/sub, stacked with a gap */
    .cart-wrap .cart-summary-status {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
        padding: 20px 16px;
    }

    /* Customer & Delivery Info (ordersRead.php) -> label above value,
       stacked with a gap. Scoped to .customer-info-body only, so the
       Order Summary sidebar's identical .cart-summary-row is untouched. */
    .cart-wrap .customer-info-body .cart-summary-row {
        flex-direction: column;
        gap: 4px;
    }
    .cart-wrap .customer-info-body .cart-summary-row span:first-child {
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--color-text-muted);
    }

    /* Cart line item -> wraps to two rows */
    .cart-wrap .cart-items { flex-wrap: wrap; gap: 10px 12px; padding: 14px 16px; }
    .cart-wrap .cart-items-thumb { width: 52px; height: 52px; font-size: 1.2rem; }
    .cart-wrap .cart-items-info { flex: 1 1 auto; min-width: 130px; }
    .cart-wrap .cart-items-subtotal {
        width: auto; margin-left: auto; align-self: center; font-size: .9rem;
    }

    /* Step indicator */
    .cart-steps { gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
    .cart-steps .cart-step-row { font-size: .74rem; }
    .cart-steps .cart-step-divider { width: 16px; }

    /* Payment method picker */
    .form-group .pick-row.col-4,
    .form-group .pick-row.col-3 { grid-template-columns: repeat(2, 1fr); }

    /* ---- Forms ---- */
    .cart-wrap.reset-wrap { grid-template-columns: 1fr; }
    .fill-button { margin-left: auto; }

    /* ---- Order items tables (ordersRead.php / ordersItems.php) ----
       Both pages have their own inline <style> block emitted after this
       stylesheet's <link>, so same-specificity selectors here would lose
       the cascade to it (same issue as the dashboard rows). Doubling the
       class keeps these rules winning regardless of source order.
       Every column stacks into its own full-width row, per item. The
       Order No header (.cart-summary-status) and the calculation summary
       sidebar (.cart-summary) are untouched - only these item tables change. */
    .order-items-table.order-items-table thead,
    .edit-items-table.edit-items-table thead { display: none; }
    .order-items-table.order-items-table tbody,
    .edit-items-table.edit-items-table tbody { display: block; width: 100%; }
    .order-items-table.order-items-table tr,
    .edit-items-table.edit-items-table tr {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
        box-sizing: border-box;
        padding: 14px 8px;
        border-bottom: 1px solid var(--color-border, #f2f2f2);
    }
    .order-items-table.order-items-table tr:last-child,
    .edit-items-table.edit-items-table tr:last-child {
        border-bottom: none;
    }
    .order-items-table.order-items-table td,
    .edit-items-table.edit-items-table td,
    .order-items-table.order-items-table td.num,
    .edit-items-table.edit-items-table td.num {
        display: block;
        width: 100%;
        box-sizing: border-box;
        padding: 0;
        border-bottom: none;
        text-align: left;
        vertical-align: top;
    }
    /* Description/remark cell (no data-label) -> extra breathing room
       below it, separating it from the Price/Qty/Subtotal rows */
    .order-items-table.order-items-table td:not([data-label]),
    .edit-items-table.edit-items-table td:not([data-label]) {
        margin-bottom: 8px;
    }

    /* Price / Qty / Subtotal / UOM -> title on the left, content on the
       right, space-between on one line (e.g. "UOM        BOX") */
    .order-items-table.order-items-table td[data-label],
    .edit-items-table.edit-items-table td[data-label] {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
    .order-items-table.order-items-table td[data-label]::before,
    .edit-items-table.edit-items-table td[data-label]::before {
        content: attr(data-label);
        font-weight: 700;
        color: var(--color-text-sub);
    }
    /* Qty's input + "/ cap" hint are wrapped in .edit-qty-wrap so they
       act as one flex item - the value side of the label/value row */
    .edit-items-table.edit-items-table td .edit-qty-wrap {
        display: flex;
        align-items: center;
        gap: 4px;
    }
    .edit-items-table.edit-items-table td .edit-qty { width: 60px; }

    /* ---- Data table ---- */
    .card-table .card-header { padding: 14px 14px 12px; }
    .card-table .card-header-title { font-size: .92rem; }
    .card-table .card-toolbox { padding: 10px 14px; gap: 6px; }
    .card-table .card-toolbox-divider { display: none; }
    .card-table .card-search-wrap { flex: 1 1 100%; }
    .card-table .card-tabs-wrap { width: 100%; }
    .card-table .card-select-option { flex: 1 1 100%; min-width: 0; }
    .card-table .card-table-wrap { max-height: none; }
    .card-table table td { padding: 12px; }
    .card-table table thead th { padding: 11px 12px; }
    .card-table .card-paginations { padding: 12px 14px; justify-content: center; }
    .card-table .card-pag-word { width: 100%; justify-content: center; }
    .card-table .card-pag-btn { width: 100%; justify-content: center; flex-wrap: wrap; }

    /* Product grid mode */
    .card-grid-wrap { grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; }

    /* ---- Dashboard ----
       dashboard.php has its own inline <style> block that is emitted
       after this stylesheet's <link>, so same-specificity selectors
       here would lose the cascade to it. Doubling the class keeps
       these rules winning regardless of source order. */
    .dash-panel.dash-panel { border-radius: 16px; overflow: hidden; }
    .dash-panel-header.dash-panel-header { padding: 14px 16px; font-size: .88rem; }
    .dash-chart-body.dash-chart-body { padding: 12px; overflow: hidden; }
    .dash-chart-body.dash-chart-body .apexcharts-canvas,
    .dash-chart-body.dash-chart-body svg { max-width: 100%; }

    /* Recent Orders / Low Stock rows -> every piece of data (icon,
       title, date, status, amount, action) stacks in its own line,
       left-aligned, full row width so nothing exceeds device width */
    .dash-row.dash-row {
        flex-direction: column;
        align-items: flex-start;
        padding: 14px 16px;
        gap: 6px;
        width: 100%;
        box-sizing: border-box;
    }
    .dash-row-icon.dash-row-icon { display: none; }
    .dash-row-main.dash-row-main { flex: 0 0 auto; width: 100%; min-width: 0; }
    .dash-row-title.dash-row-title { white-space: normal; overflow-wrap: anywhere; }
    .dash-row-sub.dash-row-sub { overflow-wrap: anywhere; }
    .dash-row .dash-badge.dash-badge,
    .dash-row .dash-row-amount.dash-row-amount,
    .dash-row .dash-row-action.dash-row-action {
        margin-left: 0;
    }

    .dash-memo-fab { right: 16px; bottom: 16px; width: 50px; height: 50px; font-size: 1.15rem; }

    /* ---- Receipt / confirm ---- */
    .rcpt-page, .cfm-page { padding: 20px 12px 32px; }
    .rcpt-card, .cfm-card { padding: 24px 18px 22px; }

    /* ---- Modals ---- */
    .ns-modal .ns-box { max-width: 92vw; padding: 1.5rem; }
    .ns-modal.memo-modal .ns-box { max-width: 94vw; }
    .ns-modal .ns-action-wrap { flex-wrap: wrap; }
    .ns-modal .ns-action-wrap button { flex: 1 1 auto; }

    /* ---- Login / uploader / verify ---- */
    .login-section { min-height: 70vh; padding: 24px 14px; }
    .login-section .login-card { padding: 32px 22px; }

    /* ---- Editor pages ---- */
    .profile-head { padding: 18px; gap: 12px; }
    .product-image-wrap { padding: 16px; }
}

/* ---- Smallest phones (~360px) ---- */
@media (max-width: 400px) {
    .stats-row { grid-template-columns: 1fr; }
    .card-grid-wrap { grid-template-columns: 1fr; }
    .cart-steps .cart-step-row .num { width: 20px; height: 20px; font-size: .7rem; }
    .form-btn-wrap .form-back-btn { font-size: .74rem; padding: 9px 10px; }
    .cart-wrap .cart-items-info { flex: 1 1 100%; }
}

/* ---- Signboard (top-bar ticker, content/nav.php) ---- */
@media (max-width: 768px) {
    /* .main margin-top and the ticker height both read this, so the page stays aligned */
    :root { --nav-ticker-height: 30px; }
    body .nav-ticker { gap: 8px; padding: 0 12px; }
    body .nav-ticker .nav-ticker-icon { width: 22px; height: 22px; font-size: .78rem; }
    body .nav-ticker .nav-ticker-content span { padding: 0 18px; font-size: .74rem; }
    body .nav-ticker .nav-ticker-content span:not(:last-child)::after { right: 4px; }
    /* fade the edge so text doesn't cut off hard against the icon / screen edge */
    body .nav-ticker .nav-ticker-track {
        -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
                mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
    }
    /* touch has no hover: press and hold to pause and read */
    body .nav-ticker:active .nav-ticker-loop { animation-play-state: paused; }
}
@media (max-width: 400px) {
    :root { --nav-ticker-height: 28px; }
    body .nav-ticker { padding: 0 10px; gap: 6px; }
    body .nav-ticker .nav-ticker-content span { padding: 0 14px; font-size: .7rem; }
}
/* motion-sensitive users: no auto-scroll, swipe the bar instead */
@media (prefers-reduced-motion: reduce) {
    body .nav-ticker .nav-ticker-track { overflow-x: auto; scrollbar-width: none; }
    body .nav-ticker .nav-ticker-track::-webkit-scrollbar { display: none; }
    body .nav-ticker .nav-ticker-loop { animation: none; }
}
