:root {
    --bg-color: #0b0f19;
    --card-bg: rgba(18, 24, 36, 0.80);
    --card-border: rgba(59, 130, 246, 0.25);
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;

    --green-bg: rgba(16, 185, 129, 0.15);
    --green-text: #34d399;
    --green-border: rgba(52, 211, 153, 0.35);

    --yellow-bg: rgba(245, 158, 11, 0.15);
    --yellow-text: #fbbf24;
    --yellow-border: rgba(251, 191, 36, 0.35);

    --red-bg: rgba(239, 68, 68, 0.15);
    --red-text: #f87171;
    --red-border: rgba(248, 113, 113, 0.35);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: system-ui, -apple-system, sans-serif;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.fixed-bg-layer {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: -1; pointer-events: none;
    background-color: #0b0f19;
    background-image: var(--company-bg, url('../img/fondo_mgconnect.webp'));
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.42;
}

/* CONTENEDORES */
.mobile-container {
    width: 100%; max-width: 520px; padding: 24px 18px 90px 18px;
    display: flex; flex-direction: column; position: relative;
}

.app-shell {
    width: 100%; max-width: 1360px; padding: 20px;
    display: grid; grid-template-columns: 270px 1fr; gap: 20px; align-items: start;
}

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

/* SIDEBAR LATERAL (PC) + ACORDEÓN (MÓVIL/TABLET) */
.sidebar-panel {
    position: sticky; top: 20px;
    background-color: rgba(13, 18, 30, 0.90);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 20px; padding: 18px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.45);
}
.sidebar-brand {
    display: flex; justify-content: space-between; align-items: center;
    padding-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-toggle-btn {
    display: none; background: rgba(59, 130, 246, 0.2); border: 1px solid rgba(59, 130, 246, 0.45);
    color: #fff; padding: 7px 12px; border-radius: 10px; font-size: 0.82rem; font-weight: 700; cursor: pointer;
}
.sidebar-user-box {
    margin: 14px 0; padding: 11px 12px; border-radius: 12px;
    background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.25);
}
.sidebar-user-box strong { display: block; font-size: 0.92rem; color: #fff; }
.sidebar-user-box span { display: block; font-size: 0.74rem; color: #93c5fd; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 14px; border-radius: 12px; text-decoration: none;
    color: var(--text-muted); font-size: 0.88rem; font-weight: 600;
    border: 1px solid transparent; transition: 0.2s; cursor: pointer; background: transparent; width: 100%; text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.nav-item.active {
    background: rgba(59, 130, 246, 0.22); color: #fff;
    border-color: rgba(59, 130, 246, 0.45);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.nav-divider { height: 1px; background: rgba(255,255,255,0.08); margin: 8px 0; }
.nav-logout { color: var(--red-text); }
.nav-logout:hover { background: var(--red-bg); color: var(--red-text); }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; padding: 14px; gap: 14px; }
    .sidebar-panel { position: relative; top: 0; padding: 14px; }
    .sidebar-toggle-btn { display: inline-flex; align-items: center; gap: 6px; }
    .sidebar-collapsible { display: none; margin-top: 10px; }
    .sidebar-collapsible.open { display: block; animation: fadeIn 0.2s ease; }
}

/* HEADER STICKY (NFC / VISTAS MÓVILES) */
.top-header {
    position: sticky; top: 0; z-index: 100;
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 20px; margin: -24px -18px 18px -18px;
    border-bottom-left-radius: 20px; border-bottom-right-radius: 20px;
    background-color: rgba(11, 15, 25, 0.88);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--card-border);
    box-shadow: 0 10px 20px rgba(0,0,0,0.4);
}
.brand-title { font-size: 1.15rem; font-weight: 800; letter-spacing: 2px; color: #fff; text-transform: uppercase; }
.brand-subtitle { font-size: 0.7rem; color: var(--accent-blue); letter-spacing: 1px; display: block; }
.header-link {
    color: var(--text-main); text-decoration: none; font-size: 0.8rem; font-weight: 600;
    padding: 6px 12px; border-radius: 10px; background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35); transition: 0.2s; display: inline-block;
}
.header-link:hover { background: rgba(59, 130, 246, 0.3); }

/* TARJETAS GLASS */
.glass-card {
    background-color: var(--card-bg);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05);
}

.profile-card { display: flex; gap: 16px; align-items: center; }
.profile-avatar {
    width: 100px; height: 134px; border-radius: 12px;
    border: 2px solid var(--accent-blue); object-fit: cover;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3); flex-shrink: 0;
}
.profile-info { flex-grow: 1; }
.profile-info h1 { font-size: 1.35rem; font-weight: 800; color: #fff; margin-bottom: 2px; line-height: 1.15; }
.profile-info .rut { font-size: 0.88rem; color: var(--text-muted); margin-bottom: 8px; }
.card-divider { height: 2px; width: 30px; background: linear-gradient(90deg, #3b82f6, transparent); border: none; margin-bottom: 8px; }
.profile-info p { font-size: 0.9rem; color: #cbd5e1; margin-bottom: 3px; }
.profile-info strong { color: var(--accent-blue); font-weight: 600; }

/* TABS */
.tabs {
    display: flex; background-color: var(--card-bg);
    backdrop-filter: blur(16px); border: 1px solid var(--card-border);
    border-radius: 14px; padding: 4px; margin-bottom: 16px; gap: 4px;
}
.tab {
    flex: 1; text-align: center; padding: 10px 4px; font-size: 0.76rem;
    font-weight: 700; color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.4px; cursor: pointer; transition: 0.25s; border-radius: 10px;
    border: 1px solid transparent;
}
.tab.active {
    color: #fff; background-color: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.45);
}
.tab-content { display: none; animation: fadeIn 0.25s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ITEMS Y BADGES */
.section-title {
    font-size: 0.82rem; font-weight: 700; color: var(--accent-blue);
    letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 12px; padding-left: 2px;
}
.cert-item {
    background-color: rgba(13, 18, 30, 0.75); backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.07); border-radius: 14px;
    padding: 12px 16px; margin-bottom: 8px;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.cert-info { display: flex; flex-direction: column; gap: 3px; }
.cert-name { font-size: 0.98rem; font-weight: 600; color: var(--text-main); }
.cert-date { font-size: 0.82rem; color: var(--text-muted); }

.badge {
    padding: 5px 10px; border-radius: 8px; font-size: 0.74rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px; border: 1px solid; white-space: nowrap; display: inline-block;
}
.badge-green { background-color: var(--green-bg); color: var(--green-text); border-color: var(--green-border); }
.badge-yellow { background-color: var(--yellow-bg); color: var(--yellow-text); border-color: var(--yellow-border); }
.badge-red { background-color: var(--red-bg); color: var(--red-text); border-color: var(--red-border); }

/* FICHA EMERGENCIA */
.emergency-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.emergency-box {
    background: rgba(11, 15, 25, 0.65); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px; padding: 12px;
}
.emergency-box span { display: block; font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; }
.emergency-box strong { display: block; font-size: 1.05rem; color: #fff; margin-top: 3px; }
.blood-badge { color: var(--red-text) !important; font-size: 1.3rem !important; }

/* FORMULARIOS Y BOTONES */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.form-control {
    width: 100%; padding: 11px 13px; border-radius: 12px;
    background: rgba(11, 15, 25, 0.88); border: 1px solid rgba(59, 130, 246, 0.35);
    color: #fff; font-size: 0.92rem; outline: none;
}
.form-control:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2); }

.btn {
    display: inline-block; width: 100%; text-align: center; padding: 11px 16px;
    border-radius: 12px; font-size: 0.88rem; font-weight: 700; cursor: pointer;
    border: none; text-decoration: none; transition: 0.2s;
}
.btn-sm { width: auto; padding: 6px 11px; font-size: 0.76rem; border-radius: 9px; }
.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-primary:hover { background: var(--accent-blue-hover); }
.btn-outline {
    background: rgba(59, 130, 246, 0.14); color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.4);
}
.btn-outline:hover { background: rgba(59, 130, 246, 0.28); color: #fff; }
.btn-danger {
    background: rgba(239, 68, 68, 0.16); color: var(--red-text);
    border: 1px solid rgba(239, 68, 68, 0.38);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.32); color: #fff; }

/* MODALES DE EDICIÓN */
.modal-backdrop {
    display: none; position: fixed; inset: 0; z-index: 999;
    background: rgba(5, 8, 15, 0.82); backdrop-filter: blur(8px);
    align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
    width: 100%; max-width: 520px; background: #101726;
    border: 1px solid var(--card-border); border-radius: 20px; padding: 22px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.7); max-height: 90vh; overflow-y: auto;
}
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-close {
    background: transparent; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer;
}

/* LEYENDA INFERIOR */
.legend-container {
    background-color: rgba(11, 15, 25, 0.95); backdrop-filter: blur(20px);
    border-top: 1px solid var(--card-border);
    padding: 12px 20px; display: flex; justify-content: center; gap: 24px;
    position: fixed; bottom: 0; left: 0; width: 100%; z-index: 100;
}
.legend-item { display: flex; align-items: center; font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-green { background-color: var(--green-text); }
.dot-yellow { background-color: var(--yellow-text); }
.dot-red { background-color: var(--red-text); }

@media (max-width: 640px) {
    .cert-item { flex-direction: column; align-items: flex-start; }
}