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