/* ============================================================
   NotaBot — Design System
   Referencia: Hospital Management SaaS (Dribbble/Creliq)
   Paleta: #F0F8F8 (fondo) · #A4DBDC (acento) · teal (marca)
   ============================================================ */

:root {
    --bg: #F0F8F8;
    --surface: #FFFFFF;
    --accent: #A4DBDC;
    --accent-soft: #E7F6F6;
    --brand: #0F766E;
    --brand-dark: #0C5E57;
    --brand-light: #14B8A6;
    --ink: #0F172A;
    --ink-soft: #475569;
    --muted: #94A3B8;
    --border: #E2E8F0;
    --danger: #E11D48;
    --sidebar-w: 260px;
    --sidebar-rail: 72px;
    --radius: 12px;
    --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
}

/* ---------- Base ---------- */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none;
}

/* Controles de formulario en color de marca */
input[type="radio"],
input[type="checkbox"] {
    accent-color: var(--brand);
}

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

.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 32px 48px;
}

/* ---------- Notificaciones (toasts) ----------
   z-index por encima de .sidebar (40) y .topbar (20) para que
   siempre sean visibles, incluso sobre el encabezado fijo. */
.notificacion {
    z-index: 60;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    object-fit: cover;
    display: block;
    box-shadow: 0 2px 6px rgba(15, 118, 110, 0.35);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-name {
    font-weight: 700;
    font-size: 17px;
    color: var(--ink);
}

.brand-sub {
    font-size: 11.5px;
    color: var(--muted);
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14.5px;
    font-weight: 500;
    color: var(--ink-soft);
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    transition: background-color 0.18s ease, color 0.18s ease;
}

.nav-item:hover {
    background: var(--bg);
    color: var(--brand);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--brand);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}

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

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.badge-local {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--brand);
    background: var(--accent-soft);
    padding: 4px 10px;
    border-radius: 999px;
}

.sidebar-version {
    font-size: 11.5px;
    color: var(--muted);
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 32px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chip {
    font-size: 12.5px;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--brand);
    border: 1px solid var(--accent);
}

.menu-toggle {
    display: none;
    width: 38px;
    height: 38px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--ink-soft);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 8px;
    transition: background-color 0.18s ease;
}

.menu-toggle:hover {
    background: var(--bg);
}

.menu-toggle svg {
    width: 22px;
    height: 22px;
}

.sidebar-overlay {
    display: none;
}

/* ---------- Hero (tarjeta de inicio) ---------- */
.hero-card {
    background: linear-gradient(135deg, var(--accent) 0%, #E9F8F8 55%, #F4FCFC 100%);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 28px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-card);
}

.hero-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--brand-dark);
    margin: 0 0 6px;
}

.hero-sub {
    font-size: 14.5px;
    color: var(--ink-soft);
    margin: 0;
    max-width: 560px;
    line-height: 1.55;
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ---------- Botones ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 9px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 1px 3px rgba(15, 118, 110, 0.3);
}

.btn-primary:hover {
    background: var(--brand-dark);
}

.btn-light {
    background: var(--surface);
    color: var(--brand);
    border-color: var(--accent);
}

.btn-light:hover {
    background: var(--accent-soft);
}

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

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ---------- Tablas ---------- */
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
}

.table-wrap table {
    min-width: 640px;
}

.table-wrap th {
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--ink-soft);
    font-weight: 600;
}

.table-wrap td {
    font-size: 14px;
    color: var(--ink);
    vertical-align: top;
}

.table-wrap tr:hover td {
    background: #F8FAFA;
}

/* ---------- Botón de acción destructiva suave (Limpiar formulario) ---------- */
.btn-clear {
    background: var(--surface);
    border: 1px solid #FECDD3;
    color: #BE123C;
    font-weight: 600;
    font-size: 13.5px;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.btn-clear:hover {
    background: #FFF1F2;
    border-color: #FDA4AF;
}

.btn-clear:focus-visible {
    outline: 2px solid #FDA4AF;
    outline-offset: 2px;
}

/* ---------- Pestañas (compatibilidad) ---------- */
.tab-button {
    transition: background-color 0.18s ease, color 0.18s ease;
}

/* ---------- Componentes existentes ---------- */
#limpiarFormularioBtn {
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#limpiarFormularioBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#criterioConservadorSection {
    transition: all 0.3s ease;
    margin-top: 1rem;
    border-left: 4px solid var(--brand-light);
}

.checkbox-item {
    transition: all 0.2s ease;
    padding: 0.5rem;
    border-radius: 0.375rem;
}

.checkbox-item:hover {
    background-color: var(--accent-soft);
}

.checkbox-item input[type="checkbox"] {
    transform: scale(1.1);
    margin-right: 0.5rem;
}

#txConservadorBtn {
    transition: all 0.3s ease;
}

#txConservadorBtn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#tratamientoField {
    min-height: 150px;
    background-color: #F8FAFA;
    border: 1px solid var(--border);
    padding: 1rem;
}

/* ============================================================
   Sidebar auto-colapsable (desktop ≥1024px)
   Colapsado: franja delgada de 72px solo iconos.
   Hover: se expande a 260px mostrando etiquetas.
   En posición fixed para que al expandirse NO desplace el contenido.
   ============================================================ */
@media (min-width: 1024px) {
    .main-area {
        margin-left: var(--sidebar-rail);
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        height: 100vh;
        width: var(--sidebar-rail);
        z-index: 40;
        box-shadow: none;
        transition: width 0.25s ease, box-shadow 0.25s ease;
        overflow: hidden;
        white-space: nowrap;
    }
    .sidebar:hover {
        width: var(--sidebar-w);
        box-shadow: 4px 0 20px rgba(15, 23, 42, 0.10);
    }
    /* Ocultar textos cuando está colapsado; mostrarlos al expandir */
    .sidebar .brand-name,
    .sidebar .brand-sub,
    .sidebar .nav-item span,
    .sidebar .sidebar-footer .badge-local {
        opacity: 0;
        transition: opacity 0.18s ease;
    }
    /* El bloque de texto no debe ocupar ancho en el rail (descentraba el logo) */
    .sidebar .brand-text {
        display: none;
    }
    .sidebar:hover .brand-text {
        display: flex;
    }
    .sidebar:hover .brand-name,
    .sidebar:hover .brand-sub,
    .sidebar:hover .nav-item span,
    .sidebar:hover .sidebar-footer .badge-local {
        opacity: 1;
    }
    /* Centrar iconos y marca cuando está colapsado */
    .sidebar .brand-mark,
    .sidebar .nav-icon {
        flex-shrink: 0;
    }
    /* El logo debe caber dentro del rail de 72px (antes 120px y se desbordaba) */
    .sidebar .sidebar-brand {
        padding: 14px 0;
        justify-content: center;
    }
    .sidebar .brand-mark {
        width: 40px;
        height: 40px;
        border-radius: 12px;
        transition: width 0.2s ease, height 0.2s ease;
    }
    .sidebar:hover .sidebar-brand {
        padding: 16px;
        justify-content: flex-start;
    }
    .sidebar:hover .brand-mark {
        width: 56px;
        height: 56px;
        border-radius: 16px;
    }
    /* Banda invisible a la derecha del rail para facilitar el hover */
    .sidebar::after {
        content: '';
        position: absolute;
        top: 0;
        right: -8px;
        bottom: 0;
        width: 8px;
    }
}

/* ============================================================
   Responsive — sidebar off-canvas en móvil/tablet
   ============================================================ */
@media (max-width: 1023px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
    }

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

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: 35;
    }

    .sidebar-overlay.hidden {
        display: none;
    }

    .menu-toggle {
        display: inline-flex;
    }

    .content {
        padding: 20px 16px 40px;
    }

    .topbar {
        padding: 12px 16px;
    }

    .hero-card {
        padding: 22px 20px;
    }
}

@media (max-width: 640px) {
    .page-title {
        font-size: 16px;
    }

    .hero-actions {
        width: 100%;
    }

    .hero-actions .btn {
        flex: 1;
        min-width: 140px;
    }

    .card-header {
        flex-direction: column;
    }

    .toolbar {
        width: 100%;
    }

    .toolbar input[type="search"] {
        flex: 1;
        min-width: 0;
    }

    /* ---------- Ventanas angostas (formato vertical tipo celular) ----------
       Se usa la app en una columna estrecha al lado de otra ventana: se
       comprime el ritmo vertical para ver más formulario sin desplazarse. */
    .content {
        padding: 14px 12px 32px;
    }

    .content section.bg-white {
        padding: 14px;
    }

    .content .mb-8 {
        margin-bottom: 14px;
    }

    .content .mb-6 {
        margin-bottom: 12px;
    }

    .content .mb-4 {
        margin-bottom: 10px;
    }

    .content h2.text-xl {
        font-size: 17px;
    }

    .hero-card {
        padding: 16px;
    }

    /* Estadísticas: dos arriba y el diagnóstico a lo ancho */
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stats-row .stat-card:last-child {
        grid-column: span 2;
    }

    .stat-card {
        padding: 12px 14px;
    }

    .stat-value {
        font-size: 22px;
    }

    /* Registros: la tabla se convierte en tarjetas apiladas
       (con data-label en cada celda, ver registros.js) */
    .table-wrap {
        overflow-x: visible;
    }

    .table-wrap table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .table-wrap thead {
        display: none;
    }

    .table-wrap tbody,
    .table-wrap tr,
    .table-wrap td {
        display: block;
        width: 100%;
    }

    .table-wrap tr {
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--surface);
        padding: 10px 12px;
        margin-bottom: 10px;
    }

    .table-wrap tr:hover td {
        background: transparent;
    }

    .table-wrap td {
        border: 0;
        padding: 3px 0;
    }

    .table-wrap td[data-label]::before {
        content: attr(data-label) ': ';
        font-size: 12.5px;
        font-weight: 600;
        color: var(--ink-soft);
    }

    .table-wrap td:last-child:not([colspan]) {
        display: flex;
        gap: 16px;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px dashed var(--border);
    }

    #limpiarFormularioBtn {
        padding: 7px 12px;
        font-size: 12.5px;
    }

    /* Sexo en una sola línea dentro de su media columna */
    .sexo-opts {
        gap: 2px 10px;
    }

    .sexo-opts label {
        font-size: 12.5px;
    }

    .sexo-opts input {
        margin-right: 4px;
    }

    /* Grupos de opciones cortas en dos columnas */
    .opts-compact {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 4px 10px;
    }

    .opts-compact > * {
        margin-top: 0 !important;
    }

    .opts-compact label {
        font-size: 13px;
    }

    /* Acciones principales a lo ancho (más fáciles de tocar) */
    #crearNotaBtn,
    #txConservadorBtn,
    #noLlegoBtn,
    #generarPDFBtn {
        width: 100%;
    }
}

/* ============================================================
   Patch: utilidades teal/cyan
   El dist pre-compilado de Tailwind 2.2.19 (npm) NO incluye las
   paletas teal ni cyan, así que aquí se definen las usadas por
   la app. Cargar DESPUÉS de vendor/tailwind.min.css (ya lo es).
   ============================================================ */

.bg-teal-50   { background-color: #F0FDFA; }
.bg-teal-500  { background-color: #14B8A6; }
.bg-teal-600  { background-color: #0D9488; }
.bg-cyan-600  { background-color: #0891B2; }

.hover\:bg-teal-600:hover  { background-color: #0D9488; }
.hover\:bg-teal-700:hover  { background-color: #0F766E; }
.hover\:bg-cyan-700:hover  { background-color: #0E7490; }

.text-teal-600 { color: #0D9488; }
.text-teal-700 { color: #0F766E; }
.text-teal-800 { color: #115E59; }

.border-teal-200 { border-color: #99F6E4; }

.focus\:ring-teal-500:focus { --tw-ring-color: #14B8A6; }

/* Color por defecto del anillo de foco (v2 usa --tw-ring-color) */

/* ============================================================
   Modo servidor: login + estadísticas
   ============================================================ */

/* --- Overlay de login (solo visible con servidor, store.js lo muestra) --- */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg) 0%, var(--accent-soft) 100%);
    padding: 20px;
}

/* .hidden debe ganarle a .login-overlay { display:flex } (misma especificidad,
   y esta regla va después en el archivo). Sin esto el overlay tapaba la app
   en modo portable (file://), donde nadie llama ocultarLogin(). */
.login-overlay.hidden {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.10);
    padding: 32px 28px;
    text-align: center;
}

.login-mark {
    width: 84px;
    height: 84px;
    border-radius: 22px;
    margin: 0 auto 14px;
}

.login-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--ink);
    margin: 0;
}

.login-sub {
    font-size: 13px;
    color: var(--ink-soft);
    margin: 6px 0 20px;
}

.login-label {
    display: block;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: 4px;
}

.login-input {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--surface);
    color: var(--ink);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-input:focus {
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.18);
}

/* --- Mostrar/ocultar contraseña en login --- */
.login-password-wrapper {
    position: relative;
    width: 100%;
}
.login-password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 4px;
    color: var(--muted);
}
.login-password-toggle:hover {
    color: var(--brand-dark);
}

.login-error {
    font-size: 13px;
    color: var(--danger);
    margin: -6px 0 12px;
    text-align: left;
}

.login-btn {
    width: 100%;
    justify-content: center;
    margin-top: 4px;
}

.login-hint {
    font-size: 11px;
    color: var(--muted);
    margin: 14px 0 0;
    line-height: 1.5;
}

/* Botón de emergencia cuando la BD no responde */
.login-local-btn {
    margin-top: 8px;
    background: var(--surface);
    color: var(--ink-soft);
    border: 1px solid var(--border);
    font-size: 13px;
}

.login-local-btn:hover {
    background: var(--accent-soft);
    color: var(--brand-dark);
    border-color: var(--accent);
}

/* --- Chip de sesión activa (topbar) --- */
.chip-user.sesion-activa {
    cursor: pointer;
    background: var(--accent-soft);
    color: var(--brand-dark);
    border-color: var(--accent);
}

.chip-user.sesion-activa:hover {
    background: var(--accent);
}

/* --- Tarjetas de estadísticas (pestaña Registros) --- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--brand);
    line-height: 1.2;
}

.stat-value.stat-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-label {
    font-size: 12px;
    color: var(--ink-soft);
    font-weight: 500;
}

:root { --tw-ring-color: rgba(15, 118, 110, 0.45); }
