:root {
    --primary: #18181B;
    --primary-dark: #3F3F46;
    --primary-mid: #3F3F46;
    --primary-light: #F4F4F5;
    --primary-lighter: #FAFAFA;
    --bg: #F9FAFB;
    --surface: #FFFFFF;
    --text: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --border-light: #F3F4F6;
    --success: #027A48;
    --success-bg: #ECFDF3;
    --danger: #DC2626;
    --danger-bg: #FEE2E2;
    --danger-border: #FECACA;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 6px;
    --radius-xs: 4px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
img { max-width: 100%; }
.icon { display: block; }

h1, h2, h3 { letter-spacing: -.01em; }

/* ---------- Layout de invitado (login, registro, home, verificación) ---------- */
.guest-shell { min-height: 100vh; display: flex; }

.guest-brand-panel {
    display: none;
    position: relative;
    overflow: hidden;
    flex-direction: column;
    justify-content: space-between;
    width: 42%;
    padding: 48px;
    background: #111827;
    color: #fff;
}
@media (min-width: 960px) { .guest-brand-panel { display: flex; } }

.guest-blob { position: absolute; border-radius: 9999px; filter: blur(80px); opacity: .35; pointer-events: none; }
.guest-blob-1 { width: 340px; height: 340px; background: #6366F1; top: -60px; left: -60px; animation: guestBlob1 16s ease-in-out infinite; }
.guest-blob-2 { width: 340px; height: 340px; background: #10B981; bottom: -50px; right: -50px; animation: guestBlob2 20s ease-in-out infinite; }
@keyframes guestBlob1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(40px, -30px) scale(1.1); }
    66% { transform: translate(-25px, 25px) scale(.95); }
}
@keyframes guestBlob2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(-35px, 20px) scale(.9); }
    66% { transform: translate(30px, -20px) scale(1.05); }
}

.guest-brand-panel .brand { position: relative; color: #fff; }
.guest-brand-panel .brand-mark { background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18); }
.guest-brand-copy { position: relative; }
.guest-brand-copy h1 { font-size: 30px; font-weight: 800; line-height: 1.25; margin: 0 0 12px; }
.guest-brand-copy p { color: #9CA3AF; max-width: 340px; margin: 0; font-size: 14.5px; line-height: 1.6; }
.guest-brand-footer { position: relative; color: #6B7280; font-size: 12px; margin: 0; }

.guest-form-panel { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 20px; }
.guest-form-inner { width: 100%; max-width: 440px; }
.guest-form-inner .card { background: transparent; border: none; box-shadow: none; padding: 0; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); }
.brand-mark {
    width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
/* ---------- Tarjeta genérica ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 32px 28px; box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }
.card p.lead { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }

/* ---------- Formularios ---------- */
label { display: block; margin: 16px 0 6px; font-size: 13px; font-weight: 600; color: var(--text); }
.field {
    width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: #fff; font: inherit; font-size: 13.5px; color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24, 24, 27, .12); }
textarea.field { resize: vertical; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid transparent; border-radius: var(--radius-sm); font: inherit; font-weight: 600; font-size: 13.5px;
    cursor: pointer; padding: 9px 16px; text-decoration: none; transition: background .15s, opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .05); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; margin-top: 22px; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); box-shadow: 0 1px 2px rgba(16, 24, 40, .05); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.btn-danger:hover { background: var(--danger-border); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

.error { color: var(--danger); font-size: 12.5px; margin-top: 5px; }
.alert { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; margin-bottom: 18px; }
.success { background: var(--success-bg); color: var(--success); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; margin-bottom: 18px; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: 13px; }

/* ---------- Shell de la app (panel, formularios de vCard) ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sidebar-logo-text { font-weight: 700; font-size: 16px; color: var(--text); }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); text-decoration: none; font-size: 13.5px; font-weight: 600;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }

.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); }
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logout-btn { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 7px; border-radius: var(--radius-sm); display: flex; text-decoration: none; transition: color .15s, background .15s; }
.logout-btn:hover { color: var(--danger); background: var(--danger-bg); }

.app-main { flex: 1; min-width: 0; }
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    height: 64px; padding: 0 36px; border-bottom: 1px solid var(--border); background: var(--surface);
    position: sticky; top: 0; z-index: 10;
}
.app-header > div { min-width: 0; }
.app-header h2 { margin: 0 0 2px; font-size: 19px; font-weight: 700; }
.app-header p { margin: 0; color: var(--text-muted); font-size: 13px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.app-content { padding: 32px 36px; }

/* ---------- Tarjetas de estadística ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); }
.stat-icon {
    width: 38px; height: 38px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center;
    margin-bottom: 14px;
}
.stat-icon.violet { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-bg); color: var(--success); }
.stat-icon.gray { background: var(--bg); color: var(--text-muted); }
.stat-label { color: var(--text-muted); font-size: 12.5px; margin: 0 0 4px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; margin: 0; }

/* ---------- Panel de listado (vCards) ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 700; }

.vcard-thumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.vcard-thumb-placeholder {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-gray { background: var(--bg); color: var(--text-muted); }
.vcard-actions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; flex-shrink: 0; }
.vcard-actions form { margin: 0; display: flex; }
.icon-btn {
    width: 32px; height: 32px; border-radius: var(--radius-sm); border: none; background: var(--bg);
    color: var(--text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; text-decoration: none;
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .stat-icon { margin: 0 auto 16px; width: 56px; height: 56px; }

/* ---------- Tablas (clonado de Caronte) ---------- */
.table-wrapper { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrapper .table { min-width: 560px; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--surface); padding: 0 16px; height: 50px; text-align: left; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
.table tfoot td { background: var(--surface); padding: 0; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border-light); font-size: 13.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg); }
.table-link { color: var(--primary); text-decoration: none; font-weight: 500; }
.table-link:hover { text-decoration: underline; }
.empty-row { text-align: center; color: var(--text-muted); padding: 40px !important; }
.table-bordered th,
.table-bordered td { border: 1px solid var(--border); }
.table-bordered th:first-child,
.table-bordered td:first-child { border-left: none; }
.table-bordered th:last-child,
.table-bordered td:last-child { border-right: none; }
.table-bordered tr:last-child td { border-bottom: none; }

/* ---------- Paginación (clonado de Caronte) ---------- */
.pagination { display: flex; gap: 4px; justify-content: center; margin: 0; padding: 0; list-style: none; }
.page-link { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-xs); font-size: 13px; color: var(--text-muted); text-decoration: none; }
.page-link:hover, .page-link.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Utilidades de texto ---------- */
.text-xs { font-size: 12px; }
.text-gray { color: var(--text-muted); }

/* ---------- Campos dinámicos (teléfonos/correos) ---------- */
.fila-dinamica { display: flex; gap: 8px; margin-bottom: 10px; }
.fila-dinamica select.field { flex-shrink: 0; width: auto; }
.fila-dinamica input.field { flex: 1; min-width: 0; }
.fila-telefono .pais-select { max-width: 92px; padding-left: 8px; padding-right: 22px; }

/* ---------- Panel lateral (drawer) ---------- */
.drawer-overlay {
    position: fixed; inset: 0; background: rgba(17, 24, 39, .35);
    opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
    z-index: 110;
}
.drawer-overlay.is-open { opacity: 1; visibility: visible; }

.drawer {
    position: fixed; top: 10px; right: 10px; bottom: 10px;
    width: 460px; max-width: calc(100% - 20px);
    background: var(--surface); border-radius: var(--radius-lg);
    box-shadow: 0 8px 32px rgba(16, 24, 40, .18);
    display: flex; flex-direction: column;
    transform: translateX(calc(100% + 20px)); transition: transform .25s cubic-bezier(.4, 0, .2, 1);
    z-index: 120;
}
.drawer.is-open { transform: translateX(0); }

.drawer-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 20px 24px; background: var(--bg); border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; flex-shrink: 0;
}
.drawer-title { font-size: 16px; font-weight: 700; margin: 0; }
.drawer-close {
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    padding: 6px; border-radius: var(--radius-sm); display: flex; flex-shrink: 0;
    transition: background .15s, color .15s;
}
.drawer-close:hover { background: var(--border); color: var(--text); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px 24px; }
.drawer-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 24px; background: var(--bg); border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-shrink: 0;
}
.drawer-body .btn-block { margin-top: 0; }

body.drawer-lock { overflow: hidden; }

@media (max-width: 760px) {
    .app-shell { display: block; }
    .app-main { width: 100%; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .sidebar-logo { border-bottom: none; padding: 0 12px 0 0; flex-shrink: 0; }
    .sidebar-nav { flex-direction: row; padding: 0 8px; }
    .nav-item { white-space: nowrap; }
    .sidebar-user { border-top: none; padding: 0 0 0 8px; flex-shrink: 0; }
    .sidebar-user .user-info { display: none; }
    .app-header, .app-content { padding: 20px; }
    .app-header { height: auto; flex-wrap: wrap; gap: 12px; }
    .guest-form-panel { padding: 32px 20px; }
}
