/*
 * Shared responsive layer - admin aur superadmin ke saare pages ke liye.
 * Har page apni <style> ke BAAD yeh file load karta hai, isliye yahan ke
 * rules mobile/tablet par purane styles ko override karte hain.
 * Desktop ka look lagbhag wahi rehta hai, bas thoda polish.
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; height: auto; }

/* ---------- Desktop / sab screens ---------- */
.header { flex-wrap: wrap; gap: 10px; }
.header > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
.btn, button, .back { touch-action: manipulation; }
.btn { display: inline-block; text-align: center; }
.container { width: 100%; }

/* Tables jinke liye card layout nahi hai - sideways scroll ho jayenge */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Tablet ---------- */
@media (max-width: 820px) {
    body { padding: 14px; }
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
    .group-card table { white-space: normal; }
    .container[style], .container { max-width: 100% !important; }
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
    body { padding: 10px; }
    h1 { font-size: 18px !important; }

    /* form wale white box containers */
    .container { padding-left: 16px; padding-right: 16px; }
    .container > .header,
    .container > .back { padding-left: 0; padding-right: 0; }

    /* Form fields: 16px = iPhone par zoom nahi hota, bade tap targets */
    input, select, textarea { font-size: 16px !important; min-height: 44px; }
    textarea { min-height: 90px; }
    input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
    button, .btn { min-height: 44px; font-size: 15px; }
    .btn-small { min-height: 38px; padding: 8px 12px !important; font-size: 13px !important; }

    /* Top buttons ki row: 2 column grid */
    .header { flex-direction: column; align-items: stretch !important; }
    .header > div:last-child { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .header > div:last-child .btn { padding: 12px 8px; font-size: 13px; }
    .header > div:last-child .btn:first-child { grid-column: 1 / -1; }

    /* Message Costs: filter / rates stack */
    .filter > div, .rates > div { flex: 1 1 calc(50% - 8px); }
    .filter input, .rates input { width: 100% !important; }
    .filter button, .rates button { flex: 1 1 100%; }

    /* Message templates: Active toggle header wrap */
    .field-header { flex-wrap: wrap; gap: 6px; }

    /* Teams page */
    .group-title { flex-direction: column; gap: 4px; }
    .row-actions { white-space: normal !important; }
    .row-actions a { display: inline-block; margin: 4px 6px 0 0 !important; }

    /* Chats list / bubbles */
    .chat-time { float: none !important; display: block; margin-bottom: 2px; }
    .bubble { max-width: 88% !important; }

    /* Login boxes */
    .box { width: 100% !important; max-width: 340px; margin: 0 12px; }

    /* ---- Card-style tables (class="stack-table" + td[data-label]) ---- */
    table.stack-table { display: block; overflow: visible; white-space: normal; background: transparent !important; box-shadow: none !important; }
    table.stack-table tbody { display: block; }
    table.stack-table tr:first-child:has(th) { display: none; }
    table.stack-table tr { display: block; background: #fff; border-radius: 10px; margin-bottom: 12px; padding: 6px 14px; box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
    table.stack-table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; padding: 9px 0 !important; border-bottom: 1px solid #f1f1f1 !important; }
    table.stack-table td:last-child { border-bottom: none !important; }
    table.stack-table td[data-label]::before { content: attr(data-label); font-weight: 600; color: #888; font-size: 12px; text-align: left; flex-shrink: 0; }
    table.stack-table td[colspan] { display: block; text-align: center !important; }
    table.stack-table td.actions { flex-wrap: wrap; justify-content: flex-end; }
}

/* Chat view pura-screen layout: mobile browser ki address bar ke saath bhi sahi */
@supports (height: 100dvh) {
    .chat-page { height: 100dvh; }
}
