/* ===========================================
   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.7em !important;
        margin-bottom: 15px !important;
        padding-bottom: 10px !important;
    }

    /* ---- Header / Nav ---- */
    .header {
        flex-direction: column !important;
        gap: 15px !important;
        align-items: flex-start !important;
        margin-bottom: 20px !important;
    }

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

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

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

    .card-title {
        font-size: 1.1em !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !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;
    }

    /* ---- Tabelas → Cards mobile ---- */
    .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: 10px;
        padding: 14px;
        margin-bottom: 12px;
        overflow: hidden;
        word-break: break-word;
    }

    table:not(.parcelas-table):not(.ptable) tbody td {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: flex-start;
        padding: 6px 0 !important;
        border-bottom: 1px solid rgba(255,255,255,0.05) !important;
        font-size: 0.88em;
        gap: 4px 10px;
        max-width: 100%;
        overflow: hidden;
    }

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

    table:not(.parcelas-table):not(.ptable) tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.75em;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-secondary, var(--text2, #888));
        min-width: 100px;
        flex-shrink: 0;
    }

    /* Conter inputs/selects/textareas 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;
        flex: 1 1 auto;
    }

    /* 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;
    }

    /* Checkbox "ANALISANDO" em linha */
    .chk-analisando {
        display: inline-flex !important;
        align-items: center !important;
        gap: 6px !important;
        white-space: nowrap !important;
        font-size: 0.75em !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;
    }

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

    /* 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;
    }

    /* Logout e theme toggle na seleção */
    .logout-btn {
        position: static !important;
        display: block !important;
        width: fit-content !important;
        margin: 10px auto !important;
    }

    .theme-switch-wrapper {
        position: static !important;
        justify-content: center !important;
        margin-bottom: 10px !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;
    }

    /* ---- Botões de ação em tabela ---- */
    .gap-btn {
        flex-direction: column !important;
        gap: 6px !important;
    }

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

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

    .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;
    }

    /* ---- Print buttons row ---- */
    .btn-win, .btn-mac {
        font-size: 0.65em !important;
        padding: 4px 8px !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;
    }
}
