/* ===================================================================
   admin-responsive.css – Design-system utilities & mobile adaptations
   Breakpoints:
     Mobile  : <= 768px
     Tablet  : 769–1024px
     Desktop : > 1024px
   =================================================================== */

/* ── Global overflow guard ── */
html, body, .shell, .main-area {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ── Utility classes ── */
.hide-mobile   { display: revert; }
.show-mobile   { display: none !important; }
.no-scroll-x   { overflow-x: hidden !important; }

@media (max-width: 768px) {
    .hide-mobile   { display: none !important; }
    .show-mobile   { display: revert !important; }
    .stack-mobile  { flex-direction: column !important; }
    .wrap-mobile   { flex-wrap: wrap !important; }
}

/* ── Mobile card helpers (table→card conversion) ── */
.mobile-card {
    background: var(--surface);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: .875rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}

.mobile-card-primary {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.mobile-card-secondary {
    font-size: .78rem;
    color: var(--muted);
}

.mobile-card-actions {
    display: flex;
    gap: .5rem;
    flex-shrink: 0;
}

.mobile-card-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px;
    transition: opacity .2s;
}

.mobile-card-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Expand / collapse details */
.mobile-card-details {
    display: none;
    flex-direction: column;
    gap: .35rem;
    padding-top: .5rem;
    border-top: 1px solid var(--stroke);
    animation: slideDown .2s ease;
}

.mobile-card-details.expanded {
    display: flex;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.mobile-card-detail-row {
    display: flex;
    justify-content: space-between;
    font-size: .78rem;
}

.mobile-card-detail-row .label {
    color: var(--muted);
    white-space: nowrap;
}

.mobile-card-detail-row .value {
    color: var(--text);
    text-align: right;
    word-break: break-all;
}

.expand-toggle {
    background: none;
    border: none;
    color: var(--primary);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color .2s;
}

.expand-toggle:hover {
    color: var(--text);
}

.expand-toggle i {
    transition: transform .2s;
}

.expand-toggle.open i {
    transform: rotate(180deg);
}

/* ── Mobile filter drawer ── */
.filter-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 100;
    animation: fadeIn .2s ease;
}

.filter-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--stroke);
    border-radius: 16px 16px 0 0;
    padding: 1.25rem 1rem 1.5rem;
    z-index: 101;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp .25s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.filter-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.filter-drawer-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.filter-drawer-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.25rem;
    cursor: pointer;
}

/* ── Editor layout mobile (RCF / APP) ── */
/*
   Mobile: preview fixed at top, form scrolls below.
   Uses flex column with contained scroll to prevent layout shift ("samba").
   --admin-top-offset accounts for NavHeader height + content padding.
*/
@media (max-width: 768px) {
    .editor-layout {
        display: flex !important;
        flex-direction: column;
        grid-template-columns: unset !important;
        height: calc(100dvh - var(--admin-top-offset, 100px));
        gap: 0;
        overflow: hidden;
    }

    /* Save button – visually first on mobile */
    .editor-mobile-save {
        order: -2;
        flex: 0 0 auto;
        padding: .5rem 0;
        z-index: 21;
    }

    /* Phone preview – fixed below save, never moves */
    .phone-preview-sticky {
        order: -1;
        flex: 0 0 auto;
        position: static !important;
        max-height: 42vh;
        max-width: 420px;
        margin: 0 auto;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        overflow: hidden;
        z-index: 20;
    }

    .phone-preview-sticky .phone-shell {
        width: min(280px, calc(100vw - 2rem));
        height: auto;
        min-height: 280px;
        max-height: 42vh;
    }

    /* Form area – only this part scrolls */
    .admin-form-scroll {
        order: 0;
        flex: 1 1 auto;
        overflow-y: auto;
        min-height: 0;
        padding-bottom: 24px;
        -webkit-overflow-scrolling: touch;
    }
}

/* ── Automation mobile tweaks ── */
@media (max-width: 768px) {
    /* CTA full width */
    .automacao-header {
        flex-direction: column;
        gap: .75rem;
    }

    .automacao-header button {
        width: 100%;
        justify-content: center;
    }

    /* Modal inputs stack */
    .automacao-modal .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    /* Modal footer sticky */
    .automacao-modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        padding-top: .75rem;
        border-top: 1px solid var(--stroke);
        margin-top: .75rem;
    }
}

/* ── Pagination mobile ── */
@media (max-width: 480px) {
    .pagination-bar {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .pagination-bar span {
        width: 100%;
        text-align: center;
        font-size: .75rem;
    }
}

/* ── Selected-actions bar mobile ── */
@media (max-width: 768px) {
    .selected-actions-bar {
        left: .5rem !important;
        right: .5rem !important;
        transform: none !important;
        flex-direction: column;
        gap: .5rem;
        padding: .75rem !important;
    }
}
