/* ===== Variables ===== */
:root {
    --primary: #C96442;
    --primary-dark: #A84F30;
    --primary-light: #FAEAE1;
    --sidebar-bg: #EFE8DC;
    --sidebar-hover: #E5DDD0;
    --sidebar-active: #FAEAE1;
    --sidebar-text: #3D352E;
    --sidebar-text-muted: #7A6F66;
    --sidebar-border: rgba(110, 105, 97, 0.14);
    --bg: #FAF9F5;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #6E6961;
    --border: #E0D9CF;
    --success: #6F9E5F;
    --warning: #C99845;
    --danger: #BD3D2A;
    --info: #C96442;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --radius: 10px;
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --solo-rail: 36px;   /* franja con ☰ de la pestaña aparte (?solo=1) */
    --transition: 0.25s ease;
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ===== Scrollbars (estrecha y redondeada) ===== */
/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(110, 105, 97, 0.45) transparent;
}

/* WebKit / Chromium / Edge */
*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: rgba(110, 105, 97, 0.40);
    border-radius: 10px;
    transition: background 0.2s;
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(110, 105, 97, 0.70);
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Sidebar cream → thumb warm gray */
.sidebar,
.sidebar * {
    scrollbar-color: rgba(110, 105, 97, 0.30) transparent;
}

.sidebar *::-webkit-scrollbar-thumb {
    background: rgba(110, 105, 97, 0.25);
}

.sidebar *::-webkit-scrollbar-thumb:hover {
    background: rgba(110, 105, 97, 0.50);
}

/* ===== Login Screen ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 50%, #1a2332 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}

.login-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 48px 40px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.08);
    animation: fadeInUp 0.5s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo i {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 12px;
    display: block;
}

/* Brand logo — reemplaza al icono FA.
   img/logo.svg es vectorial puro (texto convertido a trazados, sin dependencia
   de la fuente Arial) y logo.png se exporta a 512x512, así que escala limpio
   a cualquier tamaño sin blur. */
.brand-logo {
    display: block;
    height: auto;
    object-fit: contain;
}

.brand-logo-lg {
    width: 72px;
    margin: 0 auto 14px;
}

.brand-logo-sm {
    width: 30px;
    height: 30px;
    margin: 0;
}

.login-logo h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

.login-logo .login-subtitle {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--primary);
    letter-spacing: 0.02em;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group label i {
    margin-right: 4px;
    color: var(--primary);
}

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    background: var(--bg, #FAF9F5);
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface, #fff);
    box-shadow: 0 0 0 3px rgba(201, 100, 66, 0.15);
}

/* Password wrapper + toggle */
.password-wrapper {
    position: relative;
}

.password-wrapper input {
    padding-right: 44px !important;
}

.toggle-password {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-password:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.toggle-password:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Caps Lock warning */
.caps-lock-warning {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--warning);
    font-weight: 500;
}

.caps-lock-warning[hidden] {
    display: none;
}

/* Remember me */
.form-options {
    margin-bottom: 14px;
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.remember-me input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Aviso bajo el usuario cuando se entra desde fuera y no hay contraseña. */
.login-hint {
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--text-muted, #6b7280);
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 0 0 12px;
}

.login-error {
    color: var(--danger);
    font-size: 0.82rem;
    min-height: 20px;
    margin-bottom: 8px;
    text-align: center;
    font-weight: 500;
}

.login-error.has-error {
    background: rgba(189, 61, 42, 0.08);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 10px;
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 6px rgba(201, 100, 66, 0.25);
}

.btn-login:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(201, 100, 66, 0.35);
}

.btn-login:active {
    transform: translateY(1px);
}

.btn-login:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.btn-login:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

/* ─── Paso 2: código 2FA por email ────────────────────────────── */
.twofa-intro {
    text-align: center;
    margin-bottom: 18px;
    color: var(--text);
}
.twofa-intro i.fas {
    font-size: 2.2rem;
    color: var(--primary);
    margin-bottom: 8px;
}
.twofa-intro p { margin: 4px 0; font-size: 0.92rem; }
.twofa-intro .twofa-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 6px;
}
.twofa-code-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.6rem;
    letter-spacing: 0.5em;
    text-align: center;
    text-indent: 0.5em;       /* compensa el letter-spacing visual */
    font-weight: 600;
    color: var(--primary);
}
.twofa-code-input::placeholder {
    color: var(--border);
    font-weight: 400;
}
.btn-link-cancel {
    width: 100%;
    margin-top: 10px;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn-link-cancel:hover { color: var(--primary); }

.login-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.login-footer #loginServerStatus {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.login-footer .status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    vertical-align: middle;
}

.login-footer .status-dot.online {
    background: var(--success);
    animation: pulse 2s infinite;
}

.login-footer .status-dot.offline {
    background: var(--danger);
}

/* Language switcher */
.lang-switcher {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.lang-btn {
    background: transparent;
    border: none;
    padding: 4px 8px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    font-family: inherit;
}

.lang-btn:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.lang-btn.active {
    color: var(--primary);
    font-weight: 700;
}

.lang-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.lang-sep {
    color: var(--border);
    font-weight: 700;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width var(--transition);
    border-right: 1px solid var(--sidebar-border);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--sidebar-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary);
    min-width: 30px;
    text-align: center;
}

.sidebar.collapsed .logo span {
    display: none;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 6px;
    transition: background var(--transition);
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

/* Cuadro de texto de ayuda */
.sidebar-help {
    padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-help-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-text-muted);
}
/* Cabecera plegable de la ayuda */
.sidebar-help-toggle {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0;
    transition: color var(--transition);
}
.sidebar-help-toggle:hover { color: var(--sidebar-text); }
.sidebar-help-chevron {
    margin-left: auto;
    font-size: 0.6rem;
    color: #9C9388;
    transition: transform 0.2s ease;
}
.sidebar-help.collapsed .sidebar-help-chevron { transform: rotate(-90deg); }
.sidebar-help.collapsed .sidebar-help-label { margin-bottom: 0; }
.sidebar-help.collapsed .sidebar-help-form,
.sidebar-help.collapsed .sidebar-help-answer { display: none; }
/* En sidebar mini (icon-only) ocultamos la ayuda entera */
.sidebar.collapsed .sidebar-help { display: none; }
.sidebar-help-text {
    width: 100%;
    padding: 8px 10px;
    background: rgba(110, 105, 97, 0.08);
    border: 1px solid rgba(110, 105, 97, 0.22);
    border-radius: 6px;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.8rem;
    line-height: 1.4;
    resize: vertical;
    transition: border-color var(--transition), background var(--transition);
}
.sidebar-help-text::placeholder {
    color: var(--sidebar-text-muted);
}
.sidebar-help-text:focus {
    outline: none;
    background: rgba(110, 105, 97, 0.12);
    border-color: rgba(110, 105, 97, 0.45);
}
.sidebar-help-send {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
    padding: 7px 10px;
    background: var(--primary, #2563eb);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition), filter var(--transition);
}
.sidebar-help-send:hover { filter: brightness(1.08); }
.sidebar-help-send:disabled { opacity: 0.6; cursor: progress; }
.sidebar-help-manual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    margin-top: 6px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid rgba(110, 105, 97, 0.30);
    border-radius: 6px;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}
.sidebar-help-manual i { color: var(--primary, #C96442); }
.sidebar-help-manual:hover { background: var(--sidebar-hover, rgba(110, 105, 97, 0.10)); }
.sidebar-help-answer {
    margin-top: 8px;
    padding: 8px 10px;
    max-height: 340px;
    overflow-y: auto;
    background: rgba(110, 105, 97, 0.10);
    border: 1px solid rgba(110, 105, 97, 0.20);
    border-radius: 6px;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
/* Markdown renderizado dentro de la respuesta */
.sidebar-help-answer p { margin: 0 0 6px; }
.sidebar-help-answer p:last-child { margin-bottom: 0; }
.sidebar-help-answer h3,
.sidebar-help-answer h4,
.sidebar-help-answer h5 {
    margin: 8px 0 4px;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.3;
}
.sidebar-help-answer h3:first-child,
.sidebar-help-answer h4:first-child { margin-top: 0; }
.sidebar-help-answer ol,
.sidebar-help-answer ul {
    margin: 4px 0 6px;
    padding-left: 18px;
}
.sidebar-help-answer li { margin-bottom: 4px; }
.sidebar-help-answer li:last-child { margin-bottom: 0; }
.sidebar-help-answer strong { font-weight: 700; }
.sidebar-help-answer em { font-style: italic; }
.sidebar-help-answer code {
    padding: 1px 4px;
    background: rgba(110, 105, 97, 0.18);
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}
.sidebar-help-answer.is-error {
    background: rgba(220, 38, 38, 0.10);
    border-color: rgba(220, 38, 38, 0.35);
}
/* Oculto cuando el sidebar está plegado */
.sidebar.collapsed .sidebar-help {
    display: none;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.menu-section {
    margin-bottom: 4px;
}

/* Barra "Plegar/Desplegar todo" */
.menu-toolbar {
    padding: 6px 10px 4px;
    border-bottom: 1px solid var(--sidebar-border);
    margin-bottom: 4px;
}
.menu-toolbar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid rgba(110, 105, 97, 0.22);
    border-radius: 6px;
    color: var(--sidebar-text-muted);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all var(--transition);
}
.menu-toolbar-btn:hover {
    background: rgba(110, 105, 97, 0.08);
    color: var(--sidebar-text);
    border-color: rgba(110, 105, 97, 0.40);
}
.menu-toolbar-icon {
    font-size: 0.6rem;
    transition: transform 0.2s ease;
}
.menu-toolbar-btn.all-collapsed .menu-toolbar-icon {
    transform: rotate(180deg);
}
.sidebar.collapsed .menu-toolbar {
    padding: 6px 4px;
}
.sidebar.collapsed .menu-toolbar-btn {
    justify-content: center;
    padding: 6px;
}
.sidebar.collapsed .menu-toolbar-label {
    display: none;
}

.menu-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 20px 4px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--tm-texto2, #6E6961);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
}
.menu-title:hover {
    color: var(--sidebar-text);
}
.menu-title .menu-chevron {
    font-size: 0.6rem;
    transition: transform 0.2s ease;
    color: #9C9388;
    flex-shrink: 0;
}
.menu-section.collapsed .menu-chevron {
    transform: rotate(-90deg);
}
.menu-section.collapsed .menu-item {
    display: none;
}

.sidebar.collapsed .menu-title {
    justify-content: center;
    text-align: center;
    font-size: 0;
    padding: 6px 0;
    cursor: default;
}

.sidebar.collapsed .menu-title::after {
    content: '···';
    font-size: 0.7rem;
}

/* Separador dentro de una sección del menú */
.menu-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.10);
    margin: 6px 16px;
}
.menu-section.collapsed .menu-divider { display: none; }
.sidebar.collapsed .menu-divider { margin: 6px 10px; }

/* Botón de información en el título de una sección (p.ej. LABORATORIO) */
.menu-info-btn {
    margin-left: auto;
    background: none;
    border: none;
    color: #9C9388;
    cursor: pointer;
    padding: 0 2px;
    font-size: 0.8rem;
    line-height: 1;
    display: inline-flex;
    transition: color var(--transition);
}
.menu-info-btn:hover { color: var(--primary, #C96442); }
.sidebar.collapsed .menu-info-btn { display: none; }

.sidebar.collapsed .menu-chevron {
    display: none;
}

/* En modo sidebar colapsado (icon-only) ignoramos el plegado por sección:
   los iconos siempre se ven para que sigan siendo clicables. */
.sidebar.collapsed .menu-section.collapsed .menu-item {
    display: flex;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
}

.menu-item:hover {
    background: var(--sidebar-hover);
    color: var(--tm-texto, #1F1F1E);
}

.menu-item.active {
    background: var(--sidebar-active);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.menu-item i {
    min-width: 22px;
    text-align: center;
    font-size: 0.9rem;
}

.menu-item span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-item-newtab {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--sidebar-text);
    opacity: 0.55;
    padding: 2px 4px;
    cursor: pointer;
    font-size: 0.7rem;
    border-radius: 3px;
    flex-shrink: 0;
    line-height: 1;
    margin-left: auto;
}

.menu-item:hover .menu-item-newtab {
    display: flex;
}

.menu-item-newtab:hover {
    opacity: 1;
    background: rgba(0,0,0,0.08);
    color: var(--primary);
}

.sidebar.collapsed .menu-item-newtab {
    display: none !important;
}

.sidebar.collapsed .menu-item {
    padding: 8px;
    justify-content: center;
}

.sidebar.collapsed .menu-item span {
    display: none;
}

/* Contador de tareas abiertas asignadas al usuario (entrada «Tareas») */
/* Tareas pendientes del usuario en la opción «Tareas»: círculo rojo */
.menu-badge {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
}

.menu-badge[hidden],
.sidebar.collapsed .menu-badge {
    display: none;
}

/* Muestra esperando a que el laboratorio la recoja (sección y opción) */
.menu-lab-aviso {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--danger, #BD3D2A);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0;
}
.menu-title .menu-lab-aviso { margin-left: auto; }
/* Solo con la campana a la vista: oculta, el ⓘ conserva su margin-left:auto. */
.menu-title .menu-lab-aviso:not([hidden]) + .menu-info-btn { margin-left: 6px; }
.menu-item .menu-lab-aviso { margin-left: auto; }
.menu-lab-aviso i { animation: lab-campana 1s ease-in-out infinite; transform-origin: 50% 0; }
@keyframes lab-campana {
    0%, 50%, 100% { transform: rotate(0); }
    10%, 30% { transform: rotate(16deg); }
    20%, 40% { transform: rotate(-16deg); }
}
.menu-lab-aviso[hidden] { display: none; }
.sidebar.collapsed .menu-item .menu-lab-aviso { display: none; }
@media (prefers-reduced-motion: reduce) {
    .menu-lab-aviso i { animation: none; }
}

/* status-dot reusable (now inside dropdown) */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    min-width: 8px;
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--danger);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Asa para cambiar el ancho del menú lateral (arrastrar; doble clic = original) */
.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 7px;
    cursor: col-resize;
    z-index: 5;
    touch-action: none;
}
.sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 3px;
    width: 2px;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.15s;
}
.sidebar-resizer:hover::after,
body.sidebar-resizing .sidebar-resizer::after { opacity: 0.5; }
.sidebar.collapsed .sidebar-resizer { display: none; }
body.sidebar-resizing { cursor: col-resize; user-select: none; }
body.sidebar-resizing .sidebar,
body.sidebar-resizing .main-content { transition: none; }
body.sidebar-resizing #programIframe { pointer-events: none; }

/* Botón ☰ de la barra superior (solo teléfono) y fondo del cajón */
.mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text);
    font-size: 1.05rem;
    cursor: pointer;
}
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 99;
}
.sidebar-backdrop.show { display: block; }

/* ===== Main Content ===== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;   /* sin esto, una tabla ancha estira la página más que la pantalla */
    transition: margin-left var(--transition);
    min-height: 100vh;
}

.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed);
}

/* ===== Top Bar ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 30px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    flex: 0 0 auto;
    min-width: 180px;
}

.topbar h1 {
    font-size: 1.25rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 0 0 auto;
    margin-left: auto;
}

.datetime {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ===== Búsqueda global ===== */
.topbar-search {
    position: relative;
    flex: 1 1 420px;
    max-width: 560px;
}

.topbar-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.95rem;
    pointer-events: none;
}

.global-search-input {
    width: 100%;
    padding: 9px 36px 9px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg, #FAF9F5);
    color: var(--text-primary);
    font-size: 0.92rem;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.global-search-input::placeholder {
    color: #94a3b8;
}

.global-search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface, #fff);
    box-shadow: 0 0 0 3px rgba(251,132,71,0.15);
}

.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: color 0.15s, background 0.15s;
}

.search-clear:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.04);
}

.search-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    max-height: 380px;
    overflow-y: auto;
    z-index: 100;
    padding: 6px;
}

.search-suggestion-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: background 0.1s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.search-suggestion-item:hover,
.search-suggestion-item.active {
    background: rgba(251, 132, 71, 0.10);
}

.search-suggestion-item i {
    color: var(--primary);
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
}

.search-suggestion-item .ssi-text {
    flex: 1;
    overflow: hidden;
}

.search-suggestion-item .ssi-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-suggestion-item .ssi-name mark {
    background: rgba(251, 132, 71, 0.25);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

.search-suggestion-item .ssi-section {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-top: 1px;
}

.search-suggestion-empty {
    padding: 14px 12px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    text-align: center;
}

/* ===== Mis tareas (topbar) ===== */
.topbar-tasks {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.05rem;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.topbar-tasks:hover {
    background: rgba(0,0,0,0.04);
    border-color: var(--border);
    color: var(--primary);
}

.topbar-tasks-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    min-width: 18px;
    padding: 1px 5px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
}

.topbar-tasks-badge.overdue {
    background: var(--danger);
}

.topbar-tasks-badge[hidden] {
    display: none;
}

/* ===== Menú usuario (topbar) ===== */
.user-menu {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px 6px 8px;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.user-menu-btn:hover,
.user-menu-btn[aria-expanded="true"] {
    background: rgba(0,0,0,0.04);
    border-color: var(--border);
}

.user-menu-btn > i.fa-user-circle {
    font-size: 1.5rem;
    color: var(--primary);
}

.user-menu-btn .chevron {
    font-size: 0.7rem;
    color: var(--text-secondary);
    transition: transform 0.15s;
}

.user-menu-btn[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    z-index: 100;
    padding: 6px;
    overflow: hidden;
}

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
}

.user-dropdown-header > i {
    font-size: 2.2rem;
    color: var(--primary);
}

.user-dropdown-header .udh-info {
    overflow: hidden;
}

.user-dropdown-header .udh-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-dropdown-header .udh-role {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.user-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.user-dropdown-server {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
}

.user-dropdown-server .status-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
}

.user-dropdown-server .uds-info {
    overflow: hidden;
}

.user-dropdown-server .uds-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-dropdown-server .uds-value {
    font-size: 0.88rem;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, color 0.1s;
}

.user-dropdown-item i {
    width: 18px;
    text-align: center;
    color: var(--text-secondary);
}

.user-dropdown-item:hover {
    background: rgba(0,0,0,0.04);
}

.btn-logout-item:hover {
    background: rgba(189, 61, 42, 0.10);
    color: var(--danger);
}

.btn-logout-item:hover i {
    color: var(--danger);
}

/* Mensajes sin leer (botón de usuario y opción «Mensajes» del desplegable) */
.msg-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.msg-badge[hidden] {
    display: none;
}

.user-dropdown-item .msg-badge {
    margin-left: auto;
}

/* Estado de los avisos de Windows en el desplegable (app.js → renderAvisosWindows) */
.avisos-windows-estado {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.avisos-windows-estado[data-estado="on"] {
    color: var(--success);
    font-weight: 600;
}

/* Círculo rojo sobre el icono del usuario con lo que tiene sin leer
   (mensajes + correos); late si hay un aviso persistente. */
.user-menu-btn {
    position: relative;
}

.user-menu-btn > .msg-badge {
    position: absolute;
    top: -3px;
    left: 22px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    font-size: 0.68rem;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--card-bg);
}

.user-menu-btn > .msg-badge.alarm {
    animation: msg-badge-alarm 1s ease-in-out infinite;
}

@keyframes msg-badge-alarm {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 2px rgba(189, 61, 42, 0.5); }
    50%      { transform: scale(1.18); box-shadow: 0 0 0 2px var(--card-bg), 0 0 0 7px rgba(189, 61, 42, 0); }
}

.toast.toast-alarm {
    font-weight: 600;
}

.toast.toast-alarm i {
    color: var(--danger);
    animation: msg-badge-alarm 1s ease-in-out infinite;
}

/* «Silenciar» del aviso de muestras del laboratorio */
.toast .toast-mute {
    flex-shrink: 0;
    margin-left: 8px;
    padding: 4px 10px;
    border: 1px solid currentColor;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.toast .toast-mute:hover { background: rgba(0, 0, 0, .08); }
.toast .toast-mute:disabled { opacity: .5; cursor: default; }
.toast.toast-alarm .toast-mute i { color: inherit; animation: none; }

@media (prefers-reduced-motion: reduce) {
    .user-menu-btn > .msg-badge.alarm,
    .toast.toast-alarm i { animation: none; }
}

/* Aviso de mensaje nuevo: al pulsarlo se abre Mensajes */
.toast.toast-clickable {
    cursor: pointer;
}

/* Llamada de la centralita 3CX (aviso fijo mientras dura la llamada) */
.toast.toast-llamada > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toast.toast-llamada .llamada-detalle { font-size: 0.78rem; opacity: 0.85; }
.toast.toast-llamada.sonando i { animation: llamada-sonando 0.9s ease-in-out infinite; }
@keyframes llamada-sonando {
    0%, 100% { transform: rotate(0); }
    20%, 60% { transform: rotate(-14deg); }
    40%, 80% { transform: rotate(14deg); }
}
@media (prefers-reduced-motion: reduce) {
    .toast.toast-llamada.sonando i { animation: none; }
}

/* ===== Modal: Personalización del panel (preferencias del propio usuario) ===== */
.prefs-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.prefs-modal-overlay[hidden] { display: none; }

/* ── Modal guía de Laboratorio ───────────────────────────────────── */
.labinfo-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
}
.labinfo-overlay[hidden] { display: none; }
.labinfo-modal {
    background: var(--surface, #fff);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    width: 640px; max-width: 95vw; max-height: 92vh;
    display: flex; flex-direction: column;
    color: var(--text, #1F1F1E);
}
.labinfo-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border, #E0D9CF);
    display: flex; align-items: center; gap: 10px;
}
.labinfo-header h2 { font-size: 1.05rem; margin: 0; flex: 1; }
.labinfo-close {
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary, #6E6961); padding: 4px; font-size: 1rem;
}
.labinfo-close:hover { color: var(--text, #1F1F1E); }
.labinfo-body { padding: 16px 20px; overflow-y: auto; font-size: 0.92rem; line-height: 1.5; }
.labinfo-intro { margin: 0 0 12px; color: var(--text-secondary, #6E6961); }
.labinfo-body h3 {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--primary, #C96442); margin: 16px 0 8px;
}
.labinfo-body h3:first-of-type { margin-top: 0; }
.labinfo-list { margin: 0; padding-left: 18px; }
.labinfo-list li { margin-bottom: 7px; }
.labinfo-list code {
    font-family: ui-monospace, SFMono-Regular, monospace;
    background: var(--neutral-light, #F0EBE4); padding: 1px 5px; border-radius: 4px; font-size: 0.85em;
}
.labinfo-rel li { color: var(--text, #1F1F1E); }
.labinfo-soft { color: var(--text-secondary, #6E6961); font-style: italic; }
.labinfo-footer {
    padding: 12px 20px; border-top: 1px solid var(--border, #E0D9CF);
    display: flex; justify-content: flex-end; align-items: center; gap: 10px;
}
.labinfo-manuales { margin-right: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.labinfo-btn-sec {
    padding: 7px 12px; border: 1px solid var(--border, #E0D9CF); border-radius: 8px; cursor: pointer;
    background: var(--surface, #fff); color: var(--text, #1F1F1E); font: inherit; font-size: 13px;
    display: inline-flex; align-items: center; gap: 6px;
}
.labinfo-btn-sec:hover { background: var(--neutral-light, #F0EBE4); }
.labinfo-btn-sec i { color: var(--primary, #C96442); }
.labinfo-btn {
    padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer;
    background: var(--primary, #C96442); color: #fff; font: inherit; font-weight: 600;
}
.labinfo-btn:hover { background: #A84F30; }

.prefs-modal {
    background: var(--surface, #fff);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    width: 720px; max-width: 95vw; max-height: 92vh;
    display: flex; flex-direction: column;
}

.prefs-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border, #E0D9CF);
    display: flex; align-items: center; gap: 10px;
}
.prefs-header i { color: var(--primary, #C96442); font-size: 1rem; }
.prefs-header h2 {
    flex: 1; margin: 0;
    font-size: 1rem; font-weight: 600; color: var(--text, #1F1F1E);
}
.prefs-close {
    background: none; border: none; padding: 4px 8px;
    color: var(--text-secondary, #6E6961);
    font-size: 1.1rem; cursor: pointer; border-radius: 4px;
}
.prefs-close:hover { color: var(--danger, #BD3D2A); }

.prefs-tabs {
    display: flex; gap: 4px;
    border-bottom: 1px solid var(--border, #E0D9CF);
    background: var(--surface, #fff);
    padding: 0 16px;
}
.prefs-tab {
    background: none; border: none;
    padding: 12px 18px; cursor: pointer;
    font: inherit; font-size: 0.875rem;
    color: var(--text-secondary, #6E6961);
    border-bottom: 3px solid transparent;
    display: inline-flex; align-items: center; gap: 8px;
}
.prefs-tab:hover { color: var(--text, #1F1F1E); }
.prefs-tab.active {
    color: var(--primary, #C96442);
    border-bottom-color: var(--primary, #C96442);
    font-weight: 600;
}

.prefs-body {
    padding: 18px 20px;
    overflow-y: auto;
    flex: 1;
    background: var(--bg, #FAF9F5);
}
.prefs-help {
    margin: 0 0 12px;
    font-size: 0.82rem; color: var(--text-secondary, #6E6961);
}
.prefs-warning {
    background: var(--warning-light, #F9F0DC);
    color: #8a6d00;
    padding: 10px 14px; border-radius: 8px;
    margin-bottom: 14px;
    display: flex; align-items: center; gap: 10px;
    font-size: 0.82rem;
}

.prefs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
}
@media (max-width: 600px) { .prefs-grid { grid-template-columns: 1fr; } }

.prefs-check {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #E0D9CF);
    border-radius: 8px; cursor: pointer;
    transition: all 0.12s;
}
.prefs-check:hover { border-color: var(--primary, #C96442); }
.prefs-check input {
    width: 16px; height: 16px; margin: 0; flex: 0 0 16px;
    cursor: pointer; accent-color: var(--primary, #C96442);
}
.prefs-check.checked {
    background: var(--primary-light, #FAEAE1);
    border-color: var(--primary, #C96442);
}
.prefs-check .pi-icon {
    width: 28px; height: 28px; flex: 0 0 28px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    background: var(--neutral-light, #F0EBE4);
    color: var(--text-secondary, #6E6961);
}
.prefs-check .pi-text { display: flex; flex-direction: column; }
.prefs-check .pi-label { font-weight: 600; color: var(--text, #1F1F1E); font-size: 0.875rem; }
.prefs-check .pi-sub { font-size: 11px; color: var(--text-secondary, #6E6961); }

.prefs-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border, #E0D9CF);
    display: flex; gap: 12px; align-items: center;
}
.prefs-link {
    background: none; border: none;
    color: var(--primary, #C96442);
    font: inherit; cursor: pointer;
    padding: 0; text-decoration: underline;
    font-size: 0.85rem;
}
.prefs-link:hover { color: var(--primary-dark, #A84F30); }
.prefs-btn {
    padding: 8px 16px; border-radius: 8px;
    border: 1px solid transparent;
    font: inherit; font-size: 0.875rem; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    transition: background 0.15s;
}
.prefs-btn-primary {
    background: var(--primary, #C96442); color: #fff;
    border-color: var(--primary, #C96442);
}
.prefs-btn-primary:hover:not(:disabled) { background: var(--primary-dark, #A84F30); }
.prefs-btn-primary:disabled {
    background: var(--neutral-light, #F0EBE4);
    color: var(--text-secondary, #6E6961);
    border-color: var(--border, #E0D9CF);
    cursor: not-allowed;
}
.prefs-btn-outline {
    background: var(--surface, #fff);
    color: var(--text, #1F1F1E);
    border-color: var(--border, #E0D9CF);
}
.prefs-btn-outline:hover { background: var(--neutral-light, #F0EBE4); }

/* ===== KPI Cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    padding: 20px 30px 0;
}

.kpi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    border-left: 4px solid transparent;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-produccion { border-left-color: #f97316; }
.kpi-entradas { border-left-color: var(--success); }
.kpi-salidas { border-left-color: var(--info); }
.kpi-pedidos { border-left-color: var(--warning); }
.kpi-stock { border-left-color: var(--danger); }
.kpi-laboratorio { border-left-color: #8b5cf6; }
.kpi-scada { border-left-color: #06b6d4; }
.kpi-mantenimiento { border-left-color: #ec4899; }
.kpi-verificaciones { border-left-color: #14b8a6; }
.kpi-personal { border-left-color: #6366f1; }
.kpi-conta-ventas { border-left-color: #0ea5e9; }
.kpi-conta-compras { border-left-color: #a855f7; }
.kpi-cobros-hoy { border-left-color: #22c55e; }
.kpi-pagos-hoy { border-left-color: #ef4444; }
.kpi-card.kpi-link { cursor: pointer; }

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.kpi-produccion .kpi-icon { background: #fff7ed; color: #ea580c; }
.kpi-entradas .kpi-icon { background: #d1fae5; color: #059669; }
.kpi-salidas .kpi-icon { background: #dbeafe; color: #2563eb; }
.kpi-pedidos .kpi-icon { background: #fef3c7; color: #d97706; }
.kpi-stock .kpi-icon { background: #fee2e2; color: #dc2626; }
.kpi-laboratorio .kpi-icon { background: #ede9fe; color: #7c3aed; }
.kpi-scada .kpi-icon { background: #ecfeff; color: #0891b2; }
.kpi-mantenimiento .kpi-icon { background: #fce7f3; color: #db2777; }
.kpi-verificaciones .kpi-icon { background: #ccfbf1; color: #0d9488; }
.kpi-personal .kpi-icon { background: #e0e7ff; color: #4f46e5; }
.kpi-conta-ventas .kpi-icon { background: #e0f2fe; color: #0284c7; }
.kpi-conta-compras .kpi-icon { background: #f3e8ff; color: #9333ea; }
.kpi-cobros-hoy .kpi-icon { background: #dcfce7; color: #16a34a; }
.kpi-pagos-hoy .kpi-icon { background: #fee2e2; color: #dc2626; }

.kpi-info {
    display: flex;
    flex-direction: column;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.kpi-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ===== Content Area ===== */
.content-area {
    padding: 20px 30px 30px;
}

/* Quick Access */
.quick-access h2 {
    font-size: 1.05rem;
    margin-bottom: 14px;
    font-weight: 600;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.quick-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    border: 2px solid transparent;
}

.quick-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.quick-card i {
    font-size: 1.5rem;
    color: var(--primary);
}

.quick-card span {
    font-size: 0.82rem;
    font-weight: 500;
}

/* Tables */
.tables-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.table-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-card.full-width {
    grid-column: 1 / -1;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.table-header h3 {
    font-size: 0.92rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-header h3 i {
    color: var(--primary);
}

.table-count {
    font-weight: 500;
    color: var(--text-secondary);
}

.table-card small.text-muted {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.view-all {
    font-size: 0.8rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.view-all:hover {
    text-decoration: underline;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 10px 20px;
    font-size: 0.73rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    background: var(--bg, #FAF9F5);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 9px 20px;
    font-size: 0.83rem;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg, #FAF9F5);
}

.loading-cell {
    text-align: center;
    color: var(--text-secondary);
    padding: 28px 20px !important;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.73rem;
    font-weight: 600;
}

.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-mp { background: #fef3c7; color: #92400e; }
.badge-pi { background: #e0e7ff; color: #3730a3; }
.badge-pa { background: #ede9fe; color: #5b21b6; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-cyan { background: #ecfeff; color: #0e7490; }
.badge-pink { background: #fce7f3; color: #be185d; }

/* ===== Program Frame ===== */
.program-frame {
    padding: 0;
    height: calc(100vh - var(--topbar-h, 65px));
    height: calc(100dvh - var(--topbar-h, 65px));
    display: flex;
    flex-direction: column;
}

/* «Abrir en nueva pestaña» (?solo=1): el módulo ocupa toda la ventana; la
   sesión la hereda de la pestaña que lo abrió (app.js → adoptOpenerSession).
   El menú empieza oculto y una franja estrecha con ☰ lo vuelve a abrir (como
   en ASM-SCADA); con el menú abierto, su propio ☰ lo esconde otra vez. */
.solo-mode .topbar,
.solo-mode .kpi-grid,
.solo-mode .content-area,
.solo-mode .frame-toolbar { display: none !important; }
.solo-mode .main-content { margin-left: var(--solo-rail) !important; min-height: 0; }
.solo-mode .program-frame { height: 100vh; }
.solo-menu-btn { display: none; }
.solo-mode .solo-menu-btn {
    display: flex;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--solo-rail);
    padding: 14px 0 0;
    z-index: 99;
    border: 0;
    border-right: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    font-size: 1.05rem;
    cursor: pointer;
}
.solo-mode .solo-menu-btn:hover { color: var(--primary); }
@media (min-width: 769px) {
    .solo-mode:not(.solo-menu-open) .sidebar { display: none !important; }
    .solo-mode.solo-menu-open .solo-menu-btn { display: none; }
    .solo-mode.solo-menu-open .main-content { margin-left: var(--sidebar-width) !important; }
}
/* La página lleva su propio «Volver al Panel» (data-asm-back): sin fila del shell */
.program-frame.own-back .frame-toolbar { display: none; }

/* App con su propio menú (ASM-CRM) abierta en la misma ventana: tapa el menú y
   la barra del ERP; la pantalla de antes sigue cargada debajo (app.js → openEmbedded). */
.embedded-app { position: fixed; inset: 0; z-index: 900; background: var(--bg-primary, #fff); }
.embedded-app[hidden] { display: none; }
.embedded-app iframe { width: 100%; height: 100%; border: 0; display: block; }

.frame-toolbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 30px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.btn-back {
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-back:hover {
    background: var(--primary);
    color: #fff;
}

.frame-title {
    font-weight: 600;
    font-size: 0.95rem;
}

#programIframe {
    flex: 1;
    width: 100%;
    border: none;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--sidebar-bg);
    color: #fff;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.toast-error { border-left: 4px solid var(--danger); }
.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-info { border-left: 4px solid var(--info); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    /* Teléfono: el menú lateral es un cajón que se abre con ☰ */
    .sidebar,
    .sidebar.collapsed {
        width: min(300px, 86vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .sidebar.mobile-open {
        transform: none;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.25);
    }
    .main-content,
    .sidebar.collapsed ~ .main-content {
        margin-left: 0;
    }
    .mobile-menu-btn { display: inline-flex; }
    .sidebar-resizer { display: none; }
    .frame-toolbar { padding: 6px 12px; gap: 10px; }
    .btn-back { font-size: 0; gap: 0; padding: 7px 10px; }
    .btn-back i { font-size: 0.9rem; }
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: 16px;
    }
    .content-area {
        padding: 16px;
    }
    .tables-row {
        grid-template-columns: 1fr;
    }
    .table-card {
        overflow-x: auto;   /* tablas del panel: desplazamiento lateral en el teléfono */
    }
    .topbar {
        padding: 10px 12px;
        gap: 10px;
        flex-wrap: wrap;
    }
    .topbar-left {
        min-width: 0;
        flex: 1 1 auto;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .topbar h1 { font-size: 1.05rem; }
    .topbar-search {
        order: 3;
        flex: 1 1 100%;
        max-width: none;
    }
    .datetime {
        display: none;
    }
    .user-menu-btn span {
        display: none;
    }
    .login-card {
        margin: 16px;
        padding: 32px 24px 28px;
    }
}

@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .quick-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
