/* Shared mobile layout. Loaded on every page. Desktop view is not changed. */
html { -webkit-text-size-adjust: 100%; }
img, video, canvas, iframe { max-width: 100%; }

@media (max-width: 768px) {
    html, body { overflow-x: hidden; }
    body { padding-bottom: env(safe-area-inset-bottom); }

    /* Typing in a field must not zoom the page on phones */
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea { font-size: 16px !important; max-width: 100%; }
    input[style*="width:"], select[style*="width:"], textarea[style*="width:"] { max-width: 100% !important; }
    button, .btn, a.btn, [role=button] { min-height: 38px; }

    /* Multi-column grids collapse to one column */
    [style*="grid-template-columns:repeat(3,1fr)"], [style*="grid-template-columns: repeat(3, 1fr)"],
    [style*="grid-template-columns:repeat(4,1fr)"], [style*="grid-template-columns:repeat(5,1fr)"],
    .stat-cards-grid { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns:repeat(2,1fr)"], [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
    [style*="min-width:300px"], [style*="minmax(300px"] { min-width: 0 !important; }
    [style*="width:680px"], [style*="width:560px"], [style*="width:480px"], [style*="width:420px"] { width: 100% !important; max-width: 100% !important; }

    /* Cards, headers and bars */
    .dashboard-card { border-radius: 14px; }
    .admin-header, .agent-header { padding-left: 1rem !important; padding-right: 1rem !important; }
    .control-bar, .control-bar-left { flex-direction: column; align-items: stretch !important; width: 100%; }
    .search-input, .page-select { width: 100% !important; min-width: 0 !important; }
    .chart-container { height: 240px !important; }
    .stat-value { font-size: 1.6rem; }
    .tab-nav { padding: .5rem !important; gap: .4rem !important; }
    .tab-btn { font-size: .74rem !important; min-height: 2.5rem !important; }
    .tab-button { font-size: .74rem; padding: .42rem .8rem; }
    .sec-sub { font-size: .76rem; }

    /* Tables become stacked cards: nothing scrolls sideways */
    .overflow-x-auto, [style*="overflow-x:auto"], [style*="overflow:auto"] { overflow-x: visible !important; }
    table.mob-t, table.mob-t tbody, table.mob-t tr, table.mob-t td { display: block; width: 100% !important; min-width: 0 !important; box-sizing: border-box; }
    table.mob-t { table-layout: auto !important; border: 0 !important; }
    table.mob-t thead, table.mob-t colgroup { display: none !important; }
    table.mob-t tr { border: 1px solid #e3edf0; border-radius: 12px; margin: 0 0 .6rem; padding: .35rem .65rem; background: #fff; }
    table.mob-t td { display: flex !important; justify-content: space-between; align-items: flex-start; gap: .8rem; border: 0 !important; padding: .28rem 0 !important; text-align: right !important; white-space: normal !important; overflow: visible !important; text-overflow: clip !important; word-break: break-word; overflow-wrap: anywhere; }
    table.mob-t td::before { content: attr(data-label); font-weight: 700; color: #7a99a8; font-size: .7rem; text-align: left; flex: 0 0 36%; max-width: 36%; }
    table.mob-t td[data-label=""]::before, table.mob-t td[colspan]::before { display: none; }
    table.mob-t td[colspan] { display: block !important; text-align: left !important; }
    table.mob-t td > div, table.mob-t td > span { min-width: 0; }

    /* Dialogs fit the screen */
    #userActionModal > div, #agNotifModal > div { max-width: 96vw !important; margin: .5rem !important; padding: 1.1rem !important; }
    .modal-box { max-width: 94vw !important; }
}

@media (max-width: 480px) {
    .tab-nav { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .header-brand-text, .admin-brand-text { font-size: .85rem !important; }
}

/* ---- extra mobile rules (v2) ---- */
@media (max-width: 768px) {
    .admin-header { height: auto !important; min-height: 56px; flex-wrap: wrap; gap: .5rem; padding: .55rem .8rem !important; }
    .diff-table { min-width: 0 !important; }
    .diff-table th, .diff-table td { padding: .5rem .4rem !important; font-size: .7rem !important; word-break: break-word; }
    h1 { word-break: break-word; }
    a, button { touch-action: manipulation; }
}
