/* ─────────────────────────────────────────────────────────────
   Marketplace (nombre provisorio) — hoja de estilos
   Shell compartido (Fase 0.5): tokens, layout base, auth, botones,
   formularios, modal genérico, badges. Cada fase agrega sus propias
   secciones a partir de acá — sin sobre-diseñar por adelantado.
   ───────────────────────────────────────────────────────────── */

:root {
    --color-bg: #f7f8fa;
    --color-surface: #ffffff;
    --color-border: #e2e6ea;
    --color-text: #1f2933;
    --color-text-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-success: #16a34a;
    --color-success-bg: #dcfce7;
    --color-warning: #d97706;
    --color-warning-bg: #fef3c7;
    --color-danger: #dc2626;
    --color-danger-bg: #fee2e2;
    --color-neutral-bg: #f1f5f9;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", Consolas, monospace;
}

/* ── Reset suave ──────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--color-neutral-bg);
    padding: 1px 5px;
    border-radius: 3px;
}

/* ── Pantalla de autenticación ────────────────────────────── */
.auth-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    min-height: 100vh;
}

/* CRÍTICO: hidden debe poder ocultar auth-screen, app-wrap y modales.
   El display:flex de arriba y de .modal-overlay anularían el atributo
   hidden sin esta regla. */
.auth-screen[hidden],
#app-wrap[hidden],
.modal-overlay[hidden] {
    display: none !important;
}

.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 2rem;
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.auth-card h2 {
    text-align: center;
    font-size: 1.4rem;
    color: var(--color-primary);
    margin-bottom: 0.25rem;
}

.auth-sub {
    text-align: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 1.25rem;
}

.auth-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.82rem;
    margin-bottom: 1rem;
    line-height: 1.4;
}

.auth-msg {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    min-height: 1.2em;
}

.auth-msg.error { color: var(--color-danger); }
.auth-msg.ok { color: var(--color-success); }

.auth-switch {
    text-align: center;
    font-size: 0.85rem;
    margin-top: 1rem;
    color: var(--color-text-muted);
}

.auth-switch a {
    color: var(--color-primary);
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ── Header con usuario ───────────────────────────────────── */
.app-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.app-header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-primary);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-badge {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    background: var(--color-neutral-bg);
    padding: 0.3rem 0.7rem;
    border-radius: 20px;
    font-weight: 600;
}

/* ── Navegación ───────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.5rem;
    overflow-x: auto;
}

.tab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 0.85rem 1.2rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
    color: var(--color-text);
}

.tab-active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

/* ── Layout principal ─────────────────────────────────────── */
.app-main {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.panel {
    display: none;
    animation: fadeIn 0.2s ease;
}

.panel-active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Formularios ──────────────────────────────────────────── */
form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

textarea {
    resize: vertical;
}

/* ── Checkboxes / radios: tamaño cómodo de clickear ────────── */
input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    flex: none;
}

/* ── Botones ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
}

.btn-secondary {
    background: var(--color-neutral-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

.btn-xs {
    padding: 0.25rem 0.55rem;
    font-size: 0.75rem;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ── Cajas de estado ──────────────────────────────────────── */
.status-box {
    margin-top: 0.75rem;
    padding: 0.65rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.status-info {
    background: var(--color-neutral-bg);
    color: var(--color-text);
}

.status-success,
.status-ok {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.status-warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.status-error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-yes {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.badge-no {
    background: var(--color-neutral-bg);
    color: var(--color-text-muted);
}

.badge-unknown,
.badge-warn {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}
.badge-info {
    background: rgba(37, 99, 235, 0.12);
    color: var(--color-primary);
}
.badge-danger {
    background: rgba(220, 38, 38, 0.12);
    color: #dc2626;
}

/* Contenedor liviano para agrupar sub-secciones dentro de un panel
   (ej. "Generar con IA", "Semáforo" en los perfiles de prospección). */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
}
.card h3 {
    margin: 0 0 0.4rem;
}

/* El dropdown de autocompletado de Google Places debe quedar por encima
   del modal de alta manual. */
.pac-container {
    z-index: 100000 !important;
}

/* Rueda de carga + banner prominente (para acciones con IA que tardan). */
@keyframes mp-spin {
    to { transform: rotate(360deg); }
}
.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: mp-spin 0.7s linear infinite;
    flex: none;
}
.loading-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding: 1rem 1.25rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary);
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: var(--radius);
}
/* `display:flex` de arriba le gana al atributo `hidden` del navegador; esta
   regla más específica restablece que `hidden` vuelva a ocultar el banner
   (si no, se quedaría "pegado" al terminar la acción). */
.loading-banner[hidden] {
    display: none;
}

/* Dos campos lado a lado (ej. latitud/longitud). */
.form-row {
    display: flex;
    gap: 0.5rem;
}
.form-row > div {
    flex: 1;
}

/* Mapa de Google en "Buscar prospectos" (portado de Scope). */
.map-canvas {
    width: 100%;
    height: 380px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

/* ── Modales (overlay/card/header/body/footer) ─────────────
   Genérico: cualquier modal usa este mismo esqueleto de clases,
   abierto/cerrado con openModal(id)/closeModal(id) (app.js) — no un
   par de funciones open/close por cada modal. ────────────────── */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 2rem 1rem;
    overflow-y: auto;
}

.modal-card {
    background: #fff;
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

/* El <form> dentro de .modal-card debe heredar el flex chain para que
   modal-body y modal-footer se estructuren bien (scroll, footer fijo). */
.modal-card > form {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.modal-lg {
    max-width: 850px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
}

.modal-body label {
    display: block;
    margin-top: 0.75rem;
}

.modal-body input:not([type="checkbox"]):not([type="radio"]),
.modal-body select,
.modal-body textarea {
    margin-top: 0.25rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* ── Panel general (superadmin) ───────────────────────────── */
.overview-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1rem 0 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.1;
}

.stat-label {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.stat-sub {
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.overview-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.overview-cols h3 {
    margin-bottom: 0.75rem;
}

/* Selector de estado compacto (tabla de Empresas / global admin). */
.status-select {
    width: auto;
    padding: 0.2rem 0.4rem;
    font-size: 0.8rem;
    margin: 0;
}

/* Barra de filtros de las vistas globales (Clientes / Órdenes). */
.admin-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.admin-filters select,
.admin-filters input {
    width: auto;
    max-width: 240px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
    margin: 0;
}

/* ── Órdenes: tarjeta clicable + zona de peligro ──────────── */
.order-card { transition: box-shadow 0.12s, border-color 0.12s; }
.order-card:hover {
    border-color: var(--color-primary);
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.10);
}

.danger-zone { border-color: var(--color-danger); }
.danger-zone h3 { color: var(--color-danger); }

/* ── "Tomar pedido": listas de cliente/empresa ─────────────── */
.take-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-top: 0.25rem;
}

.take-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid var(--color-border);
    padding: 0.5rem 0.65rem;
    cursor: pointer;
}

.take-row:last-child { border-bottom: none; }
.take-row:hover { background: var(--color-neutral-bg); }

.take-selected {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.65rem;
    background: var(--color-neutral-bg);
    border-radius: var(--radius);
    margin-top: 0.25rem;
}

/* ── Notificaciones (campana + badge + bandeja) ───────────── */
.notif-wrap { position: relative; }

.notif-bell {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem;
}

.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.notif-dropdown {
    position: absolute;
    right: 0;
    top: 2.25rem;
    width: 340px;
    max-width: 90vw;
    max-height: 420px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 200;
}

.notif-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.notif-head a { color: var(--color-primary); cursor: pointer; font-size: 0.8rem; }

.notif-item {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
}

.notif-item:hover { background: var(--color-neutral-bg); }
.notif-unread { background: #eff5ff; }

/* ── Banner de impersonación ("Ingresar como…") ───────────── */
.impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.5rem 1rem;
    background: var(--color-warning-bg);
    color: var(--color-warning);
    border-bottom: 1px solid var(--color-warning);
    font-size: 0.9rem;
    font-weight: 600;
}

.impersonation-banner .btn {
    background: var(--color-warning);
    color: #fff;
    border-color: var(--color-warning);
}

/* ── Footer ───────────────────────────────────────────────── */
.app-footer {
    text-align: center;
    padding: 1.25rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 700px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-overlay {
        padding: 0;
    }

    .modal-card {
        max-height: 100vh;
        border-radius: 0;
    }

    .overview-cols {
        grid-template-columns: 1fr;
    }
}
