:root {
    /* Paleta alineada al logo de Merissel: negro + azul #2070CD (sin morado). */
    --bg: #f5f6f8;
    --card-bg: #ffffff;
    --text: #14161c;
    --muted: #667085;
    --border: #e4e6eb;
    --brand: #2070cd;
    --brand-dark: #17548e;
    --brand-light: #eaf2fc;
    --ok: #1a9c5c;
    --warn: #c98a1c;
    --danger: #d1453b;
    --sidebar-bg: #14161c;
    --sidebar-text: #a7abb8;
    --sidebar-active: #2070cd;
    --topbar-h: 64px; /* alto fijo de la barra superior en escritorio (la usan .topbar y los encabezados de tabla fijos) */
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--brand); }

/* ---------- Auth screens (login/registro/verificación) ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.25rem;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1.75rem;
}

.brand-logo img { display: block; height: 30px; width: auto; }
.brand-logo.lockup img { height: 54px; }
.brand-logo.center { justify-content: center; }

.brand-logo .suffix {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--muted);
}

.auth-card h1 {
    font-size: 1.4rem;
    margin: 0 0 0.25rem;
}

.auth-card p.subtitle {
    color: var(--muted);
    margin: 0 0 1.5rem;
    font-size: 0.92rem;
}

.step-indicator {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.4rem;
}

.step-indicator .step-label { color: var(--muted); text-transform: none; font-weight: 500; }

.step-bar {
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin-bottom: 1.75rem;
    overflow: hidden;
}
.step-bar > div {
    height: 100%;
    background: linear-gradient(90deg, var(--brand-dark), var(--brand));
}

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 0.65rem 0.8rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    font-size: 0.95rem;
    font-family: inherit;
}
.field .hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.3rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 0.7rem 1.3rem;
    border-radius: 9px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn.btn-block { width: 100%; }
.btn.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.btn-secondary:hover { background: #eceef2; }
.btn.btn-danger { background: #fff; color: var(--danger); border: 1px solid #f2c9c5; }
.btn.btn-danger:hover { background: #fdf1f0; }

.auth-footer { text-align: center; margin-top: 1.25rem; font-size: 0.88rem; color: var(--muted); }

.alert {
    padding: 0.8rem 1rem;
    border-radius: 9px;
    font-size: 0.88rem;
    margin-bottom: 1.1rem;
}
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c2bb; }
.alert-info { background: #eaf1ff; color: var(--brand-dark); border: 1px solid #c7dafc; }
.alert-success { background: #eafaf0; color: var(--ok); border: 1px solid #b9ecd0; }

.dev-banner {
    background: #fff8e6;
    border: 1px dashed #e8b93a;
    color: #7a5b06;
    padding: 0.75rem 1rem;
    border-radius: 9px;
    font-size: 0.82rem;
    margin-bottom: 1.25rem;
    word-break: break-all;
}

/* ---------- Wizard de alta de marca ---------- */

.wizard-wrap {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 3rem 1rem;
}

.wizard-card {
    width: 100%;
    max-width: 720px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}

.wizard-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}
.wizard-step-label { font-size: 0.78rem; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: 0.03em; }

.option-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.option-card {
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    background: var(--card-bg);
}
.option-card input { display: none; }
.option-card.selected { border-color: var(--brand); background: var(--brand-light); }
.option-card .icon { font-size: 1.4rem; margin-bottom: 0.35rem; }

.check-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.6rem;
}
.check-row.locked { opacity: 0.55; }
.check-row input[type=checkbox] { margin-top: 0.2rem; }
.check-row .title { font-weight: 600; font-size: 0.92rem; }
.check-row .desc { font-size: 0.82rem; color: var(--muted); }

.badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    background: var(--brand-light);
    color: var(--brand-dark);
    margin-left: 0.4rem;
}
.badge-lock { background: #f1f2f4; color: var(--muted); }
.badge-ok { background: #e5f8ee; color: var(--ok); }
.badge-warn { background: #fdf1de; color: var(--warn); }

.wizard-actions { display: flex; justify-content: space-between; margin-top: 1.5rem; }

.summary-block { border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.summary-block h4 { margin: 0 0 0.4rem; font-size: 0.9rem; }
.summary-block .value { color: var(--muted); font-size: 0.9rem; }

/* ---------- App shell (sidebar + topbar) ---------- */

body.app-body { background: var(--bg); }

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    transition: width 0.15s ease;
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.sidebar-brand img { display: block; height: 18px; width: auto; }
.sidebar-toggle {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 7px;
    border: 1px solid #33363f;
    background: #1f2129;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-toggle:hover { color: #fff; border-color: #4b4f5c; }

.brand-switcher { margin-bottom: 1.25rem; }
.brand-switcher select {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    border: 1px solid #262932;
    background: #1f2129;
    color: #fff;
    font-size: 0.85rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.88rem;
}
.sidebar-nav a:hover { background: #1f2129; color: #fff; }
.sidebar-nav a .icon { display: flex; align-items: center; flex-shrink: 0; }
.sidebar-nav a .icon svg { width: 19px; height: 19px; flex-shrink: 0; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }

.sidebar-footer { border-top: 1px solid #262932; padding-top: 1rem; margin-top: 1rem; }
.sidebar-add-brand { display: block; text-align: center; padding: 0.5rem; border: 1px dashed #33363f; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; font-size: 0.82rem; margin-bottom: 0.9rem; }
.sidebar-add-brand:hover { color: #fff; border-color: #4b4f5c; }
.sidebar-user { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.sidebar-user .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.sidebar-user .name { color: #fff; font-size: 0.85rem; font-weight: 600; }
.sidebar-user .email { font-size: 0.75rem; color: #8b8f9c; }
.sidebar-logout { display: flex; align-items: center; gap: 0.5rem; color: #8b8f9c; text-decoration: none; font-size: 0.8rem; }
.sidebar-logout:hover { color: #fff; }

/* ---------- Menú contraído (botón «/» en .sidebar-brand) ----------
   Un solo interruptor por elemento: .label se esconde y .icon-only se
   muestra — así cada bloque del sidebar (nav, "nueva marca", equipo,
   usuario, cerrar sesión) solo necesita marcar su texto con la clase
   que corresponda, sin una regla nueva por cada uno. */
.icon-only { display: none; }
html.sidebar-collapsed .label { display: none; }
html.sidebar-collapsed .icon-only { display: inline-block; }
html.sidebar-collapsed .sidebar { width: 68px; padding-left: 0.6rem; padding-right: 0.6rem; }
html.sidebar-collapsed .sidebar-brand { justify-content: center; }
html.sidebar-collapsed .sidebar-brand img { display: none; }
html.sidebar-collapsed .brand-switcher { display: none; }
html.sidebar-collapsed .sidebar-nav a { justify-content: center; padding: 0.55rem 0; }
html.sidebar-collapsed .sidebar-add-brand { display: flex; align-items: center; justify-content: center; }
html.sidebar-collapsed .sidebar-user { justify-content: center; margin-bottom: 0.5rem; }
html.sidebar-collapsed .sidebar-logout { justify-content: center; font-size: 1rem; }

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

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    /* Barra superior fija: se queda arriba mientras se desplaza el contenido. */
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar h1 { font-size: 1.25rem; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.plan-pill { white-space: nowrap; }
.plan-pill { background: var(--brand-light); color: var(--brand-dark); font-size: 0.78rem; font-weight: 700; padding: 0.3rem 0.7rem; border-radius: 999px; }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.82rem; }

.content { padding: 1.75rem; max-width: 1200px; }

.demo-banner {
    background: #fff8e6;
    border: 1px solid #f0d68a;
    color: #7a5b06;
    padding: 0.7rem 1rem;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.25rem; }
.stat-card .label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 800; }

.panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; }
.panel h2 { font-size: 1rem; margin: 0 0 1rem; }
.panel .empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; text-align: center; }

/* Contenedor de alto fijo para un gráfico de tipo dona/pastel (Chart.js).
   Sin esto, un <canvas> responsive con "maintainAspectRatio" (default) en
   un contenedor tan ancho como .panel calcula su alto a partir de TODO ese
   ancho, quedando gigante aunque el canvas tenga un max-width propio — el
   max-width limita el ancho visible pero no el alto, dejando un bloque
   altísimo con mucho espacio en blanco. Se usa junto con la opción
   "maintainAspectRatio: false" en el new Chart(...) correspondiente. */
.chart-box { max-width: 300px; height: 260px; }

.stat-card .value a, .data-table td a.value-link { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--muted); }
.stat-card .value a:hover, .data-table td a.value-link:hover { border-bottom-color: var(--brand); }

.modal-overlay { position: fixed; inset: 0; background: rgba(20, 24, 32, 0.55); display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 50; }
.modal-card { background: var(--card-bg); border-radius: 14px; padding: 1.5rem 1.75rem; max-width: 560px; width: 100%; max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal-card h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }

/* Overlay de "trabajando" mientras se analiza un sitio (evita doble clic
   y le avisa al usuario que sí está pasando algo mientras espera). */
.loading-overlay { position: fixed; inset: 0; background: rgba(15, 18, 25, 0.72); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; z-index: 70; padding: 1.5rem; text-align: center; }
.loading-overlay.hidden { display: none; }
.loading-overlay .loading-spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.25); border-top-color: #fff; animation: geo-spin 0.8s linear infinite; }
.loading-overlay .loading-text { color: #fff; font-size: 0.95rem; font-weight: 600; max-width: 320px; line-height: 1.5; }
@keyframes geo-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .loading-overlay .loading-spinner { animation: none; border-top-color: rgba(255,255,255,0.25); }
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data-table th, table.data-table td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); }
table.data-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }

.tag { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; }
.tag-positive { background: #eafaf0; color: var(--ok); }
.tag-neutral { background: #eef1f6; color: var(--muted); }
.tag-negative { background: #fdecea; color: var(--danger); }
.tag-alta { background: #fdecea; color: var(--danger); }
.tag-media { background: #fff4e0; color: var(--warn); }
.tag-baja { background: #eef1f6; color: var(--muted); }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.25rem; }
.plan-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; padding: 1.5rem; display: flex; flex-direction: column; }
.plan-card.current { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.plan-card .price { font-size: 1.9rem; font-weight: 800; margin: 0.5rem 0; }
.plan-card .price span { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.plan-card ul { list-style: none; padding: 0; margin: 1rem 0; flex: 1; }
.plan-card li { font-size: 0.86rem; padding: 0.3rem 0; color: var(--text); }
.plan-card li:before { content: "✓ "; color: var(--ok); font-weight: 700; }
.plan-engine-icons { display: flex; gap: 0.35rem; margin: 0.25rem 0 0 1.1rem; }
.plan-engine-icon { font-size: 1.05rem; line-height: 1; }

/* Selector Mensual/Anual arriba de .plan-grid en billing.php — un grupo
   de radios estilizado como "segmented control", con el radio real
   invisible encima del texto (accesible por teclado/lector de pantalla)
   en vez de solo JS manejando clases. */
.cycle-toggle { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem; margin-bottom: 1.25rem; gap: 0.15rem; }
.cycle-option { position: relative; display: block; }
.cycle-option input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.cycle-option span { display: block; padding: 0.45rem 1.1rem; border-radius: 999px; font-size: 0.86rem; font-weight: 600; color: var(--muted); cursor: pointer; transition: background 0.15s ease, color 0.15s ease; white-space: nowrap; }
.cycle-option input:checked + span { background: var(--brand); color: #fff; }
.cycle-option input:focus-visible + span { outline: 2px solid var(--brand-dark); outline-offset: 2px; }

/* Nota cuando el ciclo anual está seleccionado pero ese plan todavía no
   tiene precio anual capturado en admin-plans.php — reemplaza al botón
   de suscripción (ver el JS de billing.php) para no dejar mandar un
   cambio de plan sin un monto real que cobrar. */
.plan-annual-note { font-size: 0.82rem; color: var(--muted); text-align: center; margin: 0; padding: 0.7rem 0; }

/* Campo "¿Tienes un código de descuento?" arriba de .plan-grid en
   billing.php — ancho acotado (si no, .field input hereda width:100%
   y se ve raro de tan ancho junto al selector Mensual/Anual, que es
   angosto). */
.promo-field { max-width: 360px; margin: 0 0 1.5rem; }

/* ---------- Desplazamiento independiente (escritorio) ----------
   El "app shell" ocupa exactamente la altura de la ventana y NO se desplaza.
   Cada zona tiene su propio scroll: el menú lateral (.sidebar) por un lado y
   el área principal (.app-main) por otro. La barra superior (.topbar) queda
   fija arriba del área principal, y los encabezados de las tablas de datos
   se quedan pegados justo debajo de ella. */
@media (min-width: 861px) {
    html, body.app-body { height: 100%; }
    body.app-body { overflow: hidden; }

    .app-shell { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

    .sidebar {
        height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: #3a3e4a transparent;
    }
    .sidebar > * { flex-shrink: 0; }
    .sidebar .sidebar-nav { flex: 1 0 auto; }
    .sidebar::-webkit-scrollbar { width: 8px; }
    .sidebar::-webkit-scrollbar-thumb { background: #3a3e4a; border-radius: 8px; }

    .app-main { height: 100%; overflow-y: auto; overscroll-behavior: contain; }
    .app-main > * { flex-shrink: 0; }

    .topbar { height: var(--topbar-h); padding-top: 0; padding-bottom: 0; }

    /* Encabezados de tabla fijos al desplazar el contenido. Sirve en las
       tablas que no están dentro de un contenedor con scroll horizontal
       (overflow-x:auto): dentro de uno, el encabezado se queda con la tabla. */
    table.data-table thead th {
        position: sticky;
        top: var(--topbar-h);
        z-index: 5;
        background: var(--card-bg);
        border-bottom: 0;
        box-shadow: inset 0 -1px 0 var(--border);
    }
}

@media (max-width: 860px) {
    .sidebar { display: none; }
    .content { padding: 1.1rem; }
}

@media (max-width: 600px) {
    .topbar { padding: 0.7rem 1rem; gap: 0.6rem; }
    .topbar h1 { font-size: 1.05rem; }
    .topbar-right { gap: 0.5rem; }
    .plan-pill { font-size: 0.72rem; padding: 0.25rem 0.55rem; }
}

/* ---------- Páginas legales (privacidad / términos) ---------- */

.legal-wrap { min-height: 100vh; padding: 2.5rem 1rem; display: flex; justify-content: center; }
.legal-card {
    width: 100%;
    max-width: 760px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2.5rem 3rem;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}
.legal-card .brand-logo { margin-bottom: 2rem; }
.legal-card h1 { font-size: 1.6rem; margin: 0 0 0.4rem; }
.legal-card .legal-updated { color: var(--muted); font-size: 0.85rem; margin: 0 0 2rem; }
.legal-card h2 { font-size: 1.05rem; margin: 1.9rem 0 0.7rem; }
.legal-card p { margin: 0 0 0.9rem; font-size: 0.92rem; line-height: 1.65; }
.legal-card ul { margin: 0 0 0.9rem; padding-left: 1.2rem; }
.legal-card li { font-size: 0.92rem; line-height: 1.65; margin-bottom: 0.35rem; }
.legal-card a { color: var(--brand); }
.legal-footer { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--muted); text-align: center; }
.legal-footer a { color: var(--muted); text-decoration: underline; }

/* Enlaces legales al pie de la app (dentro del área de contenido, no del sidebar) */
.app-footer-links { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); text-align: center; }
.app-footer-links a { color: var(--muted); }
.app-footer-copyright { margin-top: 0.4rem; font-size: 0.8rem; font-family: inherit; font-weight: inherit; color: var(--muted); text-align: center; width: 100%; }
