/* ============================================================
   GIBSON MANAGER PRO — RESPONSIVE
   Cobre: Notebook · Tablet · Mobile Android · iOS
   Sempre carregado por último (sobrescreve outros CSS)
   ============================================================ */

/* ── iOS / Safari global fixes ─────────────────────────────── */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Previne zoom automático no iOS ao focar inputs
   (font-size < 16px dispara zoom) */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* Safe area para notch (iPhone X+) */
.top-bar {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
}
.sidebar {
    padding-bottom: env(safe-area-inset-bottom);
}
.page-content {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* ── iOS PWA (home screen / standalone) ────────────────────────
   Em modo standalone com status-bar black-translucent, a barra de
   status (≈ 44-54px no iPhone moderno) flutua sobre o conteúdo.
   Precisamos empurrar a top-bar para baixo e corrigir 100vh.
   ─────────────────────────────────────────────────────────────── */
@media (display-mode: standalone) {
    /* Reservar espaço da status bar no topo */
    .top-bar {
        padding-top: env(safe-area-inset-top) !important;
        height: calc(70px + env(safe-area-inset-top)) !important;
        box-sizing: border-box;
    }

    /* Sidebar: também precisa do topo */
    .sidebar {
        padding-top: env(safe-area-inset-top) !important;
    }

    /* Corrigir 100vh no iOS standalone (não inclui safe areas) */
    html, body {
        height: -webkit-fill-available;
    }
    .main-content {
        height: calc(100vh - env(safe-area-inset-top)) !important;
    }

    /* Bottom bar / home indicator */
    .page-content {
        padding-bottom: max(32px, env(safe-area-inset-bottom)) !important;
    }
}


/* ============================================================
   NOTEBOOK PEQUENO (1024px – 1280px)
   ============================================================ */
@media (max-width: 1280px) {
    .sidebar { width: 220px; }
    .main-content { margin-left: 220px; }
    .page-content { padding: 20px 24px; }
}

@media (max-width: 1100px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; }

    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .stat-content h3 { font-size: 20px !important; }

    .search-container { width: 160px; }
    .search-container:focus-within { width: 220px; }
}


/* ============================================================
   TABLET (768px – 1024px)
   ============================================================ */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; }

    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }

    .page-content { padding: 18px 20px; }

    /* Tabelas com muitas colunas — scroll horizontal */
    .table-container,
    .card > table,
    .card-body > table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    /* Modal: mais espaço */
    .modal { max-width: 92vw; }
}


/* ============================================================
   MOBILE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* ── Layout principal ──────────────────────────────────── */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(.4,0,.2,1);
        z-index: 1000;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }

    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
    }

    /* ── Top bar ───────────────────────────────────────────── */
    .top-bar {
        height: 56px;
        padding: 0 12px;
        gap: 8px;
    }
    .top-bar h1 {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }
    .top-bar-right { gap: 6px; }
    .search-container { display: none !important; }

    /* ── Page content ──────────────────────────────────────── */
    .page-content { padding: 12px; }
    .page-header { margin-bottom: 16px; }
    .page-header h2 { font-size: 20px; }
    .page-header p { font-size: 13px; }
    .page-header .page-actions,
    .page-header [style*="display:flex"] {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* ── Grids ─────────────────────────────────────────────── */
    .grid-2,
    .grid-3,
    .grid-4 { grid-template-columns: 1fr !important; }

    /* ── Stat cards ────────────────────────────────────────── */
    .stat-card { padding: 14px 16px; gap: 12px; }
    .stat-content h3 { font-size: 22px; }
    .stat-icon { width: 48px; height: 48px; font-size: 20px; }

    /* ── Cards ─────────────────────────────────────────────── */
    .card { padding: 14px; }
    .card-header { flex-wrap: wrap; gap: 8px; }
    .card-header h3 { font-size: 16px; }

    /* ── Tabelas ───────────────────────────────────────────── */
    .table-container,
    .card-body > table,
    .card > table,
    div[style*="overflow"] > table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }
    table { min-width: 520px; }
    th { padding: 10px 10px; font-size: 10px; }
    td { padding: 10px 10px; font-size: 12px; }

    /* Cobranças: ocultar coluna cidade em mobile */
    .cobrancas-page table th:nth-child(3),
    .cobrancas-page table td:nth-child(3) { display: none; }

    /* ── Botões touch-friendly ─────────────────────────────── */
    .btn-primary, .btn-secondary, .btn-danger {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 13px;
        touch-action: manipulation;
    }
    .btn-icon { min-width: 36px; min-height: 36px; }

    /* ── Modais ────────────────────────────────────────────── */
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }
    .modal {
        border-radius: 20px 20px 0 0;
        max-height: 92vh;
        max-width: 100% !important;
        width: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-header { padding: 18px 16px 14px; }
    .modal-body   { padding: 16px; }
    .modal-footer {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    .modal-footer .btn-primary,
    .modal-footer .btn-secondary { flex: 1; justify-content: center; text-align: center; }
    .modal-title { font-size: 16px; }

    /* ── Formulários ───────────────────────────────────────── */
    .form-group { margin-bottom: 14px; }
    .form-group label { font-size: 12px; }
    .grid-2.form-row,
    .grid-3.form-row { grid-template-columns: 1fr !important; }

    /* ── Tabs ──────────────────────────────────────────────── */
    .tab-buttons {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .tab-buttons::-webkit-scrollbar { display: none; }
    .tab-btn {
        white-space: nowrap;
        padding: 10px 12px;
        font-size: 11px;
        flex-shrink: 0;
    }

    /* ── Kanban (Vendas) ───────────────────────────────────── */
    .kanban-board {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    /* ── Filtros / toolbars ────────────────────────────────── */
    .cob-filtros {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
        scrollbar-width: none;
        gap: 4px;
    }
    .cob-filtros::-webkit-scrollbar { display: none; }
    .cob-filtros .cob-tab-btn { flex-shrink: 0; white-space: nowrap; }

    /* input de busca nas páginas */
    #cobBusca { width: 100% !important; }

    /* ── Turnê / Central ───────────────────────────────────── */
    .turnes-grid { grid-template-columns: 1fr !important; }
    .turne-details-header { flex-direction: column; text-align: center; gap: 12px; }
    .turne-main-status {
        border-left: none !important;
        border-top: 1px solid var(--op-border);
        width: 100% !important;
        padding-top: 12px !important;
    }

    /* ── Dashboard cards de artista ────────────────────────── */
    .artista-selector-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* ── Seletor de artista (top bar) ──────────────────────── */
    #artistaDropdown { width: 90vw !important; left: 5vw !important; right: 5vw !important; }

    /* ── Etapas de proposta (modal multi-step) ─────────────── */
    .proposta-steps { gap: 4px; }
    .step-indicator { width: 28px; height: 28px; font-size: 11px; }
    .step-connector { width: 20px; }

    /* ── Relatórios / bordero ──────────────────────────────── */
    .relatorio-grid,
    .bordero-grid { grid-template-columns: 1fr !important; }
}


/* ============================================================
   MOBILE PEQUENO (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

    .top-bar h1 { font-size: 13px; max-width: 110px; }

    .page-content { padding: 10px; }
    .page-header h2 { font-size: 18px; }

    .card { padding: 12px; border-radius: 10px; }
    .stat-card { flex-direction: row; text-align: left; }
    .stat-content h3 { font-size: 20px; }

    /* Login: ocupa tela toda */
    .login-container {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
        padding: 40px 20px;
    }

    /* Tabela: só colunas essenciais */
    th, td { padding: 8px 8px; font-size: 11px; }

    /* Modal: sheet completo */
    .modal {
        max-height: 100vh;
        border-radius: 0;
    }

    /* Ocultar textos de botões, manter só ícones */
    .btn-text-hide { display: none; }

    /* Kanban cards: mais compactos */
    .kanban-card { padding: 12px; }
    .kanban-foto { width: 36px; height: 36px; }
    .kanban-artista { font-size: 13px; }
    .kanban-cliente { font-size: 11px; }

    /* Chart no dashboard do escritório */
    #officeDistChart { max-height: 220px; }
}


/* ============================================================
   LANDSCAPE MOBILE (altura < 500px)
   Para quando o celular está deitado
   ============================================================ */
@media (max-height: 500px) and (max-width: 900px) {
    .sidebar {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-top: 8px;
    }
    .top-bar { height: 48px; }
    .modal { max-height: 98vh; border-radius: 0; }
    .page-content { padding: 8px 12px; }
}


/* ============================================================
   PRINT — ocultar nav
   ============================================================ */
@media print {
    .sidebar, .top-bar, .mobile-menu-toggle, .sidebar-overlay { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
}

/* ============================================================
   DASHBOARD DO ESCRITÓRIO — classes responsivas
   (geradas via JS; precisam estar aqui pois <style> no innerHTML
    não funciona corretamente no Safari/iOS)
   ============================================================ */

/* Base (desktop) */
.esc-header      { display:flex; align-items:flex-end; justify-content:space-between; margin-bottom:22px; gap:12px; flex-wrap:wrap; }
.esc-kpi-grid    { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:16px; }
.esc-main-grid   { display:grid; grid-template-columns:1.55fr 1fr; gap:16px; margin-bottom:16px; }
.esc-events-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:13px; }

@media (max-width: 900px) {
    .esc-kpi-grid    { grid-template-columns:repeat(2,1fr) !important; gap:10px !important; }
    .esc-events-grid { grid-template-columns:repeat(2,1fr) !important; }
}

@media (max-width: 600px) {
    .esc-header      { flex-direction:column; align-items:flex-start; }
    .esc-header > div:last-child { width:100%; }
    .esc-header button { width:100% !important; }
    .esc-kpi-grid    { grid-template-columns:repeat(2,1fr) !important; gap:8px !important; }
    .esc-main-grid   { grid-template-columns:1fr !important; }
    .esc-events-grid { grid-template-columns:1fr !important; }
}
