* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #f4f5f7;
    color: #1c1e21;
    margin: 0;
}
nav {
    background: #1c2b3a;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.brand-logo {
    height: 34px;
    width: 34px;
    border-radius: 6px;
    object-fit: cover;
}
.login-logo {
    height: 96px;
    width: 96px;
    border-radius: 12px;
    object-fit: cover;
    margin-bottom: 0.5rem;
}
nav a {
    color: #cfd8e3;
    text-decoration: none;
    padding: 1rem 0;
    font-size: 0.95rem;
}
nav a.active, nav a:hover { color: #ffffff; font-weight: 600; }
nav .brand { color: #ffffff; font-weight: 700; margin-right: 1rem; }
.brand-link { display: flex; align-items: center; gap: 0.6rem; padding: 1rem 0; }
.brand-link:hover .brand { color: #ffdb15; }
nav .spacer { flex: 1; }
main { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }
h1 { font-size: 1.4rem; margin-top: 0; }
.card {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
label { display: block; font-weight: 600; margin: 0.75rem 0 0.25rem; font-size: 0.9rem; }
input[type=text], input[type=password], input[type=number], textarea, select {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid #ccd0d5;
    border-radius: 5px;
    font-size: 0.95rem;
}
textarea { min-height: 100px; }
button, .btn {
    background: #ffdb15;
    color: #1c1e21;
    border: none;
    padding: 0.55rem 1rem;
    border-radius: 5px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 0.75rem;
    margin-right: 0.5rem;
    display: inline-block;
    text-decoration: none;
}
button:hover, .btn:hover { background: #f0cf00; }
button.secondary, .btn.secondary { background: #e1e4e8; }
button.danger, .btn.danger { background: #e0245e; color: #fff; }
button.btn-sm, .btn.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; margin-top: 0; }
button.btn-icon, .btn.btn-icon {
    padding: 0.4rem 0.55rem; margin: 0; font-size: 1rem; line-height: 1;
    background: transparent; color: #666;
}
button.btn-icon:hover, .btn.btn-icon:hover { background: #f4e0e6; color: #e0245e; }
button.btn-amazon, .btn.btn-amazon { background: #ff9900; color: #1c1e21; }
button.btn-amazon:hover, .btn.btn-amazon:hover { background: #e08700; }
button.btn-aliexpress, .btn.btn-aliexpress { background: #e62e04; color: #fff; }
button.btn-aliexpress:hover, .btn.btn-aliexpress:hover { background: #c72703; }
table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid #eee; font-size: 0.9rem; }
th { background: #fafafa; }
tr.selected { background: #fff8dd; }
img.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 0.5rem; }
.flash { padding: 0.6rem 0.9rem; border-radius: 5px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash.error { background: #fde2e2; color: #a70000; }
.flash.success { background: #e1f7e1; color: #0a6b0a; }
.flash.warning { background: #fff3cd; color: #7a5b00; }
.hint { color: #65676b; font-size: 0.85rem; margin-top: 0.25rem; }
.hint.limite-excedido { color: #a70000; font-weight: 700; }
.login-wrap { max-width: 340px; margin: 4rem auto; }
.row { display: flex; gap: 1rem; }
.row > * { flex: 1; }
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.kpi-card {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 1.1rem 1.25rem;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.kpi-card:hover { border-color: #ffdb15; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.kpi-card .kpi-value { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.kpi-card .kpi-label { color: #65676b; font-size: 0.85rem; margin-top: 0.25rem; }
.kpi-card.warn .kpi-value { color: #a86b00; }
.kpi-card.error .kpi-value { color: #a70000; }
.weekday-picker { display: flex; gap: 0.5rem; margin: 0.4rem 0 1rem; flex-wrap: wrap; }
.weekday-picker input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }
.weekday-picker label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #e1e4e8;
    color: #1c1e21;
    font-weight: 700;
    font-size: 0.85rem;
    margin: 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}
.weekday-picker input[type=checkbox]:checked + label {
    background: #ffdb15;
}
.weekday-picker input[type=checkbox]:focus-visible + label {
    outline: 2px solid #1c2b3a;
    outline-offset: 2px;
}
.status-badge {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    border-radius: 5px;
    font-weight: 700;
    font-size: 0.9rem;
}
.status-badge.connected { background: #1ea672; color: #fff; }
.status-badge.disconnected { background: #e0245e; color: #fff; }
.status-badge.neutral { background: #8a8f98; color: #fff; }
.status-badge.warning { background: #d99a1b; color: #fff; }


/* ---------------------------------------------------------------- Ali, el robot flotante de AliMeli (ver static/ali.js y web/ali.py) */
.ali { position: fixed; right: 18px; bottom: 14px; z-index: 45; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ali-boton { position: relative; width: 118px; height: 118px; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 50%; }
.ali-boton:focus-visible { outline: 3px solid #ffdb15; outline-offset: 2px; }
.ali-boton img { width: 100%; height: 100%; display: block; object-fit: contain; filter: drop-shadow(0 6px 8px rgba(28, 43, 58, 0.28)); transform-origin: 50% 90%; animation: ali-flota 3.6s ease-in-out infinite; }
.ali-boton:hover img { animation-duration: 1.8s; }
.ali[data-estado="durmiendo"] .ali-boton img { animation-duration: 6s; }
.ali[data-estado="desconectado"] .ali-boton img { animation: none; }
.ali[data-estado="alerta"] .ali-boton img { animation: ali-sacude 2.6s ease-in-out infinite; }
.ali[data-estado="pensando"] .ali-boton img { animation: ali-piensa 1.4s ease-in-out infinite; }
.ali-badge { position: absolute; top: 6px; right: 6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #e53935; color: #fff; font-size: 0.78rem; font-weight: 700; line-height: 22px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.ali-min { position: absolute; right: 0; top: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 0; background: rgba(28, 43, 58, .75); color: #fff; font-size: 14px; line-height: 20px; cursor: pointer; opacity: 0; transition: opacity .15s; }
.ali:hover .ali-min, .ali-min:focus-visible { opacity: 1; }
.ali-burbuja { width: min(320px, calc(100vw - 36px)); background: #fff; color: #1c1e21; border: 1px solid #e1e4e8; border-radius: 14px; padding: 0.8rem 0.95rem; box-shadow: 0 8px 28px rgba(28, 43, 58, .22); font-size: 0.92rem; position: relative; }
.ali-burbuja::after { content: ""; position: absolute; right: 44px; bottom: -8px; width: 14px; height: 14px; background: #fff; border-right: 1px solid #e1e4e8; border-bottom: 1px solid #e1e4e8; transform: rotate(45deg); }
.ali-burbuja p { margin: 0 0 0.4rem; }
.ali-burbuja ul { margin: 0.2rem 0 0.5rem 1.1rem; padding: 0; }
.ali-burbuja li { margin-bottom: 0.2rem; }
.ali-burbuja .ali-pie { margin: 0.4rem 0 0; color: #6b7280; font-size: 0.8rem; }
.ali[data-estado="alerta"] .ali-burbuja, .ali[data-estado="desconectado"] .ali-burbuja { border-color: #e53935; }
/* minimizada: solo el circulo con su carita, para que no estorbe */
.ali[data-min="1"] .ali-boton { width: 52px; height: 52px; background: #ffdb15; box-shadow: 0 3px 10px rgba(28, 43, 58, .35); overflow: hidden; }
.ali[data-min="1"] .ali-boton img { transform-origin: 50% 38%; transform: translateY(6px) scale(2.4); animation: none; filter: none; }
.ali[data-min="1"] .ali-badge { top: -4px; right: -4px; }
.ali[data-min="1"] .ali-min { display: none; }
@keyframes ali-flota { 0%, 100% { transform: translateY(0) rotate(-1.2deg); } 50% { transform: translateY(-7px) rotate(1.2deg); } }
@keyframes ali-sacude { 0%, 70%, 100% { transform: translateY(0) rotate(0); } 74% { transform: rotate(-6deg); } 80% { transform: rotate(6deg); } 86% { transform: rotate(-4deg); } 92% { transform: rotate(3deg); } }
@keyframes ali-piensa { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-3px) rotate(3deg); } }
.login-ali { width: 170px; height: 170px; object-fit: contain; display: block; margin: 0 auto 0.2rem; filter: drop-shadow(0 8px 10px rgba(28, 43, 58, 0.25)); animation: ali-flota 3.6s ease-in-out infinite; }
@media (max-width: 700px) { .ali-boton { width: 92px; height: 92px; } .ali { right: 10px; bottom: 10px; } .login-ali { width: 140px; height: 140px; } }
@media (prefers-reduced-motion: reduce) { .ali-boton img, .login-ali { animation: none !important; } }
@media print { .ali { display: none !important; } }

/* ---- Ali: cajita para escribirle (dentro de la burbuja) ---- */
.ali-form { margin-top: 0.5rem; }
.ali-fila { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.ali-fila input { flex: 1 1 auto; min-width: 0; margin: 0; }
.ali-fila button { margin: 0; flex: 0 0 auto; }
.ali-respuesta { max-height: 14rem; overflow-y: auto; white-space: pre-wrap; word-wrap: break-word; padding: 0.5rem 0.6rem; background: #f4f6f9; border: 1px solid #e1e4e8; border-radius: 8px; font-size: 0.9rem; line-height: 1.4; }
.ali-respuesta.ali-error { background: #fdecec; border-color: #f2b8b8; color: #a70000; }
.ali-form .ali-pie { display: block; margin-top: 0.4rem; font-size: 0.8rem; }

/* ====================== Celular: menu propio (barra de abajo + hoja "Mas") ====================== */
.m-top, .m-tabs, .m-sheet { display: none; }
@media (max-width: 820px) {
    nav:not(.m-tabs) { display: none; }
    html { -webkit-text-size-adjust: 100%; }
    body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
    main { padding: 0.8rem 0.7rem; }
    input, select, textarea { font-size: 16px; }              /* evita que el iPhone acerque la pantalla al escribir */
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .card { padding: 0.8rem; }
    h1 { font-size: 1.35rem; }
    .m-top { display: flex; align-items: center; gap: 0.7rem; position: sticky; top: 0; z-index: 40; background: #1c2b3a; color: #fff; padding: 0.45rem 0.8rem; padding-top: calc(0.45rem + env(safe-area-inset-top)); }
    .m-top-marca { display: flex; align-items: center; gap: 0.45rem; color: #fff; text-decoration: none; font-weight: 700; }
    .m-top-titulo { margin-left: auto; color: #c8d2de; font-size: 0.9rem; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55%; }
    .m-tabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: #fff; border-top: 1px solid #d7dce2; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 8px rgba(28, 43, 58, .1); }
    .m-tab { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem; min-height: 58px; padding: 0.25rem 0.1rem; color: #4a5565; text-decoration: none; background: transparent; border: 0; border-radius: 0; font: inherit; cursor: pointer; margin: 0; }
    .m-tab:hover { background: transparent; }
    .m-tab.activa { color: #1c2b3a; font-weight: 700; box-shadow: inset 0 3px 0 #ffd814; }
    .m-ico { position: relative; font-size: 1.35rem; line-height: 1.5rem; }
    .m-et { font-size: 0.7rem; }
    .m-badge { position: absolute; top: -4px; right: -12px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #e53935; color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 18px; text-align: center; }
    .m-sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 60; }
    .m-sheet-fondo { position: absolute; inset: 0; background: rgba(28, 43, 58, .55); }
    .m-sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 85vh; overflow-y: auto; background: #fff; border-radius: 16px 16px 0 0; padding: 0.8rem 0.9rem calc(1rem + env(safe-area-inset-bottom)); box-shadow: 0 -6px 24px rgba(0, 0, 0, .25); }
    .m-sheet-cabeza { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
    .m-sheet-cabeza .btn-sm { margin-left: auto; }
    .m-sheet-rejilla { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .m-sheet-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; min-height: 78px; padding: 0.4rem 0.2rem; border: 1px solid #e1e4e8; border-radius: 12px; background: #f7f8fa; color: #1c2b3a; text-decoration: none; font-size: 0.8rem; text-align: center; }
    .m-sheet-item.activa { border-color: #ffd814; background: #fff9d6; font-weight: 700; }
    .m-sheet-pie { display: flex; gap: 1rem; justify-content: center; margin-top: 0.8rem; padding-top: 0.6rem; border-top: 1px solid #e1e4e8; }
    .m-sin-scroll { overflow: hidden; }
    .ali { display: none !important; }   /* en el celular el robot flotante estorba (tapa los controles): sus avisos estan en la barra de abajo (Tarjetas) y en la Revision */
    .nav-agente { display: none; }   /* el submenu del Agente repite la barra de abajo */
    .row { flex-wrap: wrap; }
    #mensajes { max-height: calc(100dvh - 24rem) !important; min-height: 10rem; }
    .chat-main { padding-bottom: 1rem !important; }
}

/* Dictado por voz (web/static/voz.js) */
.voz-escuchando { background:#a70000 !important; color:#fff !important; border-color:#a70000 !important; }
.voz-aviso { color:#a70000; flex-basis:100%; }
