/* ============================================================================
   CORTEX_APP — Components CSS
   ESTILO 1 · Gradiente Azul→Verde
   Sidebar gradiente, hovers ricos, glows, animações sutis
   ============================================================================ */

/* ============================================================================
   APP SHELL (sidebar + main)
   ============================================================================ */

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ============================================================================
   SIDEBAR — agora com gradiente vertical azul→verde
   ============================================================================ */

.sidebar {
    width: var(--sidebar-width);
    background: #0c1f3f;
    color: white;
    border-right: none;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width var(--transition-base);
    flex-shrink: 0;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.06);
}

.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .sidebar-badge,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-user-logout-text {
    display: none;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 8px;
}

.sidebar.collapsed .sidebar-user {
    flex-direction: column;
    padding: 10px;
    gap: 8px;
}

/* Brand (logo + nome) */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    margin-bottom: 12px;
    position: relative;
}

.sidebar-brand-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    color: white;
    background: rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-sm);
    padding: 6px;
    transition: all var(--transition-base);
}

.sidebar-brand:hover .sidebar-brand-icon {
    background: rgba(255, 255, 255, 0.28);
    transform: rotate(-5deg) scale(1.05);
}

.sidebar-brand-text {
    font-weight: 800;
    font-size: 17px;
    color: white;
    letter-spacing: 0.04em;
    /* Removido o gradient-clip — texto branco ficou melhor sobre fundo gradiente */
    -webkit-text-fill-color: white;
    background: none;
}

.sidebar-toggle {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.18);
    color: white;
}

.sidebar.collapsed .sidebar-toggle {
    position: absolute;
    right: -13px;
    top: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    margin-left: 0;
    color: var(--primary-blue);
}

.sidebar.collapsed .sidebar-toggle:hover {
    background: var(--gradient-soft);
    transform: scale(1.1);
}

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

/* Nav items */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px;
    border-radius: var(--radius-md);
    color: rgba(255, 255, 255, 0.85);
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition-base);
    position: relative;
    text-decoration: none;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: white;
    border-radius: 0 4px 4px 0;
    transition: height var(--transition-base);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.12);
    color: white;
    text-decoration: none;
    transform: translateX(2px);
}

.nav-item:hover::before {
    height: 60%;
}

.nav-item.active {
    background: white;
    color: #1e2d4c;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
}

.nav-item.active::before {
    height: 0;
}

.nav-item.active:hover {
    background: white;
    color: #1e2d4c;
    transform: none;
}

.nav-item.active .nav-item-icon {
    color: #1e2d4c;
}

.nav-item-icon {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
}

.sidebar-badge {
    margin-left: auto;
    background: white;
    color: var(--primary-blue);
    font-size: 10.5px;
    padding: 2px 7px;
    border-radius: 8px;
    font-weight: 700;
    line-height: 1.4;
}

.nav-item.active .sidebar-badge {
    background: #1e2d4c;
    color: white;
}

/* User card no rodapé */
.sidebar-user {
    margin-top: auto;
    padding: 10px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition-base);
    backdrop-filter: blur(8px);
}

.sidebar-user:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.3);
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-blue);
    font-weight: 700;
    font-size: 12.5px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.sidebar-user-avatar-foto {
    background: transparent;
    padding: 0;
}
.sidebar-user-avatar-foto img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 50%;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-perfil {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 1px;
}

.sidebar-user-logout {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-user-logout:hover {
    background: rgba(239, 68, 68, 0.85);
    color: white;
}

/* ============================================================================
   MAIN CONTENT
   ============================================================================ */

.app-main {
    flex: 1;
    padding: 28px 32px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    min-width: 0;
}

/* Page header */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-title h1 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
    margin-bottom: 3px;
}

.page-title p {
    color: var(--color-text-muted);
    font-size: 13px;
}

.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.page-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text-muted);
    font-size: 13px;
    margin-bottom: 16px;
    transition: all var(--transition-fast);
}

.page-back:hover {
    color: var(--primary-blue);
    text-decoration: none;
    transform: translateX(-2px);
}

/* ============================================================================
   BOTÕES — agora com gradiente, hover lift e glow
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    line-height: 1;
    font-family: var(--font-body);
    position: relative;
    overflow: hidden;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(30, 64, 175, 0.25);
}

.btn-primary:hover {
    background: var(--gradient-hover);
    box-shadow: var(--shadow-glow-blue);
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: var(--color-surface);
    border-color: var(--primary-blue);
    color: var(--primary-blue);
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.10);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover {
    background: var(--gradient-softer);
    color: var(--primary-blue);
    text-decoration: none;
}

.btn-danger {
    background: var(--color-danger-bg);
    color: var(--color-danger-text);
}

.btn-danger:hover {
    background: var(--color-danger-text);
    color: white;
    box-shadow: 0 4px 12px rgba(153, 27, 27, 0.25);
}

.btn-success {
    background: var(--primary-green);
    color: white;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}

.btn-success:hover {
    background: var(--primary-green-dark);
    box-shadow: var(--shadow-glow-green);
    color: white;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12.5px;
    border-radius: 8px;
}

.btn-lg {
    padding: 11px 20px;
    font-size: 14px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.btn-lg svg {
    width: 16px;
    height: 16px;
}

/* ============================================================================
   FORMULÁRIOS — agora com cards que reagem ao hover
   ============================================================================ */

.form-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 22px 24px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-xs);
    transition: all var(--transition-base);
    position: relative;
}

.form-section::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: var(--gradient-primary-vertical);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    transition: width var(--transition-base);
}

.form-section:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-blue-200);
    transform: translateY(-1px);
}

.form-section:hover::before {
    width: 4px;
}

.form-section-title {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
    letter-spacing: -0.01em;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 18px;
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group.span-full {
    grid-column: 1 / -1;
}

.form-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: 0.01em;
}

.form-label .required {
    color: var(--color-danger-text);
    margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
    padding: 9px 13px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 13.5px;
    color: var(--color-text);
    background: var(--color-surface);
    transition: all var(--transition-base);
    width: 100%;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
    border-color: var(--primary-blue-200);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(30, 64, 175, 0.12);
}

.form-input::placeholder {
    color: var(--color-text-soft);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    line-height: 1.5;
}

.form-help {
    font-size: 11.5px;
    color: var(--color-text-muted);
}

.form-error {
    font-size: 12px;
    color: var(--color-danger-text);
}

/* ============================================================================
   AVATARES
   ============================================================================ */

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
    font-weight: 600;
    transition: all var(--transition-base);
}

.avatar-sm { width: 32px; height: 32px; }
.avatar-md { width: 44px; height: 44px; }
.avatar-lg { width: 64px; height: 64px; }
.avatar-xl { width: 96px; height: 96px; }

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-icone {
    padding: 22%;
}

/* CRÍTICO: força o SVG a ter dimensões mesmo quando renderizado sem width/height inline.
   Sem display: block, alguns navegadores tratam o SVG como inline (default 300x150)
   e ele fica invisível dentro do padding do .avatar-icone. */
.avatar-icone svg {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
    color: inherit;
}

.avatar-masculino {
    background: var(--avatar-masc-bg);
    color: var(--avatar-masc-fg);
}

.avatar-feminino {
    background: var(--avatar-fem-bg);
    color: var(--avatar-fem-fg);
}

.avatar-outro {
    background: var(--avatar-outro-bg);
    color: var(--avatar-outro-fg);
}

/* Avatar grande (xl) com ring colorido elegante */
.avatar-xl {
    box-shadow: 0 0 0 4px var(--color-surface),
                0 0 0 6px rgba(30, 64, 175, 0.18),
                0 8px 24px rgba(30, 64, 175, 0.15);
}

.avatar-xl:hover {
    transform: scale(1.03);
    box-shadow: 0 0 0 4px var(--color-surface),
                0 0 0 6px rgba(5, 150, 105, 0.25),
                0 12px 28px rgba(30, 64, 175, 0.20);
}

/* ============================================================================
   BADGES — mais vivos e com transição
   ============================================================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    line-height: 1.5;
    transition: all var(--transition-fast);
}

.status-info { background: var(--color-info-bg); color: var(--color-info-text); }
.status-success { background: var(--color-success-bg); color: var(--color-success-text); }
.status-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.status-muted { background: var(--slate-100); color: var(--color-text-muted); }

/* ============================================================================
   TOAST
   ============================================================================ */

.cortex-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 18px;
    background: var(--color-text);
    color: white;
    border-radius: var(--radius-md);
    font-size: 13px;
    box-shadow: var(--shadow-xl);
    transform: translateY(20px);
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 9999;
    max-width: 380px;
    font-weight: 500;
}

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

.cortex-toast-success {
    background: var(--gradient-primary);
    box-shadow: var(--shadow-glow-green);
}
.cortex-toast-danger { background: var(--color-danger-text); }
.cortex-toast-info {
    background: var(--gradient-primary);
    box-shadow: var(--shadow-glow-blue);
}

/* ============================================================================
   LOADING / EMPTY
   ============================================================================ */

.loading-state, .empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
}

.loading-state .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--primary-blue);
    border-right-color: var(--primary-green);
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    background: var(--gradient-soft);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-blue);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.12);
    transition: transform var(--transition-base);
}

.empty-state:hover .empty-state-icon {
    transform: scale(1.05) rotate(-3deg);
}

.empty-state-icon svg {
    width: 32px;
    height: 32px;
}

.empty-state-title {
    font-family: var(--font-display);
    font-size: 16px;
    color: var(--color-text);
    font-weight: 600;
    margin-bottom: 6px;
}

.empty-state-text {
    font-size: 13px;
    margin-bottom: 18px;
    max-width: 360px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================================================
   RESPONSIVO
   ============================================================================ */

@media (max-width: 900px) {
    .form-grid,
    .form-grid-3 {
        grid-template-columns: 1fr;
    }

    .app-main {
        padding: 20px 18px;
    }

    .sidebar {
        width: var(--sidebar-width-collapsed);
    }

    .sidebar .sidebar-text,
    .sidebar .sidebar-badge,
    .sidebar .sidebar-user-info,
    .sidebar .sidebar-user-logout-text {
        display: none;
    }

    .sidebar .nav-item {
        justify-content: center;
        padding: 10px 8px;
    }
}
/* ============================================================================
   AVATAR-INICIAIS — fallback quando paciente não tem foto
   ============================================================================
   Substitui o antigo .avatar-icone (SVG ♂/♀). Mostra iniciais (1-2 letras)
   com fundo gradient e letras em branco. Variante por sexo:
     - .avatar-iniciais        → masculino/null: azul → verde
     - .avatar-iniciais-fem    → feminino:       rosa → verde
   ========================================================================== */

.avatar-iniciais {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: var(--gradient-primary);
    color: #fff;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    overflow: hidden;
}

.avatar-iniciais.avatar-iniciais-fem {
    background: var(--gradient-primary-fem);
}

.avatar-iniciais span {
    display: block;
    line-height: 1;
}

.avatar-sm.avatar-iniciais span { font-size: 12px; }
.avatar-md.avatar-iniciais span { font-size: 16px; }
.avatar-lg.avatar-iniciais span { font-size: 22px; }
.avatar-xl.avatar-iniciais span { font-size: 32px; }

/* ════════════════════════════════════════════════════════════════════════
   MODAIS — Regras globais
   ════════════════════════════════════════════════════════════════════════
   Aplica-se a qualquer página que use a estrutura:
   <div class="modal-overlay" style="display: none;">
       <div class="modal-content">
           <div class="modal-header">
               <h2>Título</h2>
               <button class="modal-close">×</button>
           </div>
           <div class="modal-body">...</div>
           <div class="modal-acoes">...</div>
       </div>
   </div>
   ════════════════════════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: modal-fade-in 0.18s ease-out;
}

@keyframes modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl, 0 20px 50px rgba(0, 0, 0, 0.3));
    animation: modal-scale-in 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modal-scale-in {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.modal-content.modal-large  { max-width: 640px; }
.modal-content.modal-xlarge { max-width: 880px; }

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

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    color: var(--color-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    line-height: 1;
}

.modal-close:hover {
    background: var(--slate-100);
    color: var(--color-text);
}

.modal-body {
    padding: 24px;
}

.modal-acoes {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 18px 24px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}


/* ============================================================================
   MOBILE / PWA — Sprint pwa_mobile
   Topbar fixa + sidebar em gaveta (drawer) + reduções de escala.
   O topbar e o backdrop são injetados pelo sidebar.js; no desktop ficam ocultos.
   ============================================================================ */

.cortex-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {

    /* ── Topbar fixa (navy, com hambúrguer) ── */
    .cortex-topbar {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(54px + env(safe-area-inset-top, 0px));
        padding: env(safe-area-inset-top, 0px) 12px 0 8px;
        background: #0c1f3f;
        color: #fff;
        z-index: 60;
        box-shadow: 0 2px 12px rgba(12, 31, 63, 0.25);
    }

    .topbar-menu-btn {
        width: 42px;
        height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        color: #fff;
        flex-shrink: 0;
        transition: background var(--transition-fast);
    }

    .topbar-menu-btn:active {
        background: rgba(255, 255, 255, 0.18);
    }

    .topbar-brand {
        display: flex;
        align-items: center;
        gap: 9px;
        font-weight: 800;
        font-size: 16px;
        letter-spacing: 0.04em;
        color: #fff;
    }

    .topbar-brand-icon {
        width: 30px;
        height: 30px;
        background: rgba(255, 255, 255, 0.18);
        border-radius: 8px;
        padding: 5px;
        color: #fff;
        flex-shrink: 0;
    }

    /* ── Shell: main ocupa a tela toda, com folga pra topbar ── */
    .app-shell { display: block; }

    .app-main {
        padding: calc(66px + env(safe-area-inset-top, 0px)) 14px 28px;
    }

    /* ── Sidebar vira gaveta lateral ── */
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        height: 100%;
        height: 100dvh;
        width: min(280px, 84vw);
        transform: translateX(-105%);
        transition: transform var(--transition-base);
        z-index: 70;
        box-shadow: 12px 0 40px rgba(12, 31, 63, 0.35);
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
        overflow-y: auto;
    }

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

    /* No mobile o modo "colapsado" do desktop é ignorado:
       a gaveta abre sempre completa, com textos visíveis. */
    .sidebar.collapsed { width: min(280px, 84vw); }
    .sidebar.collapsed .sidebar-text,
    .sidebar.collapsed .sidebar-badge { display: inline; }
    .sidebar.collapsed .sidebar-user-info { display: block; }
    .sidebar.collapsed .sidebar-brand { justify-content: flex-start; }
    .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 12px 10px; }
    .sidebar.collapsed .sidebar-user { flex-direction: row; padding: 10px; gap: 10px; }

    /* Recolher/expandir não faz sentido na gaveta */
    .sidebar-toggle,
    .sidebar.collapsed .sidebar-toggle { display: none; }

    /* Itens com área de toque maior */
    .nav-item { padding: 12px 10px; font-size: 14px; }
    .nav-item-icon { width: 19px; height: 19px; }

    /* ── Backdrop escurecido atrás da gaveta ── */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(6, 24, 51, 0.55);
        z-index: 65;
        opacity: 0;
        transition: opacity var(--transition-base);
        -webkit-backdrop-filter: blur(2px);
        backdrop-filter: blur(2px);
    }

    .sidebar-backdrop.show { display: block; opacity: 1; }

    /* Trava o scroll do fundo com a gaveta aberta */
    body.sidebar-aberta { overflow: hidden; }

    /* ── Cabeçalho de página ── */
    .page-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-title h1 { font-size: 20px; }
    .page-title p { font-size: 12.5px; }

    .page-actions { width: 100%; flex-wrap: wrap; }
    .page-actions .btn { flex: 1 1 auto; }

    /* ── Formulários em coluna única ── */
    .form-grid,
    .form-grid-3 { grid-template-columns: 1fr; gap: 12px; }

    .form-section { padding: 16px 14px; }

    /* 16px evita o zoom automático do iOS ao focar campos */
    .form-input,
    .form-select,
    .form-textarea { font-size: 16px; }

    /* ── Botões um pouco menores ── */
    .btn { padding: 9px 14px; font-size: 13px; }
    .btn-lg { padding: 11px 18px; font-size: 14px; }

    /* ── Toast ocupa a largura ── */
    .cortex-toast {
        left: 14px;
        right: 14px;
        bottom: 18px;
        max-width: none;
        text-align: center;
    }

    /* ── Login mais compacto ── */
    .login-shell { padding: 30px 22px; }

    /* Scrollbar fina */
    ::-webkit-scrollbar { width: 4px; height: 4px; }
}

@media (max-width: 480px) {
    .app-main { padding-left: 12px; padding-right: 12px; }
    .page-title h1 { font-size: 19px; }
}


/* ============================================================================
   APP DESKTOP — Sprint app_titlebar (Window Controls Overlay)
   Quando instalado como app no Chrome/Edge desktop, a barra nativa some e a
   faixa .cortex-wco-bar assume: navy, arrastável, com a marca. Os controles
   nativos (min/max/fechar) ficam sobrepostos no canto e herdam o theme_color
   navy do manifest — visual contínuo. Ativado só por html.wco (titlebar.js).
   ============================================================================ */

.cortex-wco-bar { display: none; }

html.wco .cortex-wco-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(titlebar-area-height, 33px);
    background: #0c1f3f;
    color: rgba(255, 255, 255, 0.92);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding-left: calc(env(titlebar-area-x, 0px) + 12px);
    z-index: 500;
    -webkit-app-region: drag;
    app-region: drag;
    user-select: none;
    -webkit-user-select: none;
}

html.wco .cortex-wco-bar svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    opacity: 0.95;
}

/* Empurra todo o app pra baixo da faixa */
html.wco body {
    padding-top: env(titlebar-area-height, 33px);
}

/* Sidebar sticky respeita a faixa (senão fica 33px maior que a janela) */
html.wco .sidebar {
    top: env(titlebar-area-height, 33px);
    height: calc(100vh - env(titlebar-area-height, 33px));
}

/* Se o overlay estiver ativo numa janela estreita (raro), a topbar mobile
   também desce pra não ficar por baixo da faixa */
@media (max-width: 768px) {
    html.wco .cortex-topbar {
        top: env(titlebar-area-height, 33px);
    }
}
