/* ===========================================
   K&O Legal Management — Mobile Responsive
   Importar em todos os templates:
   <link rel="stylesheet" href="/static/mobile.css">
   =========================================== */

@media (max-width: 768px) {

    /* ---- Layout geral ---- */
    body {
        padding: 10px !important;
        font-size: 14px;
        overflow-x: hidden;
        max-width: 100vw;
    }

    .container {
        max-width: 100% !important;
        padding: 0 !important;
        overflow-x: hidden;
    }

    .top-header {
        font-size: 0.65em !important;
        margin-bottom: 10px !important;
        padding-bottom: 8px !important;
    }

    /* ---- Header / Nav ---- */
    .header {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 10px !important;
        align-items: center !important;
        margin-bottom: 14px !important;
    }

    .header > div:first-child {
        flex: 1;
    }

    .header .brand {
        font-size: 1.2em !important;
    }

    .header .sub {
        font-size: 0.6em !important;
    }

    .nav-group {
        flex-wrap: wrap !important;
        gap: 10px !important;
        width: 100%;
    }

    .logo-area .brand {
        font-size: 1.4em !important;
    }

    /* ---- 1. FILTRO E SITUAÇÃO EMPILHADOS ---- */
    .card-title {
        font-size: 1em !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .card-title > span:first-child {
        font-size: 1em;
    }

    .card-title > div {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        width: 100% !important;
    }

    /* Forçar largura total nos filtros (override inline styles) */
    #filtro_busca,
    #filtro_situacao {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        font-size: 0.9em !important;
        box-sizing: border-box !important;
    }

    /* ---- Cards ---- */
    .card {
        padding: 14px !important;
        border-radius: 12px !important;
        margin-bottom: 14px !important;
    }

    /* ---- Formulários ---- */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .form-section {
        padding-left: 12px !important;
    }

    input, select, textarea {
        padding: 10px !important;
        font-size: 0.95em !important;
    }

    .btn-row {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .btn-row button {
        width: 100% !important;
    }

    button {
        padding: 12px 20px !important;
    }

    /* ---- 2. TABELAS → CARDS COM HIERARQUIA CLARA ---- */
    .table-container {
        overflow-x: visible !important;
        max-width: 100vw;
    }

    table:not(.parcelas-table):not(.ptable) {
        min-width: unset !important;
        width: 100% !important;
        table-layout: fixed;
    }

    table:not(.parcelas-table):not(.ptable) thead {
        display: none;
    }

    table:not(.parcelas-table):not(.ptable) tbody tr {
        display: block;
        background: var(--card-dark, var(--card, #1a1a1a));
        border: 1px solid var(--border, #333);
        border-radius: 14px;
        padding: 18px 18px;
        margin-bottom: 14px;
        overflow: hidden;
        word-break: break-word;
    }

    /* Cada campo do card — label à esquerda, valor à direita */
    table:not(.parcelas-table):not(.ptable) tbody td {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0 !important;
        border-bottom: 1px solid rgba(128,128,128,0.08) !important;
        font-size: 1em;
        gap: 2px 8px;
        max-width: 100%;
        overflow: hidden;
    }

    table:not(.parcelas-table):not(.ptable) tbody td:last-child {
        border-bottom: none !important;
        padding-bottom: 0 !important;
    }

    /* Labels dos campos */
    table:not(.parcelas-table):not(.ptable) tbody td::before {
        content: attr(data-label);
        font-weight: 800;
        font-size: 0.75em;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        /* Era `var(--accent, #2196f3)`: com a cor-ponte fora do base, o rótulo do cartão
           e o fio do ID caíam no AZUL do fallback — a única cor de fora da identidade que
           ainda aparecia, e só a 390 px, que é onde ninguém olha duas vezes. */
        color: var(--pri, #8a661a);
        min-width: 80px;
        flex-shrink: 0;
    }

    /* ID — destaque no topo do card */
    table:not(.parcelas-table):not(.ptable) tbody td:first-child {
        padding-bottom: 10px !important;
        border-bottom: 2px solid var(--pri, #8a661a) !important;
    }

    /* Badges inline (não empilhados) */
    table:not(.parcelas-table):not(.ptable) tbody td .badge-dias,
    table:not(.parcelas-table):not(.ptable) tbody td .badge-planilha,
    table:not(.parcelas-table):not(.ptable) tbody td .badge-fatal {
        display: inline-flex !important;
    }

    /* Conter inputs/selects dentro dos cards */
    table:not(.parcelas-table):not(.ptable) tbody td select,
    table:not(.parcelas-table):not(.ptable) tbody td input,
    table:not(.parcelas-table):not(.ptable) tbody td textarea {
        max-width: 100% !important;
        min-width: 0 !important;
        width: 100% !important;
        flex: 1 1 auto;
        font-size: 1em !important;
    }

    /* Conter textos longos */
    table:not(.parcelas-table):not(.ptable) tbody td b,
    table:not(.parcelas-table):not(.ptable) tbody td strong,
    table:not(.parcelas-table):not(.ptable) tbody td span {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Ações — largura total */
    table:not(.parcelas-table):not(.ptable) tbody td div[style*="flex-direction:column"] {
        width: 100% !important;
        align-items: stretch !important;
    }

    /* ---- 3. ESCONDER WIN/MAC NO MOBILE, MANTER ABRIR ---- */
    button.btn-win,
    button.btn-mac,
    .btn-win,
    .btn-mac {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
    }

    button.btn-exp,
    .btn-exp {
        display: block !important;
        width: 100% !important;
        padding: 10px 16px !important;
        font-size: 0.85em !important;
        border-radius: 6px !important;
    }

    /* ---- 4. SITUAÇÃO E ANALISANDO ---- */
    .status-select {
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px !important;
        font-size: 1em !important;
        border-radius: 8px !important;
    }

    .chk-analisando {
        display: inline-flex !important;
        align-items: center !important;
        gap: 8px !important;
        white-space: nowrap !important;
        font-size: 0.9em !important;
        margin-top: 6px !important;
    }

    .analista-select {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 1em !important;
        padding: 10px !important;
        border-radius: 8px !important;
    }

    /* ---- 5. OBS INPUT ---- */
    table:not(.parcelas-table):not(.ptable) tbody td .obs-input {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 50px;
    }

    /* ---- Ações: botões empilhados ---- */
    .gap-btn {
        flex-direction: column !important;
        gap: 6px !important;
    }

    .copy-group {
        flex-wrap: wrap !important;
    }

    /* Selects e textareas largura total no card */
    table:not(.parcelas-table):not(.ptable) tbody td .status-select {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Tabelas pequenas (parcelas, ptable) — scroll horizontal */
    .parcelas-table,
    .ptable {
        font-size: 0.78em !important;
    }

    /* ---- Alertas / Dropdown ---- */
    .dropdown-alerts {
        width: calc(100vw - 20px) !important;
        max-width: 100% !important;
        right: -10px !important;
    }

    .alert-item {
        padding: 12px !important;
        font-size: 0.82em !important;
    }

    /* ---- Modais ---- */
    .modal-content-conclusao,
    .modal-box,
    .instr-modal-box {
        width: 95% !important;
        max-width: 100% !important;
        padding: 20px !important;
        margin: 5% auto !important;
    }

    .modal-overlay {
        padding: 10px !important;
    }

    .modal-header-conclusao {
        font-size: 1.1em !important;
    }

    /* ---- Seleção (tela de menu) ---- */
    .selection-container {
        padding: 10px !important;
    }

    .selection-container .header {
        margin-bottom: 20px !important;
    }

    .selection-container .logo-text {
        font-size: 1.8em !important;
    }

    .options-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .option-card {
        padding: 16px !important;
    }

    /* Top bar (theme toggle + trocar senha + sair) na seleção */
    .top-actions {
        position: static !important;
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 10px !important;
        padding: 12px 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .top-actions .logout-btn {
        position: static !important;
        display: inline-block !important;
        width: auto !important;
        margin: 0 !important;
        padding: 6px 12px !important;
        font-size: 0.8em !important;
    }

    .top-actions .theme-switch-wrapper {
        position: static !important;
        justify-content: center !important;
        margin: 0 !important;
    }

    /* ---- Login ---- */
    .login-card {
        margin: 10px !important;
        padding: 25px !important;
        max-width: 100% !important;
    }

    .logo-text {
        font-size: 1.8em !important;
    }

    /* ---- Footer ---- */
    .footer {
        padding: 20px !important;
        font-size: 0.7em !important;
    }

    /* ---- Financeiro: distribuição ---- */
    .distrib-row {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }

    .totais-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .total-card .value,
    .total-card .val {
        font-size: 1.2em !important;
    }

    /* ---- Tabs ---- */
    .tabs {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    .tab-btn {
        white-space: nowrap !important;
        padding: 8px 14px !important;
        font-size: 0.78em !important;
    }

    .tab {
        white-space: nowrap !important;
        padding: 10px 15px !important;
        font-size: 0.85em !important;
    }

    /* ---- Checkbox group (admin) ---- */
    .checkbox-group {
        flex-direction: column !important;
        gap: 10px !important;
    }

    /* ---- Radio group (financeiro) ---- */
    .radio-group {
        flex-direction: column !important;
    }

    .radio-opt {
        padding: 8px 12px !important;
    }

    /* ---- User form grid (admin) ---- */
    .user-form {
        grid-template-columns: 1fr !important;
    }

    /* ---- Detail grid (modal financeiro) ---- */
    .detail-grid {
        grid-template-columns: 1fr !important;
    }

    /* ---- Explorador de arquivos ---- */
    .breadcrumb {
        font-size: 0.78em !important;
    }

    .file-item {
        padding: 10px 8px !important;
        gap: 8px !important;
    }

    .file-name {
        font-size: 0.85em !important;
    }

    .file-meta {
        display: none !important;
    }

    .file-size {
        font-size: 0.7em !important;
    }

    /* ---- Badges no mobile ---- */
    .badge-reencaminhado,
    .badge-dias,
    .badge-planilha,
    .badge-fatal {
        font-size: 0.8em !important;
        width: 26px !important;
        height: 26px !important;
    }

    .status-badge {
        font-size: 0.88em !important;
        padding: 6px 14px !important;
    }

    .badge-analisando {
        font-size: 0.82em !important;
    }
}

/* Tablet ajustes (entre 769 e 1024) */
@media (min-width: 769px) and (max-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .container {
        max-width: 100% !important;
    }

    .options-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
