:root {
    /* Off-white */
    --bg-main: #f9fafb;
    /* Branco puro para cartões */
    --bg-secondary: #ffffff;
    /* Cinza super claro para hovers */
    --bg-tertiary: #f3f4f6;

    /* Quase preto */
    --text-primary: #111827;
    /* Cinza médio */
    --text-secondary: #4b5563;

    /* Verde Esmeralda */
    --accent-color: #059669;
    /* Esmeralda mais escuro */
    --accent-hover: #047857;

    /* Âmbar / Laranja Suave */
    --secondary-accent: #d97706;

    --border-color: rgba(0, 0, 0, 0.1);

    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --transition: all 0.2s ease;

    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.05);

    /* =========================================
       Aliases e Variáveis Auxiliares
       Para garantir a consistência de variáveis antigas/diversas usadas no HTML e JS
       ========================================= */
    --primary: var(--accent-color);
    --primary-hover: var(--accent-hover);
    --accent-primary: var(--accent-color);

    /* Slate 500 */
    --secondary: #64748b;
    /* Blue 500 */
    --info: #3b82f6;
    /* Slate 800 */
    --dark: #1e293b;

    --bg-color: var(--bg-main);

    --text-color: var(--text-primary);
    --text-main: var(--text-primary);
    --text-muted: var(--text-secondary);

    --border-light: rgba(0, 0, 0, 0.05);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    font-size: 14px;
    line-height: 1.5;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: visible;
    z-index: 10;
    transition: width 0.3s ease;
    position: relative;
}

/* Sidebar Colapsada (Desktop) */
.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .logo-area h2,
.sidebar.collapsed .nav-text {
    display: none;
}

.sidebar.collapsed .nav-links a {
    justify-content: center;
    padding: 10px;
}

.sidebar.collapsed .nav-links a i {
    margin: 0;
}

.sidebar.collapsed .logo-area {
    padding: 1rem 0;
}

/* Toggle Button (Desktop) */
.sidebar-toggle-btn {
    position: absolute;
    top: 20px;
    right: -14px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    color: var(--text-primary);
    transition: background 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-tertiary);
}

.sidebar-toggle-btn i {
    font-size: 1rem;
    transition: transform 0.3s ease;
}

.sidebar.collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

.logo-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 0;
}

.logo-icon {
    color: var(--accent-color);
    font-size: 1.5rem;
    opacity: 0.7;
    transition: var(--transition);
}

.logo-container {
    padding: 0 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.logo-container h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-container h2 i {
    color: var(--accent-color);
    font-size: 1.5rem;
}

.nav-links {
    list-style: none;
    flex: 1;
    padding: 0 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-links li {
    margin-bottom: 4px;
}

.nav-links a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
}

.nav-links a i {
    font-size: 1.25rem;
    opacity: 0.7;
    transition: var(--transition);
}

.nav-links a:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.nav-links a:hover i {
    opacity: 1;
}

.nav-links a.active {
    background: var(--accent-color);
    color: #ffffff;
    box-shadow: var(--shadow-md);
}

.nav-links a.active i {
    opacity: 1;
}

/* Main Content */
.content-area {
    flex: 1;
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

#page-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    padding: 6px 12px 6px 6px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    transition: var(--transition);
    cursor: pointer;
}

.user-info:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    background: var(--accent-color);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.85rem;
}

/* Workspace Select (Environment) */
.workspace-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 16px;
    transition: var(--transition);
}

.workspace-selector:hover {
    border-color: var(--accent-color);
}

.workspace-selector i {
    color: var(--accent-color);
    font-size: 1.2rem;
}

.global-select {
    background: transparent;
    border: none;
    color: var(--text-primary);
    outline: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    width: 250px;
}

/* Sections */
.hidden-section {
    display: none !important;
}

.active-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card-documents {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0 12px 12px 12px;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--bg-tertiary);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-card h3 {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn:hover {
    background: var(--border-color);
}

.btn-primary {
    padding: 8px 16px;
    background: var(--accent-color);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--border-color);
}

.btn-icon.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: var(--danger);
}

.actions {
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input,
select,
textarea {
    padding: 10px 14px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* List Items */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 6px;
}

.list-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.list-item:hover {
    border-color: var(--bg-tertiary);
    transform: translateX(4px);
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-info {
    background: rgba(14, 165, 233, 0.1);
    color: var(--info);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    z-index: 100;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: var(--transition);
}

.modal.show .modal-content {
    transform: scale(1);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(100px);
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
    font-weight: 500;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

/* Progress Bar */
.progress-container {
    background: var(--bg-main);
    border-radius: var(--radius-full);
    height: 12px;
    width: 100%;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-bar {
    height: 100%;
    background: var(--accent-color);
    transition: width 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Restoring legacy class names with modern styling */
.glass-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    z-index: 100;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.btn-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-close:hover {
    color: var(--danger);
}

.tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
}

.tab.active,
.tab:hover {
    color: var(--text-primary);
    border-bottom-color: var(--accent-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.stat-number {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.global-context-bar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.form-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input {
    padding: 10px 14px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.hidden-section {
    display: none !important;
}

.sections {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#dashboard,
#documents,
#process,
#sync-logs,
#profiles,
#users,
#contacts,
#groups,
#companies,
#branches {
    overflow-y: auto;
    padding-right: 8px;
}

.list-header,
.filter-panel,
.documents-tabs,
.pagination-controls,
.form-card {
    flex-shrink: 0;
}

.sections,
.active-section,
#dashboard,
#process {
    min-height: 0;
}

.btn-sm {
    padding: 6px 12px !important;
    font-size: 0.8rem !important;
    border-radius: 6px !important;
    gap: 4px !important;
}

/* ── Direction Sub-tabs (Segmented Control) ──────────────────── */
.dir-tabs {
    display: flex;
    align-items: center;
    /* background: var(--bg-secondary); */
    /* border-top: 1px solid var(--border-color);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: none; */
    /* border-radius: 10px 10px 0px 0px; */
    padding: 4px 4px 0 0;
    gap: 2px;
    margin-top: 0.75rem;
    width: fit-content;
}

.dir-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border-radius: 7px 7px 0px 0px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.dir-tab:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.dir-tab.active {
    background: var(--primary);
    color: var(--bg-secondary);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.dir-tab.active i {
    color: var(--bg-secondary);
}

/* Compact filter panel rules */
#doc-filter-panel {
    padding: 0.5rem 1rem !important;
}

#doc-filter-panel .form-group {
    margin-bottom: 0.25rem !important;
    gap: 3px !important;
}

#doc-filter-panel .form-group label {
    font-size: 0.75rem !important;
}

#doc-filter-panel input,
#doc-filter-panel select {
    padding: 6px 10px !important;
    font-size: 0.85rem !important;
    height: 32px !important;
}

#doc-filter-panel .btn,
#doc-filter-panel .btn-primary {
    padding: 6px 12px !important;
    font-size: 0.8rem !important;
    height: 32px !important;
}

/* =========================================================
   RESPONSIVIDADE — IKI FiscalFlow Admin
   Breakpoints:
     Desktop grande : >= 1440px  (ajustes mínimos)
     Desktop        : 1024–1439px (sem alterações relevantes)
     Tablet         : 768–1023px
     Celular        : 480–767px
     Celular pequeno: < 480px
   ========================================================= */

/* ---------------------------------------------------------
   HAMBURGER BUTTON (visível apenas em mobile)
   --------------------------------------------------------- */
.sidebar-hamburger {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 201;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    flex-shrink: 0;
}

.sidebar-hamburger:hover {
    background: var(--bg-tertiary);
}

.sidebar-hamburger i {
    font-size: 1.4rem;
    color: var(--text-primary);
}

/* ---------------------------------------------------------
   SIDEBAR OVERLAY (mobile)
   --------------------------------------------------------- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 150;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ---------------------------------------------------------
   CHART CARD HELPERS
   --------------------------------------------------------- */
.chart-card-large {
    flex: 2;
    min-width: 0;
}

.chart-card-small {
    flex: 1;
    min-width: 0;
}

.chart-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}

/* ---------------------------------------------------------
   TABLE WRAPPER — scroll horizontal no container
   --------------------------------------------------------- */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
}

/* ---------------------------------------------------------
   FILTER ACTIONS (botões Filtrar/Limpar)
   --------------------------------------------------------- */
.filter-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

/* ---------------------------------------------------------
   DOCUMENT ACTION BAR
   --------------------------------------------------------- */
.doc-actions-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.doc-action-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.doc-action-group+.doc-action-group {
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    padding-left: 0.5rem;
    margin-left: 0.25rem;
}

/* ---------------------------------------------------------
   MODAL GRID HELPERS
   --------------------------------------------------------- */
.modal-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
}

/* ---------------------------------------------------------
   TABLET  768px – 1023px
   --------------------------------------------------------- */
@media (max-width: 1023px) {
    .sidebar {
        width: 220px;
    }

    .global-select {
        width: 160px;
    }

    .chart-card-small {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 0;
    }
}

/* ---------------------------------------------------------
   TABLET / MOBILE  <= 768px
   (Ponto de quebra principal — sidebar vira drawer)
   --------------------------------------------------------- */
@media (max-width: 768px) {

    /* === Hamburger visível === */
    .sidebar-hamburger {
        display: flex;
    }

    .sidebar-overlay {
        display: block;
    }

    /* === Sidebar como drawer === */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 200;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    /* Esconde o botão de toggle collapse em telas menores, pois usamos o drawer com hamburger */
    .sidebar-toggle-btn {
        display: none !important;
    }

    /* === Content area ocupa tudo === */
    .app-container {
        flex-direction: column;
    }

    .content-area {
        padding: 3.5rem 1rem 1rem;
        width: 100%;
        min-width: 0;
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    /* === Header === */
    header {
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: flex-start;
    }

    #page-title {
        font-size: 1.35rem;
    }

    .workspace-selector {
        flex-wrap: wrap;
        width: 100%;
        gap: 0.5rem;
        padding: 6px 10px;
    }

    .workspace-selector>div {
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .global-select {
        width: 100%;
        min-width: 0;
        flex: 1;
    }

    /* Header container direito */
    header>div:last-child {
        flex-wrap: wrap;
        gap: 0.75rem;
        width: 100%;
    }

    /* === Dashboard stats grid === */
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 0.75rem;
    }

    .stat-number {
        font-size: 1.6rem;
    }

    /* Dashboard chart cards: sem min-width fixo */
    .chart-card-large {
        flex: 1 1 100%;
        min-width: 0 !important;
    }

    .chart-card-small {
        flex: 1 1 100%;
        min-width: 0 !important;
    }

    /* === Filtros de formulário — todos os panels === */
    .filter-panel form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-panel .form-group {
        flex: 1 1 100% !important;
        min-width: 0 !important;
        width: 100% !important;
    }

    .filter-panel input,
    .filter-panel select {
        width: 100%;
        box-sizing: border-box;
    }

    /* Botões de filtro — esticam para ocupar a linha */
    .filter-panel form>div:last-child {
        justify-content: stretch;
        margin-left: 0 !important;
        width: 100%;
        flex-direction: row;
    }

    .filter-panel form>div:last-child .btn,
    .filter-panel form>div:last-child .btn-primary {
        flex: 1;
    }

    /* Grupos: grid de filtro → 1 coluna */
    #filter-group-form {
        display: flex !important;
        flex-direction: column;
    }

    #filter-group-form .form-group {
        width: 100% !important;
    }

    /* === Filtro de documentos === */
    #doc-filter-panel {
        padding: 0.75rem !important;
    }

    #filter-form {
        flex-direction: column;
        align-items: stretch;
    }

    #filter-form .form-group {
        flex: 1 1 100% !important;
        min-width: 0 !important;
        width: 100% !important;
    }

    #filter-form>div:last-child {
        justify-content: stretch;
        margin-left: 0 !important;
        width: 100%;
        flex-direction: row;
    }

    #filter-form>div:last-child button {
        flex: 1;
    }

    /* === Documentos: tabs empresa/filial === */
    .documents-tabs {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .documents-tabs>div {
        min-width: 0 !important;
        flex: 1 1 100% !important;
        width: 100% !important;
    }

    .documents-tabs select {
        width: 100%;
    }

    /* === Tab de direção documentos === */
    #tab-dirs {
        flex-wrap: wrap;
    }

    #tab-dirs .btn {
        flex: 1 1 auto;
        border-radius: 6px !important;
        text-align: center;
        min-width: 0;
        white-space: nowrap;
    }

    /* === Botões de ação de documentos === */
    .doc-actions-bar {
        width: 100%;
    }

    .doc-action-group+.doc-action-group {
        border-left: none;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding-left: 0;
        padding-top: 0.5rem;
        margin-left: 0;
        margin-top: 0.25rem;
        width: 100%;
    }

    /* === List headers === */
    .list-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .list-header h2 {
        font-size: 1.2rem;
    }

    /* === Tabelas — scroll horizontal no container === */
    .list-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .list-container table {
        min-width: 480px;
    }

    /* === Modais — não ultrapassam a viewport === */
    .modal-overlay .modal-content,
    .modal .modal-content {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    /* Grids 2 e 3 colunas → 1 coluna */
    .modal-grid-2,
    #createUserModal [style*="1fr 1fr"],
    #createBranchModal [style*="1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    .modal-grid-3,
    #createUserModal [style*="1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Modal Dossiê: tabs compactas */
    #dossierModal .modal-content {
        max-width: calc(100vw - 24px) !important;
        width: calc(100vw - 24px) !important;
    }

    #dossier-tab-header {
        gap: 0.35rem !important;
    }

    #dossier-tab-header .btn {
        font-size: 0.75rem !important;
        padding: 5px 8px !important;
    }

    /* Modal header com botões de ação */
    .modal-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* === Processamento (Sync) === */
    #form-process>div,
    #form-import {
        flex-direction: column;
    }

    #form-process .form-group {
        flex: 1 1 100% !important;
    }

    /* === Sync tabs === */
    .tabs {
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .tab {
        padding: 0.4rem 0.75rem;
    }

    /* === Toast === */
    .toast {
        right: 1rem;
        left: 1rem;
        bottom: 1rem;
        text-align: center;
    }

    /* === Paginação === */
    .pagination-controls {
        flex-direction: column !important;
        gap: 0.75rem;
        align-items: stretch !important;
        padding: 0.5rem 0 !important;
    }

    .pagination-controls>div {
        justify-content: center !important;
    }

    .pagination-controls label {
        font-size: 0.85rem;
    }
}

/* ---------------------------------------------------------
   CELULAR  < 480px
   --------------------------------------------------------- */
@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .content-area {
        padding: 3.25rem 0.75rem 0.75rem;
    }

    #page-title {
        font-size: 1.2rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .stat-number {
        font-size: 1.4rem;
    }

    .card {
        padding: 0.75rem;
    }

    .btn-primary,
    .btn-secondary,
    .btn {
        font-size: 0.82rem;
    }

    /* Tabs de direção: empilhadas */
    #tab-dirs {
        flex-direction: column;
    }

    #tab-dirs .btn {
        width: 100%;
        border-radius: 6px !important;
    }

    /* Filtros doc compactos */
    #doc-filter-panel input,
    #doc-filter-panel select {
        height: 36px !important;
        font-size: 0.82rem !important;
    }

    /* Modal padding compacto */
    .modal-overlay .modal-content,
    .modal .modal-content {
        padding: 0.75rem 1rem !important;
    }

    .modal-header h3 {
        font-size: 1rem;
    }

    /* Hamburger menor */
    .sidebar-hamburger {
        top: 0.5rem;
        left: 0.5rem;
        width: 36px;
        height: 36px;
    }

    /* List header: botão abaixo do título */
    .list-header {
        flex-direction: column;
        align-items: stretch;
    }

    .list-header .btn-primary,
    .list-header>button {
        width: 100%;
    }

    /* Contatos: botões de ação em coluna */
    #contacts .list-header>div {
        flex-direction: column;
        width: 100%;
    }

    #contacts .list-header>div .btn-primary {
        width: 100%;
    }
}

/* ---------------------------------------------------------
   CELULAR PEQUENO  < 380px
   --------------------------------------------------------- */
@media (max-width: 380px) {
    body {
        font-size: 12px;
    }

    .content-area {
        padding: 2.75rem 0.5rem 0.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .sidebar {
        width: 240px;
    }

    .btn,
    .btn-primary,
    .btn-secondary {
        padding: 7px 10px;
        font-size: 0.79rem;
    }

    #page-title {
        font-size: 1.05rem;
    }
}

/* ---------------------------------------------------------
   DESKTOP GRANDE  >= 1440px
   --------------------------------------------------------- */
@media (min-width: 1440px) {
    .chart-card-large {
        min-width: 500px;
    }

    .chart-card-small {
        min-width: 300px;
    }
}