/* =====================================================================
   Event CRM — responsive rules
   Desktop : sidebar + content (style.css)
   Tablet  : collapsible sidebar            (<= 1024px)
   Mobile  : bottom navigation, card lists  (<= 720px)
   ===================================================================== */

@media (max-width: 1280px) {
    .stat-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ---------- Tablet ---------- */

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.18s ease-out;
    }

    .sidebar.is-open {
        box-shadow: var(--shadow-lg);
        transform: translateX(0);
    }

    .sidebar-backdrop.is-visible {
        position: fixed;
        inset: 0;
        z-index: 25;
        display: block;
        background: rgba(16, 24, 40, 0.4);
    }

    .main {
        margin-left: 0;
    }

    .topbar .menu-toggle {
        display: inline-grid;
    }

    .topbar {
        gap: var(--s-3);
        padding: 0 var(--s-4);
    }

    .view {
        padding: var(--s-4);
    }

    .filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .filter-search {
        grid-column: 1 / -1;
    }

    .followup-item {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--s-2);
    }

    .followup-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 1100px) {
    .automation-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 900px) {
    .dashboard-grid,
    .report-grid,
    .settings-grid,
    .profile-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
    body {
        font-size: 15px;
    }

    /* Bottom navigation replaces the sidebar */
    .sidebar,
    .sidebar-backdrop,
    .topbar .menu-toggle {
        display: none !important;
    }

    .bottom-nav {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 30;
        display: grid;
        grid-template-columns: repeat(6, 1fr);
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface);
        border-top: 1px solid var(--border);
    }

    .bottom-nav-link {
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 2px;
        align-items: center;
        justify-content: center;
        min-width: 0;
        font-size: 10.5px;
        font-weight: 500;
        color: var(--muted);
        text-decoration: none;
    }

    .bottom-nav-link.is-active {
        color: var(--primary);
    }

    .bottom-nav-link .nav-badge {
        position: absolute;
        top: 6px;
        left: calc(50% + 4px);
        min-width: 18px;
        margin: 0;
        font-size: 11px;
        line-height: 18px;
    }

    .view {
        padding: var(--s-4) var(--s-3) calc(var(--bottom-nav-height) + var(--s-5) + env(safe-area-inset-bottom, 0px));
    }

    .topbar {
        padding: 0 var(--s-3);
    }

    .topbar-search {
        width: 150px;
        max-width: 44vw;
    }

    .user-name,
    .topbar-event-meta {
        display: none;
    }

    .toast-root {
        right: var(--s-3);
        bottom: calc(var(--bottom-nav-height) + var(--s-3) + env(safe-area-inset-bottom, 0px));
        left: var(--s-3);
        align-items: stretch;
    }

    .toast {
        max-width: none;
    }

    /* Inputs at 16px stop iOS from zooming the page on focus */
    input[type="text"],
    input[type="tel"],
    input[type="email"],
    input[type="url"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    input[type="search"],
    select,
    textarea {
        min-height: 42px;
        font-size: 16px;
    }

    .btn {
        min-height: 42px;
    }

    .btn-small {
        min-height: 36px;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
    }

    .page-actions {
        width: 100%;
    }

    .page-actions .btn {
        flex: 1;
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--s-2);
    }

    .stat-card {
        padding: var(--s-3);
    }

    .stat-value {
        font-size: 22px;
    }

    /* Single-column forms */
    .form-grid,
    .filters {
        grid-template-columns: minmax(0, 1fr);
    }

    .filter-search {
        grid-column: auto;
    }

    /* Filters fold away so the lead list stays on screen */
    .filter-toggle {
        display: inline-flex;
    }

    .filters:not(.is-expanded) .field:not(.filter-search) {
        display: none;
    }

    .bar-row {
        grid-template-columns: 112px minmax(0, 1fr);
        gap: var(--s-2);
    }

    .bar-label {
        white-space: normal;
        line-height: 1.25;
    }

    /* Board: one column at a time, swipe sideways for the next stage */
    .board-toolbar {
        grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
        gap: var(--s-2);
    }

    /* Dragging is not available on touch screens; cards use the "Move to" menu */
    .board-hint {
        display: none;
    }

    .kanban {
        grid-auto-columns: 84vw;
        scroll-snap-type: x mandatory;
        margin: 0 calc(var(--s-3) * -1);
        padding: 0 var(--s-3) var(--s-2);
    }

    .kanban-column {
        max-height: none;
        scroll-snap-align: center;
    }

    .kanban-list {
        max-height: 62vh;
    }

    .view-switch {
        width: 100%;
    }

    .view-switch-link {
        flex: 1;
        justify-content: center;
        min-height: 40px;
    }

    .rule {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .rule > .btn {
        grid-column: 2;
        justify-self: start;
    }

    .outbox-actions .btn {
        flex: 1 1 auto;
    }

    /* Lead table becomes a list of cards */
    .leads-table thead {
        display: none;
    }

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

    .leads-table tr {
        padding: var(--s-3);
        border-bottom: 1px solid var(--border);
    }

    .leads-table tbody tr:last-child {
        border-bottom: 0;
    }

    .leads-table td {
        display: flex;
        gap: var(--s-3);
        align-items: center;
        justify-content: space-between;
        padding: 4px 0;
        text-align: right;
        border: 0;
    }

    .leads-table td::before {
        flex-shrink: 0;
        font-size: 12.5px;
        font-weight: 500;
        color: var(--muted);
        content: attr(data-label);
    }

    .leads-table td.cell-name {
        display: block;
        padding-bottom: var(--s-2);
        font-size: 16px;
        text-align: left;
    }

    .leads-table .cell-sub {
        max-width: none;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .leads-table td.cell-name::before,
    .leads-table td.col-actions::before {
        display: none;
    }

    .leads-table td.col-actions {
        padding-top: var(--s-2);
    }

    .row-actions {
        gap: var(--s-2);
        justify-content: space-between;
        width: 100%;
    }

    .row-actions .icon-btn {
        flex: 1;
        border: 1px solid var(--border);
    }

    .row-actions .icon-btn-whatsapp {
        flex: 2;
        color: #fff;
        background: var(--whatsapp);
        border-color: var(--whatsapp);
    }

    .pagination {
        justify-content: center;
    }

    /* Modals fill the screen */
    .modal-overlay {
        align-items: stretch;
        padding: 0;
    }

    .modal {
        max-width: none;
        max-height: none;
        min-height: 100%;
        border-radius: 0;
    }

    .modal-small {
        align-self: center;
        min-height: 0;
        margin: var(--s-4);
        border-radius: 10px;
    }

    .modal-header {
        padding-left: var(--s-4);
    }

    .modal-body {
        padding: var(--s-4);
    }

    .modal-footer {
        padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
    }

    .modal-footer .btn {
        flex: 1;
    }

    /* Lead profile */
    .profile-actions {
        width: 100%;
    }

    .profile-actions .btn {
        flex: 1 1 auto;
    }

    .profile-actions .btn-whatsapp {
        flex-basis: 100%;
        order: -1;
    }

    .pipeline {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        row-gap: var(--s-4);
    }

    .pipeline-step:nth-child(4)::before {
        display: none;
    }

    .info-row {
        grid-template-columns: 120px minmax(0, 1fr);
    }

    .followup-actions .btn {
        flex: 1 1 calc(50% - 6px);
    }

    .list-item {
        flex-wrap: wrap;
    }

    .list-meta {
        width: 100%;
    }

    .action-row .btn,
    .action-buttons {
        width: 100%;
    }

    .action-buttons .btn {
        flex: 1;
    }
}

@media print {
    .sidebar,
    .topbar,
    .bottom-nav,
    .page-actions,
    .toast-root {
        display: none !important;
    }

    .main {
        margin: 0;
    }

    .card {
        break-inside: avoid;
        box-shadow: none;
    }
}
