/* ============================================================
   NUDE BEAUTY BAR CRM — "Serene Modern" (Nude Elegance)
   Paleta crema/terracota/salvia + glassmorphism + editorial
   ============================================================ */

:root {
    --bg: #FBF7F3;
    --surface: #FFFFFF;
    --primary: #C0876A;
    --primary-dark: #A97050;
    --accent: #A8C5B9;
    --text: #4A4640;
    --muted: #9CA3AF;
    --border: #ECE3D8;
    --danger: #B91C1C;
    --success: #166534;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px rgba(192,135,106,0.06);
    --radius: 1rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Raleway', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.55;
}

h1, h2, h3, h4, .brand-name {
    font-family: 'Lora', Georgia, serif;
    font-weight: 600;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ LOGIN / AUTH ============ */
.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(900px 400px at 90% -50px, rgba(192,135,106,0.14), transparent 60%),
        radial-gradient(700px 400px at -10% 110%, rgba(168,197,185,0.18), transparent 60%),
        linear-gradient(160deg, #FBF7F3, #F3ECE4);
}
.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1.1fr 1fr;
}
.auth-visual {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem 4rem;
    color: #fff;
    background:
        radial-gradient(800px 500px at 20% 20%, rgba(168,197,185,0.25), transparent 60%),
        linear-gradient(135deg, #2F2A26, #4A4640 60%, #6B5D52);
    overflow: hidden;
}
.auth-brand { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 3rem; }
.auth-logo { background: rgba(255,255,255,0.12); border-color: rgba(255,255,255,0.2); }
.auth-brand-name { color: #fff; font-size: 1.2rem; }
.auth-quote { position: relative; z-index: 1; }
.auth-eyebrow {
    text-transform: uppercase; letter-spacing: 0.25em; font-size: 0.7rem;
    color: var(--accent); font-weight: 600; margin-bottom: 1rem;
}
.auth-quote h1 { font-size: 3rem; line-height: 1.1; margin-bottom: 1.2rem; }
.auth-sub { color: rgba(255,255,255,0.7); max-width: 24rem; font-size: 1rem; font-weight: 300; }
.auth-dots { position: absolute; bottom: 2rem; right: 3rem; display: flex; gap: 0.5rem; }
.auth-dots span { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: rgba(255,255,255,0.35); }
.auth-dots span:nth-child(2) { background: var(--accent); }

.auth-form-col {
    display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.auth-card {
    width: 100%; max-width: 24rem;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border: 1px solid rgba(255,255,255,0.7);
    border-radius: 1.5rem;
    padding: 2.5rem;
    box-shadow: var(--shadow);
}
/* Panel de marca compacto para el login en móvil. En escritorio el logo
   vive en .auth-visual (columna izquierda oscura), pero esa columna se
   oculta por completo debajo de 900px (ver @media abajo) y no quedaba
   ningún logo visible en el login por celular.
   Antes reusaba el degradado oscuro tipo "Editorial Noir" de citas/ —
   se veía feo y desentonaba: el CRM es la paleta cálida crema/terracota
   "Nude Elegance", no ink-black. Ahora es solo el logo (caja blanca,
   sombra suave) flotando sobre el mismo fondo crema de la página — sin
   panel de color, sin texto repetido al lado (el wordmark ya está en la
   imagen). */
.auth-mobile-medallion { display: none; }
@media (max-width: 900px) {
    .auth-mobile-medallion {
        display: flex; align-items: center; justify-content: center;
        margin-bottom: 1.5rem;
    }
    .auth-mobile-medallion .brand-logo {
        width: 7rem; height: 7rem; border-radius: 1.35rem; padding: 0.6rem;
        box-shadow: var(--shadow);
    }
}

.auth-card-head { margin-bottom: 1.75rem; }
.auth-card-head h2 { font-size: 1.6rem; margin-bottom: 0.25rem; }
.auth-card-head p { color: var(--muted); font-size: 0.9rem; }
.auth-foot { margin-top: 1.75rem; text-align: center; color: var(--muted); font-size: 0.75rem; }

/* ============ LAYOUT APP ============ */
.app {
    display: grid;
    grid-template-columns: 250px 1fr;
    min-height: 100vh;
}
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.65rem; padding: 0 0.5rem 1.5rem; }
.mobile-menu-close { display: none; margin-left: auto; background: none; border: none; font-size: 1.2rem; color: var(--muted); cursor: pointer; padding: 0.3rem; }

/* Barra superior + botón de menú: solo existen visualmente en móvil (ver
   media query abajo). En escritorio el sidebar ya está siempre visible. */
.mobile-topbar { display: none; }
.mobile-menu-btn {
    background: var(--surface); border: 1px solid var(--border); border-radius: 0.6rem;
    width: 2.4rem; height: 2.4rem; flex-shrink: 0;
    font-size: 1.15rem; color: var(--text); cursor: pointer;
}
.sidebar-backdrop { display: none; }
.brand-logo {
    width: 2.4rem; height: 2.4rem; border-radius: 0.75rem;
    background: #fff; border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; flex-shrink: 0; padding: 0.3rem;
}
/* El PNG es apaisado (wordmark "nude. BEAUTY BAR" sobre fondo blanco), no
   cuadrado — object-fit:contain para no recortarlo dentro del cuadro chico
   del sidebar/login. Fondo blanco propio (no var(--surface)) porque el PNG
   ya trae fondo blanco sólido; así no se nota el borde del recorte sobre
   el panel oscuro de auth-visual. */
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
/* Versión grande sin texto al lado — el nombre ya vive dentro de la propia
   imagen (wordmark "nude. BEAUTY BAR"), así que repetirlo en un <span>
   aparte era redundante. Usada en el sidebar/topbar del CRM (no en el login,
   que mantiene el tamaño chico junto al texto de marca). */
.brand-logo-lg { width: 3.6rem; height: 3.6rem; border-radius: 1rem; padding: 0.45rem; }
/* En escritorio el sidebar siempre está visible (no hay botón ☰ que
   compartir el ancho con), así que el logo puede ir centrado y más grande.
   Se limita a ≥901px a propósito: debajo de eso .sidebar-brand también es
   la fila del cajón móvil, donde SÍ convive con el botón ✕ de cerrar
   (empujado con margin-left:auto) — centrar ahí lo desalinearía. */
@media (min-width: 901px) {
    .sidebar .sidebar-brand { justify-content: center; padding-bottom: 2rem; }
    .sidebar .brand-logo-lg { width: 6rem; height: 6rem; border-radius: 1.25rem; padding: 0.65rem; }
}
.brand-mark { color: var(--primary); font-family: 'Lora', serif; font-weight: 700; font-size: 1.2rem; }
.sidebar-brand-name { font-size: 1.05rem; }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border-radius: 0.75rem;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 500;
    transition: all .15s;
}
.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link .nav-ico { width: 1.1rem; height: 1.1rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.nav-link .nav-ico svg { width: 100%; height: 100%; }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.sidebar-user { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.5rem; }
.sidebar-user .avatar {
    width: 2rem; height: 2rem; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Lora', serif; font-size: 0.9rem;
}
.sidebar-user-name { font-size: 0.82rem; font-weight: 600; }
.sidebar-user-mail { font-size: 0.72rem; color: var(--muted); }

.main {
    padding: 2rem 2.5rem;
    max-width: 1200px;
    width: 100%;
}
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 2rem;
}
.topbar h1 { font-size: 1.6rem; }
.topbar-sub { color: var(--muted); font-size: 0.85rem; }
.empresa-chip {
    display: inline-flex; align-items: center; gap: 0.5rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 999px; padding: 0.45rem 1rem;
    font-size: 0.82rem; font-weight: 600;
    box-shadow: var(--shadow);
}
.empresa-chip .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; }

/* ============ TARJETAS / GRIDS ============ */
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card {
    background: rgba(255,255,255,0.78);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border: 1px solid var(--border);
    border-top-color: rgba(255,255,255,0.7);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}
.card-kpi .kpi-label {
    font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--primary); font-weight: 700; margin-bottom: 0.5rem;
    display: flex; align-items: center; justify-content: space-between;
}
.card-kpi .kpi-value { font-size: 1.9rem; font-weight: 700; font-family: 'Lora', serif; }
.card-kpi .kpi-ico {
    width: 2rem; height: 2rem; border-radius: 0.6rem;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 0.9rem;
}
/* min-width:0 en los hijos directos: por defecto un hijo de grid tiene
   min-width:auto, así que un descendiente "ancho" (ej. un input
   datetime-local, cuyo control nativo en Android/Chrome no se achica bien)
   puede empujar toda la columna — y con ella la tarjeta completa — más
   allá del viewport en móvil. Encontrado en vivo en Agenda: la tarjeta de
   "Bloqueos" quedaba cortada a la mitad, sin poder hacer scroll para verla
   completa, porque el body tiene overflow-x:hidden. */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.grid-2 > * { min-width: 0; }
.card-title { font-size: 1.05rem; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; }
.card-title a { font-size: 0.78rem; font-weight: 500; }

/* ============ ACORDEÓN (Configuración y similares) ============
   <details>/<summary> nativos en vez de JS: gratis, accesibles (teclado +
   lectores de pantalla) y colapsan solos en móvil sin CSS extra por breakpoint
   — el mismo layout de una columna sirve para escritorio y celular. */
.accordion { display: flex; flex-direction: column; gap: 0.85rem; }
.accordion-item {
    background: rgba(255,255,255,0.78);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border: 1px solid var(--border);
    border-top-color: rgba(255,255,255,0.7);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.accordion-item > summary {
    list-style: none;
    display: flex; align-items: center; gap: 0.85rem;
    padding: 1.15rem 1.5rem;
    cursor: pointer;
    font-family: 'Lora', Georgia, serif;
    font-weight: 600;
    font-size: 1.02rem;
    user-select: none;
}
.accordion-item > summary::-webkit-details-marker { display: none; }
.accordion-item > summary:hover { background: rgba(192,135,106,0.06); }
.accordion-summary-ico {
    width: 2.1rem; height: 2.1rem; border-radius: 0.65rem; flex-shrink: 0;
    background: rgba(192,135,106,0.12); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.accordion-summary-text { flex: 1; min-width: 0; }
.accordion-summary-sub {
    display: block; font-family: 'Raleway', sans-serif; font-weight: 400;
    font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem;
}
.accordion-chevron {
    flex-shrink: 0; width: 1.6rem; height: 1.6rem; color: var(--muted);
    transition: transform .2s ease;
}
.accordion-item[open] > summary .accordion-chevron { transform: rotate(180deg); }
.accordion-item[open] > summary { border-bottom: 1px solid var(--border); }
.accordion-body { padding: 1.5rem; }
@media (prefers-reduced-motion: no-preference) {
    .accordion-item[open] .accordion-body { animation: acordeon-abrir .22s ease; }
}
@keyframes acordeon-abrir {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 560px) {
    .accordion-item > summary { padding: 1rem 1.15rem; font-size: 0.95rem; }
    .accordion-body { padding: 1.15rem; }
}

/* ============ TABLAS ============ */
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th {
    text-align: left; padding: 0.6rem 0.75rem;
    color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}
.table td { padding: 0.7rem 0.75rem; border-bottom: 1px solid #F3EDE5; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FDFAF6; }

/* ============ BADGES ============ */
.badge {
    display: inline-block; padding: 0.25rem 0.65rem; border-radius: 999px;
    font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em;
}
.badge-pendiente { background: #FEF3C7; color: #92400E; }
.badge-pagado { background: #D1FAE5; color: #065F46; }
.badge-anulado { background: #FEE2E2; color: #991B1B; }
.badge-vencido { background: #FED7AA; color: #9A3412; }
.badge-bot { background: #DBEAFE; color: #1E40AF; }
.badge-asignado { background: #EDE9FE; color: #5B21B6; }
.badge-cerrado { background: #F3F4F6; color: #4B5563; }

/* ============ BOTONES ============ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    background: var(--primary); color: #fff; border: none;
    border-radius: 999px; padding: 0.7rem 1.4rem;
    font-family: 'Raleway', sans-serif; font-weight: 600; font-size: 0.88rem;
    cursor: pointer; transition: all .15s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: scale(0.97); transition: transform 100ms ease-out; }
@media (prefers-reduced-motion: reduce) {
    .btn:active { transform: none; }
}
.btn-lg { padding: 0.9rem 2rem; font-size: 1rem; }
.btn-full { width: 100%; }
.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.78rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991B1B; }

/* ============ RADIO PILLS (tipo identificación) ============ */
.tipo-id { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 0.5rem; }
.tipo-id-opt {
    display: flex; align-items: center; justify-content: center; gap: 0.4rem;
    border: 1px solid var(--border); border-radius: 999px;
    padding: 0.55rem 0.4rem; font-size: 0.8rem; font-weight: 600;
    color: var(--muted); cursor: pointer; transition: all .15s;
}
.tipo-id-opt:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }
.tipo-id-opt input { accent-color: var(--primary); }

/* ============ FORMULARIOS ============ */
.form { display: flex; flex-direction: column; gap: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span {
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
/* :not(checkbox/radio) — sin esto, cualquier checkbox/radio anidado dentro
   de un .field (ej. la lista de servicios de "Nueva cita") hereda ancho
   100%/padding/borde de campo de texto y se vuelve una caja gigante en vez
   de un checkbox normal — encontrado en producción el 2026-08-23, rompía
   también la selección de servicios al crear una cita. */
.field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 0.7rem 0.9rem;
    border: 1px solid #D7CFC4;
    border-radius: 0.75rem;
    font-size: 0.92rem;
    font-family: 'Raleway', sans-serif;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
.field input:not([type="checkbox"]):not([type="radio"]):focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(192,135,106,0.15);
}

/* ---- Selector de servicios tipo lista clickeable (ej. "Nueva cita") —
   reemplaza el checkbox plano del navegador por una tarjeta con check
   propio, mismo espíritu que .en-addon-card de loyalty/ pero en la paleta
   del CRM. El <input> sigue siendo el checkbox real (accesible, funciona
   con teclado); solo se oculta visualmente. ---- */
.servicio-picker { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.3rem; }
.servicio-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    transition: border-color .15s, background-color .15s;
}
.servicio-item:hover { border-color: var(--primary); }
.servicio-item input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 1px; height: 1px;
    margin: 0;
}
.servicio-item-check {
    flex-shrink: 0;
    width: 1.15rem; height: 1.15rem;
    border: 2px solid var(--border);
    border-radius: 0.4rem;
    display: flex; align-items: center; justify-content: center;
    transition: background-color .15s, border-color .15s;
}
.servicio-item-check::after {
    content: "";
    width: 0.55rem; height: 0.55rem;
    background: #fff;
    clip-path: polygon(20% 45%, 40% 65%, 80% 20%, 90% 30%, 40% 85%, 10% 55%);
    transform: scale(0);
    transition: transform .12s;
}
.servicio-item input:checked ~ .servicio-item-check {
    background: var(--primary);
    border-color: var(--primary);
}
.servicio-item input:checked ~ .servicio-item-check::after { transform: scale(1); }
.servicio-item:has(input:checked) {
    border-color: var(--primary);
    background: rgba(192, 135, 106, 0.07);
}
.servicio-item input:focus-visible ~ .servicio-item-check {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.grid-2-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ============ FRANJAS DE HORARIO (horario partido) ============ */
.horario-dia { border-bottom: 1px solid var(--border); padding: 0.85rem 0; }
.horario-dia:last-of-type { border-bottom: none; }
.horario-dia-nombre { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.5rem; }
.horario-franjas { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.5rem; }
.horario-franja { display: flex; align-items: center; gap: 0.5rem; }
.horario-franja input[type="time"] { flex: 1; min-width: 0; }
.horario-quitar { flex-shrink: 0; padding: 0.45rem 0.65rem; }
@media (max-width: 420px) {
    .horario-franja { flex-wrap: wrap; }
    .horario-franja input[type="time"] { flex-basis: 40%; }
}

/* ============ ALERTAS ============ */
.alert {
    background: #FEF2F2; color: #B91C1C;
    border: 1px solid #FECACA; border-radius: 0.75rem;
    padding: 0.8rem 1rem; font-size: 0.85rem; margin-bottom: 1rem;
}
.alert-success { background: #F0FDF4; color: #166534; border-color: #BBF7D0; }

/* ============ NUEVA VENTA: selector de clienta ============ */
.buscar-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.buscar-input {
    flex: 1; min-width: 0; padding: 0.7rem 0.9rem;
    border: 1px solid #D7CFC4; border-radius: 0.75rem;
    font-size: 0.92rem; font-family: 'Raleway', sans-serif;
}
.cliente-resultados { display: flex; flex-direction: column; gap: 0.4rem; max-height: 18rem; overflow-y: auto; }
.cliente-resultado-item {
    text-align: left; width: 100%;
    background: var(--bg); border: 1px solid var(--border); border-radius: 0.75rem;
    padding: 0.65rem 0.85rem; font-size: 0.9rem; font-weight: 600; color: var(--text);
    cursor: pointer; transition: all .15s;
}
.cliente-resultado-item:hover, .cliente-resultado-item:active { background: var(--surface); border-color: var(--primary); }
.cliente-seleccionada {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.9rem;
    border: 2px solid var(--accent); border-radius: 0.75rem; background: #F5FBF8; flex-wrap: wrap;
}
.cliente-seleccionada .avatar {
    width: 2.4rem; height: 2.4rem; border-radius: 50%; flex-shrink: 0;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center; font-family: 'Lora', serif;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }

    /* El sidebar completo (nav + selector de empresa + usuario) ya no cabe
       arriba del contenido en un celular sin obligar a hacer scroll para
       ver la página real — se convierte en un cajón lateral que se abre
       con el botón ☰ de la barra superior, en vez de apilarse siempre
       visible como en escritorio. */
    .mobile-topbar {
        display: flex; align-items: center;
        position: sticky; top: 0; z-index: 30;
        gap: 0.75rem; padding: 0.85rem 1rem;
        background: var(--surface); border-bottom: 1px solid var(--border);
    }
    /* Centrado real en toda la barra (no solo en el espacio que le sobra al
       botón ☰): position:absolute + left:50% lo saca del flujo del flex,
       así el ☰ no lo empuja hacia la izquierda. */
    .mobile-topbar .sidebar-brand {
        position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
        min-width: 0;
    }
    .mobile-topbar .mobile-menu-btn { margin-left: auto; }
    .mobile-topbar .sidebar-brand-name {
        flex: 1; min-width: 0;
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .mobile-menu-close { display: block; }
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 50;
        width: min(82vw, 300px); height: 100dvh;
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 0 40px rgba(0,0,0,0.18);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop {
        display: block; position: fixed; inset: 0; z-index: 40;
        background: rgba(28,27,25,0.4);
        opacity: 0; pointer-events: none;
        transition: opacity .2s ease;
    }
    .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
    @media (prefers-reduced-motion: reduce) {
        .sidebar { transition: none; }
        .sidebar-backdrop { transition: none; }
    }

    .auth-shell { grid-template-columns: 1fr; }
    .auth-visual { display: none; }
    .grid-2 { grid-template-columns: 1fr; }
    .main { padding: 1.25rem; }
    /* Sin min-width, .table (width:100%) se aprieta hasta ser ilegible en
       vez de activar el scroll horizontal — encontrado en la tabla de
       Servicios (6 columnas) en móvil, donde el contenido no se veía
       completo. min-width fuerza el ancho real de las columnas y deja que
       sea el contenedor el que scrollee, no el texto el que se aplaste. */
    .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-scroll .table { min-width: 640px; }
    .topbar { flex-wrap: wrap; gap: 0.75rem; }
    .empresa-chip { max-width: 100%; }
    .empresa-chip-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    /* Clientes: en vez de forzar scroll horizontal sobre una tabla de 7
       columnas (ilegible incluso con .table-scroll), debajo de 900px se
       cambia a una lista de tarjetas apiladas — mismos datos, layout
       vertical pensado para el ancho de un celular. */
    .clientes-table-wrap { display: none; }
    .clientes-cards { display: flex; flex-direction: column; gap: 0.75rem; }
}
@media (min-width: 901px) {
    .clientes-cards { display: none; }
}

/* Debajo de ~560px un grid de KPIs de 2 columnas ya no deja suficiente
   espacio por tarjeta (el texto de las etiquetas se aprieta o se corta) —
   forzar una sola columna en vez de dejar que auto-fit intente 2 al límite. */
@media (max-width: 560px) {
    .grid-kpi { grid-template-columns: 1fr; }
    .grid-2-col { grid-template-columns: 1fr; }
}

/* ============ TARJETA DE CLIENTA (listado móvil) ============ */
.cliente-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 0.9rem; padding: 1rem;
}
.cliente-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.6rem; }
.cliente-card-name { font-family: 'Lora', serif; font-weight: 600; font-size: 0.98rem; }
.cliente-card-rows { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.75rem; }
.cliente-card-row { display: flex; gap: 0.4rem; font-size: 0.82rem; color: var(--muted); }
.cliente-card-row strong { color: var(--text); font-weight: 500; }
.cliente-card-fidelidad { margin-bottom: 0.75rem; }
.cliente-card-actions { display: flex; gap: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.75rem; }
.cliente-card-actions .btn { flex: 1; }

/* ============ TARJETA DE LISTA GENÉRICA (Ventas/Pagos/Servicios en móvil) ============
   Mismo patrón visual que .cliente-card, con nombres genéricos para reusar
   en cualquier listado que hoy sea una tabla ancha — evita repetir el mismo
   bloque de CSS por cada página. */
.list-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 0.9rem; padding: 1rem;
}
.list-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.5rem; }
.list-card-title { font-family: 'Lora', serif; font-weight: 600; font-size: 0.95rem; min-width: 0; }
.list-card-rows { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.7rem; font-size: 0.82rem; color: var(--muted); }
.list-card-rows strong { color: var(--text); font-weight: 500; }
.list-card-actions { display: flex; gap: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.list-card-actions .btn { flex: 1; }

/* Toggle genérico tabla↔tarjetas: cada página marca su propia tabla y su
   propio contenedor de tarjetas con estas dos clases (mismo patrón que
   .clientes-table-wrap/.clientes-cards) — así una página que no las use no
   se ve afectada. */
@media (max-width: 900px) {
    .table-to-cards { display: none; }
    .cards-on-mobile { display: flex; flex-direction: column; gap: 0.75rem; }
}
@media (min-width: 901px) {
    .cards-on-mobile { display: none; }
}

/* ============ MODAL "Nueva cita" (crm/paginas/agenda.php) ============
   <dialog> nativo: backdrop, cierre con Escape y foco atrapado vienen gratis
   del navegador — nada de JS de terceros. Soportado en iOS/Safari desde la
   16.4, que ya es la referencia mínima real de este proyecto (ver el resto
   de CSS moderno ya usado, ej. :has()). */
.modal-cita {
    border: none; padding: 0; margin: auto;
    width: min(92vw, 32rem); max-height: 88vh;
    border-radius: 1.25rem; box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    background: var(--surface);
}
.modal-cita::backdrop { background: rgba(28,27,25,0.45); backdrop-filter: blur(2px); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.15rem 1.5rem; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--surface);
    border-radius: 1.25rem 1.25rem 0 0;
}
.modal-header h3 { margin: 0; font-size: 1.05rem; font-family: 'Lora', serif; }
.modal-close {
    background: none; border: none; font-size: 1.3rem; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 0.3rem;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1.5rem; overflow-y: auto; }
@media (max-width: 560px) {
    .modal-cita { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; }
    .modal-header { border-radius: 0; }
}

/* ---------- Animación de entrada/salida de <dialog> (.dialog-sheet) ----------
   El <dialog> sigue siendo la base (backdrop, Escape, foco atrapado vienen
   gratis) — esto solo anima su aparición/desaparición. Un <dialog> no puede
   animar su propio cierre nativo (pasa de "open" a display:none de un
   frame a otro), así que el cierre real de la etiqueta se retrasa con
   setTimeout() hasta que termina la transición de salida (ver JS en
   agenda.php) — la clase "is-open" se agrega un frame después de
   showModal() para que el navegador tenga tiempo de pintar el estado
   inicial antes de animar hacia el final. */
.dialog-sheet {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity .45s cubic-bezier(0.34,1.56,0.64,1), transform .45s cubic-bezier(0.34,1.56,0.64,1);
}
.dialog-sheet.is-open { opacity: 1; transform: translateY(0); }
.dialog-sheet.closing {
    opacity: 0;
    transform: translateY(24px);
    transition-timing-function: cubic-bezier(0.16,1,0.3,1);
}
@media (prefers-reduced-motion: reduce) {
    .dialog-sheet { transition: opacity .2s ease; transform: none !important; }
}

/* Trampa anti-bot: campo señuelo fuera de pantalla (no display:none, para
   que bots simples que solo revisan visibilidad "básica" igual lo llenen) */
.bt-hp {
    position: absolute;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Círculo de iniciales/foto reusado en varias páginas (sidebar, venta nueva,
   bandeja de Instagram) — antes solo .sidebar-user .avatar tenía forma real;
   en cualquier otro lugar el div quedaba sin redondear ni centrar. Base
   única aquí, cada uso solo ajusta el tamaño inline. */
.avatar {
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Lora', serif;
    font-weight: 600;
    flex-shrink: 0;
}

/* ---- Bandeja de Instagram: dos columnas, lista + hilo, sin navegar a otra
   página para ver de qué trata cada conversación ---- */
.chat-shell {
    display: grid;
    grid-template-columns: 22rem 1fr;
    gap: 1.25rem;
    align-items: start;
}
.chat-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 75vh;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.chat-list-empty { color: var(--muted); text-align: center; padding: 2.5rem 1rem; font-size: 0.9rem; }
.chat-list-item {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem;
    border-radius: 0.85rem;
    text-decoration: none;
    color: inherit;
    transition: background .12s ease;
}
.chat-list-item:hover { background: var(--bg); text-decoration: none; }
.chat-list-item.active { background: #F3EDE5; }
.chat-list-item .avatar { width: 2.4rem; height: 2.4rem; font-size: 0.95rem; }
.chat-list-item-body { min-width: 0; flex: 1; }
.chat-list-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.chat-list-item-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list-item-time { font-size: 0.7rem; color: var(--muted); flex-shrink: 0; white-space: nowrap; }
.chat-list-item-preview { font-size: 0.8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0.2rem 0 0.45rem; }
.chat-list-item-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    padding: 0 0.3rem;
    margin-right: 0.4rem;
}
.chat-thread {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    min-height: 75vh;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
}
.chat-thread-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    gap: 0.5rem;
    text-align: center;
}
.chat-thread-empty span { font-size: 2rem; }
.chat-thread-messages { flex: 1; display: flex; flex-direction: column; gap: 0.75rem; overflow-y: auto; padding: 0.25rem; }

@media (max-width: 900px) {
    .chat-shell { grid-template-columns: 1fr; }
    .chat-list { max-height: 22rem; }
    .chat-thread { min-height: 60vh; }
}

/* ---- Toggle switch reusable (on/off), reemplaza checkboxes sueltos donde
   el estado es binario y visible de un vistazo importa (ej. bot activo) ---- */
.toggle-switch { position: relative; display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; user-select: none; }
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-switch .toggle-track {
    width: 2.6rem; height: 1.5rem; border-radius: 999px;
    background: var(--border); transition: background .15s ease; flex-shrink: 0; position: relative;
}
.toggle-switch .toggle-thumb {
    position: absolute; top: 0.15rem; left: 0.15rem;
    width: 1.2rem; height: 1.2rem; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    transition: transform .15s ease;
}
.toggle-switch input:checked + .toggle-track { background: var(--success); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(1.1rem); }
.toggle-switch input:focus-visible + .toggle-track { outline: 2px solid var(--primary); outline-offset: 2px; }
.toggle-switch-label { font-size: 0.85rem; font-weight: 500; }

/* ============================================================
   ACCESIBILIDAD — materiales y transparencia (apple-design §14)
   ============================================================ */
@media (prefers-reduced-transparency: reduce) {
    .card, .auth-card, .auth-visual {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--surface) !important;
    }
}
@media (prefers-contrast: more) {
    .card, .auth-card {
        background: var(--surface);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border: 2px solid var(--text);
    }
}
