* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
}

:root {
    --azul: #00104a;
    --verde: #8cc63f;
    --fondo: #f2f4f8;
    --tarjeta: #ffffff;
    --borde: #dde2ec;
    --texto: #1c2333;
    --texto-suave: #5b6478;
    --rojo: #d63b3b;
}

body {
    background-color: var(--fondo);
    color: var(--texto);
    min-height: 100vh;
}

/* ---------- LOGIN ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--azul), #0a1d6b);
}

.login-card {
    background: var(--tarjeta);
    width: 360px;
    max-width: 90vw;
    padding: 36px 32px;
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}

.login-card h1 {
    color: var(--azul);
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.login-card .subt {
    color: var(--texto-suave);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.field {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--texto-suave);
}

.field input, .field select {
    padding: 10px 12px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.95rem;
}

.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--verde);
}

.btn {
    display: inline-block;
    background: var(--azul);
    color: #fff;
    border: none;
    padding: 11px 20px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.95rem;
}

.btn:hover { opacity: 0.9; }
.btn.full { width: 100%; }
.btn.verde { background: var(--verde); color: var(--azul); }
.btn.secundario { background: transparent; color: var(--azul); border: 1px solid var(--azul); }
.btn.peligro { background: var(--rojo); }

.msg {
    font-size: 0.85rem;
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    display: none;
}
.msg.error { display: block; background: #fdeaea; color: var(--rojo); }
.msg.ok { display: block; background: #eaf7e0; color: #3f7d1a; }

/* ---------- DASHBOARD ---------- */
.topbar {
    background: var(--azul);
    color: #fff;
    padding: 16px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar .brand { font-weight: 900; font-size: 1.2rem; }
.topbar .brand .verde { color: var(--verde); }
.topbar .acciones { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.topbar a { color: #fff; text-decoration: none; font-size: 0.85rem; opacity: 0.9; }
.topbar a:hover { opacity: 1; text-decoration: underline; }

.contenido {
    max-width: 1100px;
    margin: 24px auto 60px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}

.tarjeta {
    background: var(--tarjeta);
    border: 1px solid var(--borde);
    border-radius: 12px;
    padding: 22px 24px;
}

.tarjeta h2 {
    font-size: 1.05rem;
    color: var(--azul);
    margin-bottom: 4px;
}

.tarjeta .desc {
    font-size: 0.82rem;
    color: var(--texto-suave);
    margin-bottom: 16px;
}

.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fila-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.check-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f2f7;
    font-size: 0.9rem;
}
.check-item:last-child { border-bottom: none; }
.check-item input { width: 18px; height: 18px; }

.hint {
    font-size: 0.78rem;
    color: var(--texto-suave);
    margin-top: 6px;
}

.barra-guardar {
    max-width: 1100px;
    margin: 0 auto 30px;
    padding: 0 20px;
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.estado-conexion {
    font-size: 0.85rem;
    padding: 8px 14px;
    border-radius: 20px;
    background: #eee;
}
.estado-conexion.ok { background: #eaf7e0; color: #3f7d1a; }
.estado-conexion.error { background: #fdeaea; color: var(--rojo); }

.span-2 { grid-column: span 2; }

#mapa-zona {
    height: 340px;
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--borde);
    margin-bottom: 6px;
    background: #e8ebf2;
}

/* ---------- VISTA PREVIA EN VIVO ---------- */
/* Secciones (izquierda), vista previa (centro) y bloque de edición (derecha) */
.editor-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.secciones-panel {
    flex: 0 1 240px;
    min-width: 220px;
}
.secciones-header { display: flex; align-items: center; justify-content: space-between; }
.secciones-header h3 { font-size: 0.95rem; color: var(--azul); margin-bottom: 0; }

.agregar-seccion-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0;
    padding: 10px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    background: #f8f9fc;
}
.agregar-seccion-form .field { margin-bottom: 0; }

.secciones-lista { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.seccion-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    background: #fff;
    cursor: grab;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--texto-suave);
}
.seccion-item:hover { border-color: var(--verde); }
.seccion-item.activo { border-color: var(--verde); color: var(--azul); background: #f2f8ea; }
.seccion-item.arrastrando { opacity: 0.4; }
.seccion-handle { color: var(--texto-suave); cursor: grab; }
.seccion-item .seccion-nombre { flex: 1; }
.seccion-item .btn-mini { flex-shrink: 0; }

.preview-frame-wrap {
    flex: 2 1 380px;
    border: 1px solid var(--borde);
    border-radius: 10px;
    overflow: hidden;
    background: #111;
}

.preview-frame-wrap iframe {
    width: 100%;
    height: 460px;
    border: none;
    display: block;
}

#bloque-editor-host {
    flex: 1 1 320px;
    min-width: 280px;
}

.tarjeta-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 4px;
}
.tarjeta-header-flex h2 { margin-bottom: 0; }

.leyenda-mapa { display: flex; gap: 16px; flex-wrap: wrap; }
.leyenda-mapa span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda-punto {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--borde);
}

/* ---------- PESTAÑAS ---------- */
.tabs {
    max-width: 1100px;
    margin: 22px auto 0;
    padding: 0 20px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--texto-suave);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 12px 16px;
    cursor: pointer;
}

.tab-btn:hover { color: var(--azul); }
.tab-btn.active { color: var(--azul); border-bottom-color: var(--verde); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- SELECTOR DE PLANTILLAS ---------- */
.plantillas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.plantilla-opcion {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 2px solid var(--borde);
    border-radius: 10px;
    padding: 12px;
    cursor: pointer;
    transition: border-color .15s;
}

.plantilla-opcion input { position: absolute; opacity: 0; pointer-events: none; }
.plantilla-opcion.seleccionada { border-color: var(--verde); box-shadow: 0 0 0 2px rgba(140,198,63,0.3); }

.plantilla-preview {
    height: 64px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.plantilla-preview-clasica { background: #8cc63f; }
.plantilla-preview-nocturna { background: #05070a; }
.plantilla-preview-corporativa { background: linear-gradient(135deg, #001233, #023e7d 60%, #0466c8); }
.plantilla-preview-minimal { background: #f5f7fa; border: 1px solid #dde2ec; }

.preview-pildora { height: 12px; border-radius: 8px; margin: 3px 10px; background: #00104a; }
.plantilla-preview-corporativa .preview-pildora { background: rgba(255,255,255,0.3); }
.plantilla-preview-nocturna .preview-pildora { background: #262c35; border: 1px solid rgba(255,183,3,0.4); }

.plantilla-nombre { font-weight: 700; color: var(--azul); font-size: 0.9rem; }
.plantilla-desc { font-size: 0.78rem; color: var(--texto-suave); }

/* ---------- FONDO PERSONALIZADO ---------- */
.fondo-preview-wrap {
    margin-bottom: 12px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--borde);
    max-width: 420px;
}

.fondo-preview-wrap img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: cover;
}

/* ---------- CIUDADES DESTINO ---------- */
.separador-seccion { height: 1px; background: var(--borde); margin: 20px 0; }

.tarjeta h3 {
    font-size: 0.95rem;
    color: var(--azul);
    margin-bottom: 4px;
}

.ciudad-fila {
    display: grid;
    grid-template-columns: 1fr 110px 110px 80px auto auto auto;
    gap: 8px;
    align-items: start;
    margin-bottom: 8px;
}

.ciudad-fila input {
    padding: 8px 10px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.88rem;
    width: 100%;
}

.ciudad-nombre-wrap { position: relative; }

.ciudad-sugerencias {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--borde);
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(0,0,0,0.15);
    max-height: 220px;
    overflow-y: auto;
    z-index: 30;
}

.ciudad-sugerencias.visible { display: block; }

.sugerencia-item {
    padding: 9px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f7;
}
.sugerencia-item:last-child { border-bottom: none; }
.sugerencia-item:hover { background: #f2f4f8; }
.sugerencia-item.sugerencia-vacia { cursor: default; color: var(--texto-suave); }
.sugerencia-item.sugerencia-vacia:hover { background: transparent; }

/* ---------- FRANJAS HORARIAS (frecuencia de Waze por horario) ---------- */
.franja-fila {
    display: grid;
    grid-template-columns: 130px auto 130px auto 80px auto auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}
.franja-fila input {
    padding: 8px 10px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.88rem;
    width: 100%;
}
.franja-fila span { font-size: 0.85rem; color: var(--texto-suave); white-space: nowrap; }

.btn-mini {
    width: 34px;
    height: 34px;
    border: 1px solid var(--borde);
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}
.btn-mini:hover { background: #f2f4f8; }
.btn-mini.peligro { color: var(--rojo); border-color: #f3caca; }

#btn-agregar-ciudad { margin-top: 6px; }

/* ---------- BARRA GUARDAR AL FINAL ---------- */
.barra-guardar-final {
    background: var(--tarjeta);
    border-top: 1px solid var(--borde);
    padding: 20px;
    margin-top: 10px;
}

/* ---------- ORIENTACION (radios tipo pastilla) ---------- */
.orientacion-opciones { display: flex; gap: 10px; }

.radio-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border: 1px solid var(--borde);
    border-radius: 30px;
    font-size: 0.9rem;
    cursor: pointer;
}
.radio-pill input { accent-color: var(--verde); }

/* ---------- LISTADO DE VALLAS ---------- */
.contenido-lista {
    max-width: 1100px;
    margin: 24px auto 60px;
    padding: 0 20px;
}

.lista-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.lista-header h1 { color: var(--azul); font-size: 1.4rem; margin-bottom: 4px; }
.lista-header .desc { font-size: 0.85rem; color: var(--texto-suave); max-width: 560px; }

.vallas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 18px;
}

.valla-card {
    background: var(--tarjeta);
    border: 1px solid var(--borde);
    border-radius: 12px;
    padding: 20px;
}

.valla-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}

.valla-card-header h3 { color: var(--azul); font-size: 1.05rem; }

.valla-badges { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

.badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 20px;
    background: #eef1f8;
    color: var(--azul);
    white-space: nowrap;
}

.valla-url {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.valla-url input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.82rem;
    color: var(--texto-suave);
    background: #f8f9fc;
}

.valla-card-acciones {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
    align-items: center;
}

.valla-card-acciones .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
}

/* ---------- MODAL ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 15, 30, 0.55);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.abierto { display: flex; }

.modal-caja {
    background: var(--tarjeta);
    border-radius: 14px;
    padding: 28px;
    width: 460px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-caja h2 { color: var(--azul); margin-bottom: 6px; }
.modal-caja .desc { font-size: 0.85rem; color: var(--texto-suave); margin-bottom: 18px; }

.modal-acciones {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.modal-caja-mapa { width: 640px; }

#mapa-origen-modal {
    height: 420px;
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--borde);
    background: #e8ebf2;
    cursor: crosshair;
}
