/* =============================================================================
   MEDICFOLIO — layout.css
   Navbar, Sidebar, estructura principal, flash messages
   ============================================================================= */

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
    --navbar-h:      56px;
    --sidebar-w:     248px;
    --sidebar-bg:    #0F172A;
    --sidebar-hover: #1E293B;
    --sidebar-activo:#1D4ED8;
    --sidebar-texto: #E2E8F0;
    --sidebar-texto-suave: #94A3B8;
    --navbar-bg:     #1E293B;
    --navbar-texto:  #F1F5F9;
    --transition:    .2s ease;
}

/* ── Reset base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--fondo, #F8FAFC);
    color: var(--texto, #1E293B);
    min-height: 100vh;
}

/* ── NAVBAR ─────────────────────────────────────────────────────────────────── */
.navbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--navbar-h);
    background: var(--navbar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
    gap: 1rem;
}

/* Hamburguesa */
.navbar-hamburguesa {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: .375rem;
    border-radius: 6px;
    flex-shrink: 0;
}
.navbar-hamburguesa span {
    display: block;
    width: 20px; height: 2px;
    background: var(--navbar-texto);
    border-radius: 2px;
    transition: var(--transition);
}
.navbar-hamburguesa:hover { background: rgba(255,255,255,.1); }

/* Logo */
.navbar-logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    text-decoration: none;
    color: var(--navbar-texto);
}
.navbar-logo-icono  { font-size: 1.25rem; }
.navbar-logo-nombre {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.01em;
    color: #fff;
}
.navbar-izq {
    display: flex;
    align-items: center;
    gap: .625rem;
    flex-shrink: 0;
}
.navbar-entorno {
    font-size: .65rem;
    font-weight: 700;
    background: #F59E0B;
    color: #000;
    border-radius: 4px;
    padding: .1rem .375rem;
    letter-spacing: .04em;
}

/* Breadcrumb */
.navbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: .375rem;
    font-size: .875rem;
    color: var(--sidebar-texto);
    overflow: hidden;
    flex: 1;
    min-width: 0;
}
.breadcrumb-link {
    color: var(--sidebar-texto);
    text-decoration: none;
    white-space: nowrap;
}
.breadcrumb-link:hover { color: #fff; }
.breadcrumb-sep      { color: var(--sidebar-texto-suave); }
.breadcrumb-actual   {
    color: #fff;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Alertas */
.navbar-alertas {
    position: relative;
    color: var(--navbar-texto);
    text-decoration: none;
    font-size: 1.25rem;
    padding: .375rem;
    border-radius: 6px;
    flex-shrink: 0;
}
.navbar-alertas:hover { background: rgba(255,255,255,.1); }
.alertas-badge {
    position: absolute;
    top: 0; right: 0;
    background: #EF4444;
    color: #fff;
    font-size: .65rem;
    font-weight: 700;
    border-radius: 50%;
    width: 16px; height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--navbar-bg);
}

/* Usuario */
.navbar-der {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}
.navbar-usuario { position: relative; }
.navbar-usuario-btn {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--navbar-texto);
    padding: .375rem .625rem;
    border-radius: 6px;
    transition: background var(--transition);
}
.navbar-usuario-btn:hover { background: rgba(255,255,255,.1); }
.navbar-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--sidebar-activo);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .875rem;
    font-weight: 700;
    flex-shrink: 0;
}
.navbar-usuario-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}
.navbar-usuario-nombre {
    font-size: .8125rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}
.navbar-usuario-rol {
    font-size: .7rem;
    color: var(--sidebar-texto);
}
.navbar-chevron { font-size: .75rem; color: var(--sidebar-texto); }
.navbar-vista-como {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 .625rem;
    border-radius: 999px;
    background: #FEF3C7;
    color: #92400E;
    font-size: .75rem;
    font-weight: 700;
    white-space: nowrap;
}

/* Dropdown usuario */
.navbar-usuario-menu {
    position: absolute;
    top: calc(100% + .5rem);
    right: 0;
    background: #fff;
    border: 1px solid var(--borde, #E2E8F0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    min-width: 240px;
    z-index: 300;
    overflow: hidden;
}
.usuario-menu-header {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--borde, #E2E8F0);
    background: var(--fondo, #F8FAFC);
}
.usuario-menu-email {
    font-size: .8125rem;
    color: var(--texto-suave, #64748B);
    overflow: hidden;
    text-overflow: ellipsis;
}
.usuario-menu-vista-activa {
    margin-top: .375rem;
    font-size: .75rem;
    font-weight: 700;
    color: #92400E;
}
.usuario-menu-vista {
    padding: .5rem 0;
}
.usuario-menu-vista form {
    margin: 0;
}
.usuario-menu-vista-titulo {
    padding: .25rem 1rem .375rem;
    font-size: .7rem;
    font-weight: 700;
    color: var(--texto-suave, #64748B);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.usuario-menu-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .625rem 1rem;
    text-decoration: none;
    color: var(--texto, #1E293B);
    font-size: .9rem;
    transition: background var(--transition);
}
.usuario-menu-vista-opcion {
    width: 100%;
    border: 0;
    background: transparent;
    cursor: pointer;
    text-align: left;
}
.usuario-menu-vista-opcion-activa {
    background: #EFF6FF;
    color: #1D4ED8;
    font-weight: 700;
}
.usuario-menu-item:hover { background: var(--fondo, #F8FAFC); }
.usuario-menu-divider {
    height: 1px;
    background: var(--borde, #E2E8F0);
    margin: .25rem 0;
}
.usuario-menu-salir { color: #DC2626 !important; }
.usuario-menu-salir:hover { background: #FEF2F2 !important; }

/* ── LAYOUT PRINCIPAL ───────────────────────────────────────────────────────── */
.layout-wrap {
    display: flex;
    min-height: 100vh;
    padding-top: var(--navbar-h);
}

/* ── SIDEBAR ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    position: fixed;
    top: var(--navbar-h);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition);
    scrollbar-width: thin;
    scrollbar-color: var(--sidebar-hover) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--sidebar-hover); border-radius: 2px; }

/* Secciones del sidebar */
.sidebar-seccion { padding: .75rem 0; }
.sidebar-seccion + .sidebar-seccion { border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-seccion-bottom { margin-top: auto; }
.sidebar-seccion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .25rem .875rem .375rem;
}
.sidebar-seccion-label {
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #94A3B8;
}
.sidebar-agregar {
    color: #94A3B8;
    text-decoration: none;
    font-size: 1.125rem;
    line-height: 1;
    width: 22px; height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background var(--transition);
}
.sidebar-agregar:hover { background: #1E293B; color: #fff; }

/* Vacio */
.sidebar-vacio { padding: .375rem .875rem; }
.sidebar-vacio-link {
    font-size: .8125rem;
    color: var(--sidebar-activo);
    text-decoration: none;
}

/* Pacientes en sidebar */
.sidebar-pacientes { display: flex; flex-direction: column; }
.sidebar-paciente-wrap { border-left: 3px solid transparent; }
.sidebar-paciente-activo { border-left-color: var(--sidebar-activo); }

.sidebar-paciente-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .875rem;
    text-decoration: none;
    color: #E2E8F0;
    transition: background var(--transition);
}
.sidebar-paciente-link:hover { background: #1E293B; }
.sidebar-paciente-activo .sidebar-paciente-link { background: rgba(29,78,216,.25); }

.sidebar-paciente-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8125rem;
    font-weight: 700;
    color: #CBD5E1;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-paciente-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.sidebar-paciente-info { display: flex; flex-direction: column; overflow: hidden; }
.sidebar-paciente-nombre {
    font-size: .8125rem;
    font-weight: 500;
    color: #E2E8F0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-paciente-edad {
    font-size: .7rem;
    color: #94A3B8;
}

/* Módulos del paciente activo */
.sidebar-modulos {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,.2);
    padding: .25rem 0;
}
.sidebar-modulo-link {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .375rem .875rem .375rem 2.25rem;
    text-decoration: none;
    color: #CBD5E1;
    font-size: .8125rem;
    transition: background var(--transition);
    border-left: 2px solid transparent;
}
.sidebar-modulo-link:hover { background: #1E293B; color: #fff; }
.sidebar-modulo-activo {
    color: #fff;
    background: rgba(29,78,216,.35);
    border-left-color: #1D4ED8;
}
.sidebar-modulo-icono { font-size: .9375rem; width: 18px; text-align: center; }
.sidebar-modulo-qr { opacity: .7; }
.sidebar-modulo-qr:hover { opacity: 1; }

/* Links generales */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .875rem;
    text-decoration: none;
    color: #CBD5E1;
    font-size: .875rem;
    border-radius: 0;
    transition: background var(--transition);
    border-left: 3px solid transparent;
}
.sidebar-link:hover { background: #1E293B; color: #fff; }
.sidebar-link-activo {
    color: #ffffff;
    background: rgba(29,78,216,.4);
    border-left-color: #1D4ED8;
}
.sidebar-link-icono { width: 18px; text-align: center; font-size: .9375rem; }

/* Plan badge */
.sidebar-plan {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .625rem .875rem;
    border-top: 1px solid rgba(255,255,255,.06);
    flex-wrap: wrap;
}
.plan-badge {
    font-size: .7rem;
    font-weight: 700;
    padding: .2rem .5rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.plan-free    { background: #334155; color: #94A3B8; }
.plan-básico  { background: #1D4ED8; color: #fff; }
.plan-premium { background: #7C3AED; color: #fff; }
.plan-trial   { font-size: .7rem; color: var(--sidebar-texto-suave); }
.plan-upgrade {
    font-size: .7rem;
    color: #F59E0B;
    text-decoration: none;
    margin-left: auto;
    font-weight: 600;
}
.plan-upgrade:hover { text-decoration: underline; }

/* ── CONTENIDO PRINCIPAL ────────────────────────────────────────────────────── */
.main-contenido {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 1.5rem 2rem;
    min-height: calc(100vh - var(--navbar-h));
    max-width: 100%;
    overflow-x: hidden;
}

/* ── OVERLAY (mobile) ───────────────────────────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
}
.overlay-visible { display: block; }

/* ── FLASH MESSAGES ─────────────────────────────────────────────────────────── */
.flash {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: .9375rem;
    animation: slideDown .25s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.flash-exito  { background: #DCFCE7; border: 1px solid #86EFAC; color: #166534; }
.flash-error  { background: #FEE2E2; border: 1px solid #FCA5A5; color: #991B1B; }
.flash-info   { background: #DBEAFE; border: 1px solid #93C5FD; color: #1E40AF; }
.flash-alerta { background: #FEF3C7; border: 1px solid #FCD34D; color: #92400E; }
.flash-icono  { font-size: 1rem; flex-shrink: 0; font-weight: 700; }
.flash-texto  { flex: 1; }
.flash-cerrar {
    background: none; border: none;
    cursor: pointer; font-size: 1.125rem;
    color: inherit; opacity: .7;
    padding: 0 .25rem;
    flex-shrink: 0;
}
.flash-cerrar:hover { opacity: 1; }

/* ── PÁGINA PÚBLICA (login, QR) ─────────────────────────────────────────────── */
.pagina-publica {
    background: #F1F5F9;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

/* ── RESPONSIVE ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar-abierto {
        transform: translateX(0);
    }
    .main-contenido {
        margin-left: 0;
        padding: 1rem;
    }
    .navbar-usuario-info { display: none; }
    .navbar-breadcrumb   { display: none; }
    .navbar-chevron      { display: none; }
}

@media (max-width: 480px) {
    .main-contenido { padding: .75rem; }
}

/* ── TABS (reutilizados en varios módulos) ───────────────────────────────────── */
.tabs-contenedor {
    background: var(--superficie, #fff);
    border: 1px solid var(--borde, #E2E8F0);
    border-radius: 8px;
    overflow: hidden;
}
.tabs-nav {
    display: flex;
    border-bottom: 2px solid var(--borde, #E2E8F0);
    background: var(--fondo, #F8FAFC);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs-nav::-webkit-scrollbar { display: none; }
.tab-btn {
    display: flex; align-items: center; gap: .375rem;
    padding: .875rem 1.25rem;
    border: none; background: transparent; cursor: pointer;
    font-size: .9rem; color: var(--texto-suave, #64748B);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px; white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--primario, #2563EB); }
.tab-activa {
    color: var(--primario, #2563EB);
    border-bottom-color: var(--primario, #2563EB);
    font-weight: 600;
    background: #fff;
}
.tab-badge {
    background: var(--primario, #2563EB); color: #fff;
    border-radius: 999px; font-size: .7rem;
    padding: .1rem .45rem; font-weight: 600;
    min-width: 1.25rem; text-align: center;
}
.tab-panel { display: none; padding: 1.5rem; }
.tab-visible { display: block; }

/* ── UTILIDADES COMUNES ─────────────────────────────────────────────────────── */
.pagina-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.pagina-header h1 { font-size: 1.375rem; font-weight: 700; margin: 0; }
.pagina-header-izq { display: flex; align-items: center; gap: .75rem; flex: 1; }
.pagina-header-der { display: flex; gap: .5rem; }
.btn-volver {
    color: var(--texto-suave, #64748B);
    text-decoration: none;
    font-size: .875rem;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: .25rem;
}
.btn-volver:hover { color: var(--primario, #2563EB); }

.campo { margin-bottom: 1rem; }
.campo label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: .3125rem;
    color: var(--texto, #1E293B);
}
.campo input,
.campo select,
.campo textarea {
    width: 100%;
    padding: .5625rem .75rem;
    border: 1px solid var(--borde, #E2E8F0);
    border-radius: 6px;
    font-size: .9375rem;
    color: var(--texto, #1E293B);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.campo input:focus,
.campo select:focus,
.campo textarea:focus {
    outline: none;
    border-color: var(--primario, #2563EB);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.campo textarea { resize: vertical; min-height: 80px; }

.btn {
    display: inline-flex; align-items: center; gap: .375rem;
    padding: .5625rem 1.125rem;
    border-radius: 6px; font-size: .9375rem; font-weight: 500;
    cursor: pointer; border: none; text-decoration: none;
    transition: background .15s, box-shadow .15s;
    white-space: nowrap;
}
.btn-primario   { background: var(--primario, #2563EB); color: #fff; }
.btn-primario:hover   { background: #1D4ED8; }
.btn-secundario { background: var(--fondo, #F8FAFC); border: 1px solid var(--borde, #E2E8F0); color: var(--texto, #1E293B); }
.btn-secundario:hover { background: var(--borde, #E2E8F0); }
.btn-outline    { background: transparent; border: 1px solid var(--primario, #2563EB); color: var(--primario, #2563EB); }
.btn-outline:hover    { background: var(--primario, #2563EB); color: #fff; }
.btn-peligro    { background: #DC2626; color: #fff; }
.btn-peligro:hover    { background: #B91C1C; }
.btn-sm { padding: .375rem .75rem; font-size: .875rem; }
.btn-completo { width: 100%; justify-content: center; }
