/* ── RESET & BASE ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button { font-family: inherit; font-size: inherit; color: inherit; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

html {
    overflow-y: scroll;
    scrollbar-width: none;
}
html::-webkit-scrollbar { display: none; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    font-size: 14px;
    line-height: 1.5;
}

/* ── NAVBAR ────────────────────────────────────────────────── */
.navbar {
    background: #1e293b;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
    gap: 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: .5px;
    color: #93c5fd;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    flex: 1;
}

.nav-link {
    color: #cbd5e1;
    text-decoration: none;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: background .15s, color .15s;
}
.nav-link:hover, .nav-link.active {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-left: auto;
}
.user-name { color: #e2e8f0; font-size: 0.85rem; }
.user-role {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
}
.user-role.admin   { background: #3b82f6; color: #fff; }
.user-role.gestor  { background: #f59e0b; color: #fff; }
.user-role.user    { background: #64748b; color: #fff; }

.btn-logout {
    background: rgba(239,68,68,.15);
    color: #fca5a5;
    border: 1px solid rgba(239,68,68,.3);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.8rem;
    transition: background .15s;
}
.btn-logout:hover { background: rgba(239,68,68,.3); }

/* ── CONTAINER ─────────────────────────────────────────────── */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ── MESSAGES ──────────────────────────────────────────────── */
.messages { margin-bottom: 1rem; }
.message {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    border-left: 4px solid transparent;
}
.message.success { background: #d1fae5; border-color: #10b981; color: #065f46; }
.message.error   { background: #fee2e2; border-color: #ef4444; color: #991b1b; }
.message.warning { background: #fef3c7; border-color: #f59e0b; color: #92400e; }
.message.info    { background: #dbeafe; border-color: #3b82f6; color: #1e40af; }

/* ── PAGE HEADER ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); }
.back-link {
    display: inline-block;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}
.back-link:hover { text-decoration: underline; }
.sub-info { color: var(--gray-500); font-size: 0.85rem; margin-top: 0.2rem; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }

/* ── STATS ─────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.stat-label { color: var(--gray-500); font-size: 0.8rem; margin-top: 0.25rem; text-transform: uppercase; letter-spacing: .5px; }

/* ── CARDS ─────────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1rem;
}
.card-body-scroll {
    max-height: 213px;
    overflow-y: auto;
}
.card-body-scroll-lg {
    max-height: 355px;
    overflow-y: auto;
}
.card-body-scroll-lg2 {
    max-height: 426px;
    overflow-y: auto;
}
.table-wrapper {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table-scroll {
    max-height: 240px;
    overflow-y: auto;
}
.table-scroll-main {
    max-height: 390px;
    overflow-y: auto;
}
.table-scroll-main .table thead th {
    position: sticky;
    top: 0;
    background: var(--gray-50);
    z-index: 1;
    box-shadow: 0 1px 0 var(--gray-200);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: var(--radius) var(--radius) 0 0;
}
.card-header h2, .card-header h3 { font-size: 1rem; font-weight: 600; }
.card-total { font-size: 1.1rem; font-weight: 700; color: var(--primary); white-space: nowrap; }
.card-header-right { display: flex; align-items: center; gap: 0.75rem; }
.card-body { padding: 1.25rem; }

.collapsible { cursor: pointer; user-select: none; }
.collapsible::after { content: ' ▾'; font-size: 0.75rem; color: var(--gray-500); }
.collapsible.collapsed::after { content: ' ▸'; }
.collapsible.collapsed { border-bottom: none; border-radius: var(--radius); }

/* ── PROCESSO GRID ─────────────────────────────────────────── */
.processo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
}
.card-full { grid-column: 1 / -1; }

@media (max-width: 768px) {
    .processo-grid { grid-template-columns: 1fr; }
}

/* ── TOTAL FINAL ───────────────────────────────────────────── */
.total-final-card {
    background: linear-gradient(135deg, #1e3a5f, #2563eb);
    color: #fff;
    border-radius: var(--radius);
    padding: 1.5rem 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
    margin: 1rem 0;
}
.total-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; opacity: .8; }
.total-value { font-size: 2.5rem; font-weight: 800; margin: 0.25rem 0; }
.total-breakdown { font-size: 0.8rem; opacity: .75; }

/* ── INFO GRID ─────────────────────────────────────────────── */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.info-full { grid-column: 1 / -1; }
.info-label { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--gray-500); margin-bottom: 2px; }
.info-row1 { grid-template-columns: repeat(4, 1fr); }
.info-row2 {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin-top: 0.5rem;
}
.info-row1 > div, .info-row2 > div { min-width: 0; }
.info-truncate { min-width: 0; }
.info-truncate > span:not(.info-label) {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.info-wrap > span:not(.info-label) {
    display: block;
    overflow-wrap: break-word;
}

/* ── TABLES ────────────────────────────────────────────────── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table-scroll .table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}
.table thead th {
    background: var(--gray-50);
    padding: 0.6rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 1px solid var(--gray-200);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.table tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--gray-50); }
.table-sm thead th, .table-sm tbody td { padding: 0.45rem 0.75rem; }
.tfoot-total td { background: var(--gray-50); font-weight: 600; border-top: 2px solid var(--gray-200); padding: 0.6rem 0.75rem; }
.val { font-weight: 600; text-align: right; }
.nowrap { white-space: nowrap; }
.td-truncate { display: block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; }
.page-header-title { min-width: 0; overflow: hidden; max-width: 55%; }
.h1-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none; }
.empty-row { text-align: center; color: var(--gray-500); font-style: italic; padding: 1.5rem !important; }
.badge-inativo { background: #fee2e2; color: var(--danger); }
.actions-cell { white-space: nowrap; width: 1%; }
.col-actions { width: 1%; white-space: nowrap; }

/* ── BADGES ────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    white-space: nowrap;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.badge-lg { font-size: 0.85rem; padding: 4px 14px; }
.badge-execucao { background: #d1fae5; color: #065f46; }
.badge-terminado { background: var(--gray-200); color: var(--gray-700); }
.badge-role-admin   { background: #dbeafe; color: #1e40af; }
.badge-role-gestor  { background: #fef3c7; color: #92400e; }
.badge-role-user    { background: var(--gray-100); color: var(--gray-700); }
.badge-action-login    { background: #d1fae5; color: #065f46; }
.badge-action-logout   { background: var(--gray-100); color: var(--gray-700); }
.badge-action-create   { background: #dbeafe; color: #1e40af; }
.badge-action-edit     { background: #fef3c7; color: #92400e; }
.badge-action-deactivate { background: #fee2e2; color: #991b1b; }
.badge-action-activate   { background: #d1fae5; color: #065f46; }
.badge-action-delete     { background: #fee2e2; color: #991b1b; }

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s;
}
.btn-outline:hover { background: #eff6ff; }
.btn-outline:disabled,
.btn-outline[disabled] { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.btn-ghost {
    background: transparent;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s;
}
.btn-ghost:hover { background: var(--gray-100); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s;
}
.btn-danger:hover { background: #b91c1c; }
.btn-reload {
    background: transparent;
    color: var(--gray-400);
    border: 1.5px solid var(--gray-300);
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color .15s, border-color .15s;
    padding: 0;
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: hidden;
}
.btn-reload:hover { color: var(--primary); border-color: var(--primary); }
.btn-reload.reloading { color: var(--primary); border-color: var(--primary); }
.btn-warning { background: var(--warning); color: #fff; border: none; padding: 0.5rem 1.25rem; border-radius: var(--radius); cursor: pointer; font-size: 0.875rem; font-weight: 500; text-decoration: none; display: inline-block; transition: background .15s; }
.btn-warning:hover { background: #b45309; }

.btn-sm { padding: 0.25rem 0.75rem !important; font-size: 0.8rem !important; line-height: 1.4 !important; font-weight: 500 !important; vertical-align: middle !important; }
.col-center { text-align: center; }
.table th.col-center, .table td.col-center { text-align: center; white-space: nowrap; }
.btn-block { width: 100%; text-align: center; }

/* ── FORMS ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.form-input, input.form-input, select.form-input, textarea.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: #fff;
    color: var(--gray-900);
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea.form-input { resize: vertical; }
.field-error { color: var(--danger); font-size: 0.78rem; display: block; margin-top: 3px; }
.field-error-js { animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: translateY(0); } }
.form-error { background: #fee2e2; color: #991b1b; padding: 0.5rem 0.75rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }

.form-card { padding: 1.5rem; }
.form-card-sm { max-width: 520px; }
.form-grid { display: flex; flex-direction: column; gap: 0; }
.form-section { margin-bottom: 1.5rem; }
.form-section-title { font-size: 0.75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--primary); margin-bottom: 0.75rem; padding-bottom: 0.4rem; border-bottom: 2px solid #dbeafe; font-weight: 700; }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; }
.form-group-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── CLIENTES LIST ─────────────────────────────────────────── */
.clientes-list { padding: 0.5rem 0; }
.cliente-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
    gap: 1rem;
}
.cliente-item:last-child { border-bottom: none; }
.cliente-item:hover { background: var(--gray-50); }
.cliente-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.cliente-icon { font-size: 1.5rem; flex-shrink: 0; }
.cliente-info > div { min-width: 0; }
.cliente-nome { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cliente-meta { color: var(--gray-500); font-size: 0.8rem; }
.cliente-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* ── PROCESSOS LIST ────────────────────────────────────────── */
.processos-list { padding: 0.5rem 0; }
.processo-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--gray-100);
    gap: 0.75rem;
}
.processo-item:last-child { border-bottom: none; }
.processo-item:hover { background: var(--gray-50); }
.processo-icon { font-size: 1.4rem; }
.processo-info { flex: 1; }
.processo-nome { font-weight: 600; }
.processo-meta { color: var(--gray-500); font-size: 0.8rem; }
.processo-side { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }

/* ── USER HOME GRID ────────────────────────────────────────── */
.user-home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

/* ── TABS ──────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--gray-200);
}
.tab-btn {
    background: none;
    border: none;
    padding: 0.4rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── SEARCH ────────────────────────────────────────────────── */
.search-input {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    width: 240px;
}
.search-input:focus { outline: none; border-color: var(--primary); }

/* ── TWO COL ───────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

/* Card que preenche a altura da célula do grid e faz scroll no overflow */
.card-fill { display: flex; flex-direction: column; }
.card-fill > .table-wrapper { flex: 1; overflow-y: auto; min-height: 0; }

/* ── LINKS ─────────────────────────────────────────────────── */
.link-doc { color: var(--primary); text-decoration: none; font-size: 0.8rem; }
.link-doc:hover { text-decoration: underline; }

/* ── EMPTY STATE ───────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--gray-500); font-style: italic; padding: 2rem; }

/* ── PWA INSTALL BUTTON ────────────────────────────────────── */
.btn-install {
    background: rgba(255,255,255,.12);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,.25);
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
    transition: background .15s;
    white-space: nowrap;
}
.btn-install:hover { background: rgba(255,255,255,.22); }

/* Garante que em modo standalone (instalado) oculta affordances de browser */
@media (display-mode: standalone) {
    .btn-install { display: none !important; }
}

.btn-success { background: var(--success); color: #fff; border: none; padding: 0.5rem 1.25rem; border-radius: var(--radius); cursor: pointer; font-size: 0.875rem; font-weight: 500; text-decoration: none; display: inline-block; transition: background .15s; }
.btn-success:hover { background: #15803d; }
.btn-estado-ativo { background: var(--success); color: #fff; border-color: var(--success); }
.btn-estado-desativado { background: var(--danger); color: #fff; border-color: var(--danger); }
.estado-segmento { display: inline-flex; border: 1px solid var(--gray-300); border-radius: var(--radius); overflow: hidden; }
.seg-btn { border: none; background: #fff; color: var(--gray-500); padding: 0.3rem 0; min-width: 90px; width: 90px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: background .15s, color .15s; -webkit-font-smoothing: antialiased; }
.seg-btn.seg-ativo { background: var(--success); color: #fff; }
.seg-btn.seg-desativado { background: var(--danger); color: #fff; }

/* ── MODAL DE CONFIRMAÇÃO ──────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    z-index: 9999; display: flex; align-items: center; justify-content: center;
    animation: fadeIn .15s ease;
}
.modal-box {
    background: #fff; border-radius: 12px; padding: 2rem 2rem 1.5rem;
    max-width: 420px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    text-align: center;
}
.modal-icon { font-size: 2.5rem; color: var(--danger); margin-bottom: 0.5rem; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.75rem; }
.modal-msg { color: var(--gray-600); font-size: 0.9rem; line-height: 1.5; margin-bottom: 1.5rem; }
.modal-msg p { margin-bottom: 0; white-space: pre-wrap; }
.modal-aviso { color: var(--danger); font-weight: 600; font-size: 0.85rem; margin-top: 0.75rem !important; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: center; }
.modal-actions .btn-danger { padding: 0.5rem 1.5rem; }
.modal-actions .btn-outline { padding: 0.5rem 1.5rem; }

/* ── PICKER MODAL ──────────────────────────────────────────── */
.picker-box { max-width: 480px; text-align: left; }
.picker-search { width: 100%; margin-bottom: 0.75rem; box-sizing: border-box; }
.picker-list { max-height: 168px; overflow-y: auto; border: 1px solid var(--gray-200); border-radius: 8px; margin-bottom: 1rem; }
.picker-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 0.65rem 1rem; cursor: pointer; font-size: 0.9rem; color: var(--gray-800); border-bottom: 1px solid var(--gray-100); }
.picker-item:last-child { border-bottom: none; }
.picker-item:hover { background: var(--primary-light, #eff6ff); color: var(--primary); }
.picker-item-active { background: var(--primary-light, #eff6ff); font-weight: 600; color: var(--primary); }
.picker-trigger { text-align: left; cursor: pointer; width: 100%; color: var(--gray-800); }
.picker-empty { cursor: default; color: var(--gray-500) !important; }

/* ── MOBILE / PWA ──────────────────────────────────────────── */
@media (max-width: 640px) {
    /* Navbar */
    .navbar { padding: 0 0.75rem; gap: 0.5rem; flex-wrap: wrap; height: auto; padding-top: 0.5rem; padding-bottom: 0.5rem; }
    .nav-brand { font-size: 1rem; }
    .nav-links { gap: 0; order: 3; width: 100%; padding-top: 0.25rem; padding-bottom: 0.25rem; }
    .nav-link { padding: 0.3rem 0.5rem; font-size: 0.78rem; }
    .nav-user { gap: 0.5rem; margin-left: auto; }
    .user-name { display: none; }
    .user-role { display: none; }
    .btn-logout { padding: 0.3rem 0.75rem; font-size: 0.78rem; }

    /* Layout */
    .container { padding: 0.75rem; }
    .stats-row { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .stat-card { padding: 0.75rem 1rem; }
    .stat-value { font-size: 1.5rem; }
    .processo-grid { grid-template-columns: 1fr; }
    .user-home-grid { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }

    /* Page header */
    .page-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .page-header h1 { font-size: 1.2rem; }
    .header-actions { flex-wrap: wrap; gap: 0.4rem; }

    /* Cards */
    .card-header { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }
    .card-header-right { flex-wrap: wrap; gap: 0.4rem; }
    .card-body { padding: 0.75rem; }

    /* Tabelas — scroll horizontal */
    .table { font-size: 0.78rem; min-width: 480px; }
    .table thead th, .table tbody td { padding: 0.4rem 0.5rem; white-space: nowrap; }
    .table-sm { min-width: 360px; }

    /* Dashboard — no mobile anula fixed layout e percentagens; cada coluna cresce pelo conteúdo */
    #tabela-processos { table-layout: auto !important; width: auto !important; }
    .table-wrapper { -webkit-overflow-scrolling: touch; }

    /* Botões de ação nas tabelas — não quebram */
    .actions-cell { white-space: nowrap; width: 1%; }
.col-actions { width: 1%; white-space: nowrap; }

    /* Total final */
    .total-final-card { padding: 1rem; }
    .total-value { font-size: 2rem; }
    .total-breakdown { font-size: 0.75rem; }

    /* Modal */
    .modal-box { padding: 1.25rem 1rem; margin: 1rem; width: calc(100% - 2rem); }
    .modal-actions { flex-direction: column; gap: 0.5rem; }
    .modal-actions .btn-outline,
    .modal-actions .btn-danger { width: 100%; justify-content: center; }

    /* Formulários */
    .form-input { font-size: 0.9rem; }
    .form-group { margin-bottom: 0.75rem; }

    /* Info grid no detalhe de processo */
    .info-grid, .info-row1, .info-row2 { grid-template-columns: 1fr; }
    .info-row2 { margin-top: 1rem; }

    /* Lista de clientes */
    .cliente-item { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem; }
    .cliente-actions { flex-wrap: wrap; gap: 0.4rem; width: 100%; }
    .cliente-actions .btn-sm { flex: 1; justify-content: center; }

    /* Lista de processos do cliente */
    .processo-item { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem; }
    .processo-side { flex-wrap: wrap; gap: 0.4rem; }

    /* Área segura para notch/barra inferior em iOS */
    body { padding-bottom: env(safe-area-inset-bottom); }
    .navbar { padding-top: calc(0.5rem + env(safe-area-inset-top)); }
}

/* Linha separadora da navbar apenas em mobile real (não em zoom de desktop) */
@media (max-width: 430px) {
    .nav-links { border-top: 1px solid rgba(255,255,255,.1); }
}

/* ── COLLAPSE-BTN (título clicável separado das acções) ────── */
.collapse-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    flex: 1;
    min-width: 0;
}
.collapse-icon {
    font-size: 0.7rem;
    color: var(--gray-500);
    flex-shrink: 0;
    display: inline-block;
    transition: transform 0.2s ease;
}
.collapse-btn:not(.collapsed) .collapse-icon { transform: rotate(90deg); }
.card-header.header-collapsed { border-bottom: none; border-radius: var(--radius); }

/* ── HORAS — GRUPOS POR UTILIZADOR ─────────────────────────── */
.user-group-row { cursor: pointer; background: var(--gray-50); }
.user-group-row:hover { background: #e8f0fe !important; }
.user-group-row td { font-size: 0.875rem; }
.group-arrow { font-size: 0.7rem; color: var(--gray-500); margin-right: 0.35rem; display: inline-block; width: 0.8rem; }
.group-detail { background: #fafbfc; }
.group-detail td { color: var(--gray-700); font-size: 0.82rem; }
.detail-indent { color: var(--gray-400); padding-left: 1rem !important; }
.muted-text { color: var(--gray-500); font-size: 0.8rem; }

/* ── SECTION SEARCH ─────────────────────────────────────────── */
.section-search-bar { padding-bottom: 0.6rem; }
.section-search {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.8rem;
    width: 220px;
    font-family: inherit;
}
.section-search:focus { outline: none; border-color: var(--primary); }

/* ── PAGINATION BAR ──────────────────────────────────────────── */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.65rem 0;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-100);
}
.pagination-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 8rem;
    text-align: center;
}

/* ── LOGIN PAGE ────────────────────────────────────────────── */
body.login-page {
    display: flex;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b, #0f172a);
}
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 2rem;
}
.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 40px rgba(0,0,0,.3);
}
.login-logo {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary);
    text-align: center;
    margin-bottom: 0.25rem;
}
.login-sub {
    text-align: center;
    color: var(--gray-500);
    font-size: 0.85rem;
    margin-bottom: 1.75rem;
}
.login-form .form-group { margin-bottom: 1rem; }
.login-form .form-group label { font-size: 0.8rem; font-weight: 600; color: var(--gray-700); display: block; margin-bottom: 4px; }

/* ── SCROLLBAR VISÍVEL (toggle via classe) ───────────────────── */
html.scrollbar-on { scrollbar-width: thin; scrollbar-color: #94a3b8 #e5e7eb; }
html.scrollbar-on body { min-height: calc(100vh + 1px); }
html.scrollbar-on::-webkit-scrollbar { display: block; width: 8px; }
html.scrollbar-on::-webkit-scrollbar-track { background: #e5e7eb; }
html.scrollbar-on::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; }
html.scrollbar-on::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ── MODO ESCURO ─────────────────────────────────────────────── */
[data-theme="dark"] {
    --gray-50:  #1e293b;
    --gray-100: #0f172a;
    --gray-200: #1e293b;
    --gray-300: #334155;
    --gray-500: #94a3b8;
    --gray-700: #cbd5e1;
    --gray-900: #f1f5f9;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,.4);
}
[data-theme="dark"] body { background: #0f172a; color: #f1f5f9; }
[data-theme="dark"] .navbar { background: #020617; }
[data-theme="dark"] .card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .login-card { background: #1e293b; }
[data-theme="dark"] .card-header { background: #162032; border-color: #334155; }
[data-theme="dark"] .form-input,
[data-theme="dark"] input.form-input,
[data-theme="dark"] select.form-input,
[data-theme="dark"] textarea.form-input { background: #162032; color: #f1f5f9; border-color: #334155; }
[data-theme="dark"] .form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.25); }
[data-theme="dark"] .picker-trigger { background: #162032; color: #f1f5f9; border-color: #334155; }
[data-theme="dark"] .table thead th { background: #162032; }
[data-theme="dark"] .table-scroll-main .table thead th { box-shadow: 0 1px 0 #334155; }
[data-theme="dark"] .table tbody tr:hover { background: #1e293b; }
[data-theme="dark"] .tfoot-total td { background: #162032; }
[data-theme="dark"] .modal-box { background: #1e293b; color: #f1f5f9; }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.7); }
[data-theme="dark"] .picker-item { background: #1e293b; color: #f1f5f9; }
[data-theme="dark"] .picker-item:hover { background: #334155; }
[data-theme="dark"] .picker-list { border-color: #334155; }
[data-theme="dark"] .btn-ghost { color: #cbd5e1; border-color: #475569; }
[data-theme="dark"] .btn-ghost:hover { background: #334155; }
[data-theme="dark"] .btn-outline:hover { background: #1e3a5f; }
[data-theme="dark"] .btn-reload { color: #64748b; border-color: #475569; }
[data-theme="dark"] .seg-btn { background: #334155; color: #94a3b8; border-color: #475569; }
[data-theme="dark"] .seg-btn.seg-ativo { background: var(--success); color: #fff; }
[data-theme="dark"] .seg-btn.seg-desativado { background: var(--danger); color: #fff; }
[data-theme="dark"] .cliente-item:hover,
[data-theme="dark"] .processo-item:hover { background: #1e293b; }
[data-theme="dark"] .cliente-item,
[data-theme="dark"] .processo-item { border-color: #334155; }
[data-theme="dark"] .badge-terminado { background: #334155; color: #94a3b8; }
[data-theme="dark"] .badge-role-user { background: #334155; color: #94a3b8; }
[data-theme="dark"] .message.success { background: #064e3b; color: #6ee7b7; border-color: #059669; }
[data-theme="dark"] .message.error   { background: #7f1d1d; color: #fca5a5; border-color: #dc2626; }
[data-theme="dark"] .message.warning { background: #78350f; color: #fcd34d; border-color: #d97706; }
[data-theme="dark"] .message.info    { background: #1e3a5f; color: #93c5fd; border-color: #3b82f6; }
[data-theme="dark"] .form-section-title { border-color: #1e3a5f; }
[data-theme="dark"] .pagination-bar { background: #162032; border-top-color: #334155; }

/* ── NAVBAR — SETTINGS ICON ──────────────────────────────────── */
.btn-settings {
    color: #94a3b8;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.4rem;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    font-size: 1.1rem;
    line-height: 1;
    transition: color .15s, background .15s;
}
.btn-settings:hover,
.btn-settings.active { color: #fff; background: rgba(255,255,255,.1); }

/* ── DEFINIÇÕES — TOGGLE SWITCH ──────────────────────────────── */
.settings-list { display: flex; flex-direction: column; gap: 0; }
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid var(--gray-200);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; }
.setting-label { font-weight: 600; font-size: 0.95rem; }
.setting-desc  { font-size: 0.82rem; color: var(--gray-500); margin-top: 2px; }
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--gray-300);
    border-radius: 999px;
    cursor: pointer;
    transition: background .2s;
}
.toggle-track::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(20px); }
@media (hover: none) and (pointer: coarse) {
    .setting-row-scrollbar { display: none; }
}

/* ── BANNER OFFLINE ─────────────────────────────────────────── */
#offline-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: #ef4444;
    color: #fff;
    text-align: center;
    padding: .6rem 1rem;
    font-size: .9rem;
    font-weight: 600;
}
