/* Panel de Corralón San José. Colores de la marca (logo y PDF): rojo, naranja y gris oscuro.
   El rojo es para la acción principal y lo urgente; el resto va en neutros con un poco del gris de la marca. */
:root {
  --red: #e3262e;
  --red-dark: #b81d24;
  --red-soft: #fdeceb;
  --orange: #f28c28;
  --orange-dark: #9a4f0c;
  --orange-soft: #fef3e7;
  --dark: #2f2b2c;
  --text: #2f2b2c;
  --muted: #736b69;
  --faint: #a39b98;
  --line: #e9e4e1;
  --line-strong: #d8d0cd;
  --bg: #f5f3f1;
  --card: #ffffff;
  --hover: #faf8f7;
  --green: #2c7a33;
  --green-soft: #e7f4e4;
  --violet: #4b4566;
  --violet-soft: #eceaf3;
  --chat-bg: #efeae2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(47, 43, 44, 0.06), 0 1px 6px rgba(47, 43, 44, 0.04);
  --topbar: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--red-dark); text-underline-offset: 2px; }
a:hover { color: var(--red); }
h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
small { font-size: 0.8em; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num, .money { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* --- Barra superior ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px;
  height: var(--topbar); padding: 0 20px;
  background: var(--dark); color: #fff;
  border-bottom: 3px solid var(--red);
}
.brand { flex: none; display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  background: var(--red); color: #fff; font-weight: 800; letter-spacing: 0.5px;
}
.brand-text { display: flex; flex-direction: column; font-weight: 700; line-height: 1.1; }
.brand-text small { color: var(--orange); font-weight: 600; }
/* Solapas: la activa lleva una raya naranja pegada a la línea roja de la barra */
.nav { align-self: stretch; display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav a {
  position: relative; flex: none; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 14px; color: #d9d2d0; text-decoration: none; font-weight: 600;
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.nav a.active { color: #fff; }
.nav a.active::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px;
  border-radius: 3px 3px 0 0; background: var(--orange);
}
.nav-short { display: none; }
.badge {
  min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 0.75rem; font-weight: 700; line-height: 20px; text-align: center;
}
/* Mensajes del mes contra los gratis de Meta (469/1.000) */
.wa-meter {
  padding: 6px 12px; border-radius: 999px; white-space: nowrap;
  background: rgba(255, 255, 255, 0.08); color: #d9d2d0; font-size: 0.85rem; font-variant-numeric: tabular-nums;
}
.wa-meter strong { color: #fff; }
.wa-meter[data-level="warn"] { background: var(--orange); color: #fff; }
.wa-meter[data-level="charged"] { background: var(--red); color: #fff; }
/* Interruptor del bot: verde encendido, rojo apagado (app/conversation/switch.py) */
.bot-switch {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border: 0; border-radius: 999px; cursor: pointer; white-space: nowrap;
  background: rgba(255, 255, 255, 0.08); color: #d9d2d0; font: inherit; font-size: 0.85rem; font-weight: 600;
}
.bot-switch:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.bot-dot { width: 9px; height: 9px; border-radius: 50%; background: #5fd06e; box-shadow: 0 0 0 3px rgba(95, 208, 110, 0.18); }
.bot-switch[data-on="false"] { background: var(--red); color: #fff; }
.bot-switch[data-on="false"] .bot-dot { background: #fff; box-shadow: none; }
.bell {
  padding: 7px 14px; border: 0; border-radius: 8px; cursor: pointer; white-space: nowrap;
  background: var(--orange); color: #fff; font: inherit; font-size: 0.9rem; font-weight: 600;
}
.bell:hover { background: #e07b17; }
.bell.on { background: transparent; color: #bdb5b3; border: 1px solid #5a5455; }
.offline-banner {
  display: none; padding: 8px 20px; text-align: center;
  background: var(--red); color: #fff; font-weight: 600;
}
body.offline .offline-banner { display: block; }
.wa-down-banner {
  padding: 10px 20px; text-align: center;
  background: var(--red-dark); color: #fff; font-weight: 700;
}
.bot-off-banner {
  display: flex; align-items: center; justify-content: center; gap: 8px 14px; flex-wrap: wrap;
  padding: 10px 20px; text-align: center;
  background: var(--red-dark); color: #fff; font-weight: 700;
}
.bot-off-banner .btn { border-color: #fff; background: #fff; color: var(--red-dark); }
.bot-off-banner .btn:hover { background: var(--red-soft); }

/* --- Botones, chips y tarjetas ------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #c4bab6; background: var(--hover); color: var(--text); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); color: #fff; }
.btn-small { padding: 5px 12px; font-size: 0.875rem; }
.btn-danger { color: var(--red-dark); }
/* Acción secundaria de una fila: solo texto */
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { border-color: var(--line); background: #fff; color: var(--text); }
/* «Vendido»: tilde verde */
.btn-sold::before { content: "✓"; color: var(--green); font-weight: 800; }
.btn-sold:hover { border-color: var(--green); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  background: var(--orange-soft); color: var(--orange-dark); font-size: 0.85rem; font-weight: 600;
}
.chip-danger { background: var(--red-soft); color: var(--red-dark); }
.chip-ok { background: var(--green-soft); color: var(--green); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 1.05rem; }
.card-head .hint { color: var(--muted); font-size: 0.85rem; }

.avatar {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--orange-soft); color: var(--orange-dark); font-weight: 700; font-size: 0.95rem;
}
.avatar-big { width: 52px; height: 52px; font-size: 1.1rem; }

/* --- Bandejas de avisos y conversaciones --------------------------------------- */
.inbox {
  display: grid; grid-template-columns: 360px minmax(0, 1fr);
  height: calc(100vh - var(--topbar));
}
.inbox-list {
  display: flex; flex-direction: column; min-height: 0;
  background: #fff; border-right: 1px solid var(--line);
}
/* Con un cartel arriba (bot apagado, WhatsApp desconectado, sin conexión) la bandeja ocupa lo
   que queda de la pantalla: con el alto fijo de arriba quedaba más alta que la pantalla y
   aparecía otra barra de scroll. En el celular (hasta 860 px) la página se corre entera. */
@media (min-width: 861px) {
  body[data-page="avisos"], body[data-page="conversaciones"] { display: flex; flex-direction: column; height: 100vh; }
  body[data-page="avisos"] > *, body[data-page="conversaciones"] > * { flex: none; }
  body[data-page="avisos"] > .page, body[data-page="conversaciones"] > .page { flex: 1; min-height: 0; }
  .page-avisos > .inbox, .page-conversaciones > .inbox { height: 100%; }
}
.segmented {
  display: flex; gap: 4px; margin: 14px; padding: 4px;
  background: var(--bg); border-radius: 10px;
}
.segmented a {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 8px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.segmented a:hover { color: var(--text); }
.segmented a.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.segmented .count {
  min-width: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 0.75rem; line-height: 19px; text-align: center;
}
.alert-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.alert-list > li + li { border-top: 1px solid #f1edeb; }
.alert-item {
  display: flex; gap: 12px; padding: 12px 12px 12px 10px; margin: 2px 0;
  border-radius: 10px; border-left: 3px solid transparent;
  color: var(--text); text-decoration: none;
}
.alert-item:hover { background: var(--hover); color: var(--text); }
.alert-item.selected { background: var(--orange-soft); border-left-color: var(--orange); }
.alert-item.waiting, .alert-item.urgent { border-left-color: var(--red); }
.item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.item-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-top time { flex: none; color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.item-sub {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  color: var(--muted); font-size: 0.875rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-sub > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.alert-item.waiting .item-sub { color: var(--red-dark); font-weight: 600; }
.item-sub.tone-ok { color: var(--green); font-weight: 600; }
.item-sub.tone-urgent { color: var(--red-dark); font-weight: 600; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.item-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; }
.tag {
  padding: 1px 8px; border-radius: 6px; border: 1px solid var(--line);
  font-size: 0.75rem; color: var(--muted); background: #fff; white-space: nowrap;
}
.tag-muted { background: var(--bg); }
.tag-alert { border-color: var(--red-soft); background: var(--red-soft); color: var(--red-dark); }
.tag-money { border: 0; padding: 0; background: none; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Conversaciones: qué está esperando el bot de cada cliente */
.item-preview { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-state { font-weight: 600; }
.conv-waiting { color: var(--orange-dark); }
.conv-person { color: var(--red-dark); }
.conv-ok { color: var(--green); }
.conv-bot, .conv-done { color: var(--muted); }
.chip.conv-bot, .chip.conv-done { background: var(--bg); }
.chip.conv-person { background: var(--red-soft); }
.chip.conv-ok { background: var(--green-soft); }
.list-empty { padding: 32px 16px; color: var(--muted); text-align: center; }

.inbox-detail { overflow-y: auto; min-height: 0; }
.empty-detail {
  display: grid; place-content: center; gap: 4px; height: 100%; padding: 24px;
  text-align: center; color: var(--muted);
}
.empty-detail p { margin: 0; }
.empty-detail::before {
  content: ""; justify-self: center; width: 56px; height: 56px; margin-bottom: 10px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.empty-title { font-size: 1.15rem; font-weight: 700; color: var(--text); }

.detail { display: flex; flex-direction: column; gap: 16px; padding: 22px 28px 32px; max-width: 1480px; }
.back { display: none; align-self: flex-start; font-weight: 600; text-decoration: none; }
.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.who { flex: 1; min-width: 200px; }
.who h1 { font-size: 1.4rem; }
.who p { margin: 2px 0 0; color: var(--muted); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Qué tiene que hacer el vendedor: los motivos del aviso */
.todo {
  padding: 12px 16px; border-radius: var(--radius);
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--orange); box-shadow: var(--shadow);
}
.todo.urgent { border-left-color: var(--red); }
.todo.done { border-left-color: var(--green); }
.todo-title {
  margin: 0 0 6px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted);
}
.todo ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.todo li { display: flex; align-items: baseline; gap: 10px; font-weight: 600; }
.todo li::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); }
.todo li.tone-urgent { color: var(--red-dark); }
.todo li.tone-urgent::before { background: var(--red); }
.todo li.tone-ok { color: var(--green); }
.todo li.tone-ok::before { background: var(--green); }
.todo li.tone-done { color: var(--green); font-weight: 500; }
.todo li.tone-done::before { background: var(--green); }

/* Si el bot sigue contestando, con el botón para pausarlo */
.bot-state {
  display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap;
  padding: 8px 8px 8px 14px; border-radius: 10px;
  background: transparent; border: 1px dashed var(--line-strong); color: var(--muted); font-size: 0.92rem;
}
.bot-state.paused { background: var(--violet-soft); border: 1px solid #d9d5e6; color: var(--violet); font-weight: 600; }

.detail-body { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.orders { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 1280px) {
  .detail-body { grid-template-columns: minmax(0, 1.05fr) minmax(360px, 1fr); align-items: start; }
  /* La charla queda a la vista mientras se recorre el pedido. Su alto se mide contra el panel
     del detalle (cqh) y no contra la ventana: con un cartel arriba (bot apagado, WhatsApp
     desconectado, sin conexión) el panel es más bajo y el último mensaje quedaba cortado.
     La primera medida queda para un navegador que no conozca cqh */
  .inbox-detail { container-type: size; }
  .detail-body > .chat {
    position: sticky; top: 16px;
    display: flex; flex-direction: column;
    max-height: calc(100vh - var(--topbar) - 32px);
    max-height: calc(100cqh - 32px);
  }
  .detail-body > .chat .bubbles { flex: 1; min-height: 0; max-height: none; }
}

/* --- El pedido ---------------------------------------------------------------- */
.order-state { margin-right: auto; }
.table-scroll { overflow-x: auto; }
.order-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.order-table th {
  text-align: left; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 0 8px 8px; border-bottom: 1px solid var(--line);
}
.order-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.order-table tbody td:first-child { font-weight: 700; }
.order-table .num { text-align: right; white-space: nowrap; }
.order-table tfoot td { border-bottom: 0; padding: 5px 8px; color: var(--muted); }
.order-table tfoot tr:first-child td { padding-top: 12px; }
.order-table tfoot tr.total td {
  color: var(--text); font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--dark); padding-top: 10px;
}
.code { color: var(--faint); font-family: ui-monospace, Consolas, monospace; font-size: 0.8em; }
.note { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
/* Las otras formas de pago, debajo del total */
.pay-options { margin: 6px 0 0; padding: 0; font-variant-numeric: tabular-nums; }
.pay-options div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 4px 16px; flex-wrap: wrap;
  padding: 4px 8px; color: var(--muted); font-size: 0.9rem;
}
.pay-options div:nth-child(odd) { background: var(--bg); border-radius: 6px; }
.pay-options dt { margin: 0; }
.pay-options dd { margin: 0 0 0 auto; color: var(--text); font-weight: 600; text-align: right; }
.pay-options small { color: var(--muted); font-weight: 400; }
.order-foot { margin: 10px 0 0; color: var(--muted); font-size: 0.85rem; }
.pending-items {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: var(--red-soft);
}
.pending-items h3 { font-size: 0.95rem; color: var(--red-dark); margin-bottom: 6px; }
.pending-items ul { margin: 0; padding-left: 18px; }
.pending-items li { margin-bottom: 6px; }
.pending-items p { margin: 2px 0 0; color: var(--muted); font-size: 0.875rem; }
.more-pending { margin: 8px 0 0; padding-left: 18px; }
.order-more { background: #fcfbfa; }
.order-more .card-head h2 { font-size: 0.98rem; }

/* --- La charla, en burbujas como en WhatsApp ----------------------------------- */
.chat .bubbles {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 560px; overflow-y: auto; padding: 12px;
  background: var(--chat-bg); border-radius: 10px;
}
.bubble {
  max-width: 82%; padding: 6px 10px 4px; border-radius: 10px;
  background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
.bubble p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.bubble-in { align-self: flex-start; border-top-left-radius: 2px; }
.bubble-out { align-self: flex-end; border-top-right-radius: 2px; background: #fdf0e1; }
.bubble-seller { background: #d9fdd3; }
.bubble-who { display: block; font-size: 0.72rem; font-weight: 700; color: var(--muted); }
.bubble-seller .bubble-who { color: var(--green); }
/* El PDF del presupuesto, arriba del texto como en WhatsApp */
.bubble-pdf {
  display: block; margin: 4px 0 6px; padding: 8px 10px; border-radius: 8px;
  background: #fff; border: 1px solid var(--line); color: var(--red-dark); font-weight: 600; text-decoration: none;
}
.bubble-pdf::before { content: "PDF"; margin-right: 8px; padding: 1px 5px; border-radius: 4px; background: var(--red); color: #fff; font-size: 0.7rem; }
.bubble-pdf:hover { border-color: var(--red); }
.bubble time { display: block; text-align: right; font-size: 0.7rem; color: var(--muted); }

/* --- Páginas con contenido centrado -------------------------------------------- */
.content { max-width: 1100px; margin: 0 auto; padding: 28px 24px 56px; display: flex; flex-direction: column; gap: 18px; }
.content-wide { max-width: 1280px; }
.content > * { min-width: 0; }
.content > header { display: flex; flex-direction: column; gap: 6px; }
.content > header h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
.content > header p { margin: 0; color: var(--muted); max-width: 78ch; }
.content > header.page-head-row { flex-direction: row; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; }
.page-head-row > div:first-child { display: flex; flex-direction: column; gap: 6px; flex: 1 1 32rem; min-width: 0; }

/* Números grandes: tarjetas sueltas (precios) o una franja (pedidos, resumen) */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { padding: 14px 16px; }
.stat strong { display: block; font-size: 1.45rem; }
.stat > span { color: var(--muted); font-size: 0.875rem; }
.stat-warn { border-color: #f6d3ac; background: #fffaf4; }
.stat-warn strong { color: var(--orange-dark); }
.card.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  padding: 0; overflow: hidden;
}
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 16px 20px; border-left: 1px solid var(--line); margin-left: -1px; }
.kpi strong { font-size: 1.75rem; font-weight: 800; line-height: 1.15; letter-spacing: -0.01em; }
.kpi span { color: var(--muted); font-size: 0.875rem; }
.kpi .kpi-extra { color: var(--text); font-weight: 600; }
.kpi.accent strong { color: var(--red); }
.kpi.good strong { color: var(--green); }
a.kpi { color: inherit; text-decoration: none; }
a.kpi:hover { background: var(--hover); }
a.kpi .kpi-go { color: var(--red-dark); font-weight: 600; }

.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 4px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 28px; margin-top: 12px; border: 2px dashed #d7cfcc; border-radius: var(--radius);
  background: var(--hover); text-align: center; cursor: pointer;
}
.dropzone:hover { border-color: var(--orange); }
.dropzone.drag { border-color: var(--orange); background: var(--orange-soft); }
.dropzone input { display: none; }
.dropzone strong { font-size: 1.05rem; }
.notice { padding: 12px 14px; border-radius: 10px; }
.notice-danger { background: var(--red-soft); color: var(--red-dark); }
.notice-ok { background: var(--green-soft); color: var(--green); }
.notice-info { background: var(--orange-soft); color: var(--orange-dark); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.data-table th {
  text-align: left; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); padding: 0 8px 8px; border-bottom: 1px solid var(--line);
}
.data-table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; white-space: nowrap; }
.up { color: var(--red-dark); font-weight: 600; }
.down { color: var(--green); font-weight: 600; }
.status-applied { color: var(--green); font-weight: 600; }
.status-rejected, .status-failed { color: var(--red-dark); font-weight: 600; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 200px; }
.field label { font-weight: 600; font-size: 0.875rem; }
.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
.input:focus { outline: 2px solid var(--orange); outline-offset: -1px; border-color: var(--orange); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.results { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; max-height: 280px; overflow-y: auto; }
.results li { border-bottom: 1px solid var(--line); }
.results li:last-child { border-bottom: 0; }
.results button {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  padding: 8px 12px; border: 0; background: #fff; text-align: left; cursor: pointer; font: inherit; color: var(--text);
}
.results button:hover, .results button.chosen { background: var(--orange-soft); }
.results button:disabled { color: inherit; cursor: default; background: #fff; }
.results button .muted { white-space: nowrap; }
.card-head .input { max-width: 240px; }
details { margin: 4px 0; }
details summary { cursor: pointer; padding: 6px 0; }

/* Período y estado: botones redondeados */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line-strong); background: #fff;
  color: var(--text); font-size: 0.875rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.filter:hover { border-color: #c4bab6; color: var(--text); }
.filter.active { background: var(--dark); border-color: var(--dark); color: #fff; }
.card-head .filters { justify-content: flex-end; }
.nowrap { white-space: nowrap; }
.action-error { margin: 0 0 10px; color: var(--red-dark); font-weight: 600; }

/* --- Pedidos -------------------------------------------------------------------- */
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; justify-content: flex-end; }
.row-link { font-size: 0.875rem; font-weight: 600; white-space: nowrap; color: var(--text); text-decoration-color: var(--line-strong); }
.row-link:hover { color: var(--red-dark); text-decoration-color: currentColor; }
@media (min-width: 861px) { .orders-table .row-actions { flex-wrap: nowrap; } }
.state {
  display: inline-block; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  font-size: 0.8rem; font-weight: 700; background: var(--bg); color: var(--muted);
}
.state-esperando { background: var(--bg); color: var(--muted); }
.state-confirmados { background: var(--orange-soft); color: var(--orange-dark); }
.state-vendidos { background: var(--green-soft); color: var(--green); }
.state-perdidos { background: var(--red-soft); color: var(--red-dark); }
.state-pensar { background: var(--violet-soft); color: var(--violet); }
/* El cliente cambió el pedido y salió otro presupuesto: se ve, pero apagado */
.orders-table tr.replaced td { color: var(--muted); }
.orders-table tr.replaced .c-customer, .orders-table tr.replaced .c-total { font-weight: 400; }
.orders-table tr.replaced .c-total { text-decoration: line-through; }
.orders-table td { vertical-align: middle; }
.orders-table .c-customer { font-weight: 600; }
.orders-table .c-total { font-weight: 700; }
.orders-table .c-meta { display: none; }

/* --- Resumen del mes ------------------------------------------------------------- */
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav .current { padding: 6px 12px; font-weight: 700; }
.month-nav .filter[aria-disabled="true"] { color: var(--faint); pointer-events: none; }
.card.hero {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 0;
  padding: 0; overflow: hidden;
}
.hero-main { padding: 22px 24px; background: var(--dark); color: #fff; display: flex; flex-direction: column; gap: 8px; }
.hero-main .label { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--orange); }
.hero-main strong { font-size: 3.4rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.hero-main p { margin: 0; color: #d9d2d0; max-width: 46ch; }
.hero-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.hero-side .kpi { border-left: 1px solid var(--line); border-top: 1px solid var(--line); margin: 0 0 -1px -1px; }
.summary-grid { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 16px; flex-wrap: wrap; padding: 9px 0; border-bottom: 1px solid var(--line); }
.facts li:last-child { border-bottom: 0; }
.facts .what { color: var(--muted); }
.facts .value { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.facts .value small { color: var(--muted); font-weight: 500; }
.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: minmax(9rem, 12rem) minmax(0, 1fr) auto; align-items: center; gap: 12px; }
.funnel-row .what { color: var(--muted); font-size: 0.92rem; }
.funnel-row .count { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.5rem; text-align: right; }
.funnel-row .count small { color: var(--muted); font-weight: 500; }
.funnel .meter-bar { margin: 0; height: 10px; border-radius: 5px; }
.funnel .meter-bar::-webkit-progress-value { background: var(--dark); border-radius: 5px; }
.funnel .meter-bar::-moz-progress-bar { background: var(--dark); border-radius: 5px; }
/* Presupuestos por día: barras en gris (en horario) y abajo, en naranja, lo que salió con el
   local cerrado. El SVG se estira a lo ancho; el alto queda fijo para que los números del eje calcen. */
.chart-wrap { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 8px; }
.y-axis { position: relative; width: 3ch; height: 160px; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.y-axis span { position: absolute; right: 0; line-height: 1; transform: translateY(-50%); }
.y-top { top: 10px; }
.y-mid { top: 85px; }
.y-zero { top: 160px; }
.chart { display: block; width: 100%; height: 160px; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .in-hours { fill: var(--faint); }
.chart .after-hours { fill: var(--orange); }
.chart .hit { fill: transparent; }
.chart .day:hover .hit { fill: var(--bg); }
.x-axis { display: grid; margin-top: 6px; color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.x-axis span { text-align: center; white-space: nowrap; }
.days-28 { grid-template-columns: repeat(28, minmax(0, 1fr)); }
.days-29 { grid-template-columns: repeat(29, minmax(0, 1fr)); }
.days-30 { grid-template-columns: repeat(30, minmax(0, 1fr)); }
.days-31 { grid-template-columns: repeat(31, minmax(0, 1fr)); }
.chart-table { margin-top: 12px; }
.chart-table summary { color: var(--muted); font-size: 0.875rem; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 0.85rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--faint); }
.legend .after::before { background: var(--orange); }
.method { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }

/* --- Administración --------------------------------------------------------------- */
.admin-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.admin-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
/* Cómo está cada pieza: punto verde o rojo, el nombre y el dato */
.health { list-style: none; margin: 0; padding: 0; }
.health li {
  display: grid; grid-template-columns: 8px minmax(7rem, 11rem) minmax(0, 1fr); align-items: baseline; gap: 2px 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.health li:last-child { border-bottom: 0; }
.health li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--green); transform: translateY(-1px); }
.health li.health-bad::before { background: var(--red); }
.health li.health-warn::before { background: var(--orange); }
.health .name { color: var(--muted); }
.health .value { font-weight: 600; }
.health .value small { display: block; color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.health li.health-bad .value > span:first-child { color: var(--red-dark); }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.ok { color: var(--green); }
.bad { color: var(--red-dark); }
.meter-bar {
  display: block; width: 100%; height: 8px; margin: 6px 0 14px; border: 0; border-radius: 4px;
  appearance: none; background: var(--bg); color: var(--green); overflow: hidden;
}
.meter-bar::-webkit-progress-bar { background: var(--bg); }
.meter-bar::-webkit-progress-value { background: var(--green); }
.meter-bar::-moz-progress-bar { background: var(--green); }
.meter-bar[data-level="warn"]::-webkit-progress-value { background: var(--orange); }
.meter-bar[data-level="warn"]::-moz-progress-bar { background: var(--orange); }
.meter-bar[data-level="charged"]::-webkit-progress-value { background: var(--red); }
.meter-bar[data-level="charged"]::-moz-progress-bar { background: var(--red); }
.big { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.01em; }
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 7.5rem 4.5rem minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.level { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.level-error { color: var(--red-dark); }
.level-aviso { color: var(--orange-dark); }
.level-info { color: var(--faint); }

/* --- Sinónimos ------------------------------------------------------------------- */
.alias-group { padding: 14px 0; border-bottom: 1px solid var(--line); }
.alias-group:last-child { border-bottom: 0; }
.alias-product { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.alias-product .muted { white-space: nowrap; font-variant-numeric: tabular-nums; }
.alias-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.alias-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line);
}
.alias-chip button {
  width: 24px; height: 24px; border: 0; border-radius: 50%; cursor: pointer;
  background: transparent; color: var(--muted); font-size: 1rem; line-height: 1;
}
.alias-chip button:hover { background: var(--red-soft); color: var(--red); }
.alias-chip.learned { background: var(--orange-soft); }

/* --- Ingreso ---------------------------------------------------------------------- */
.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--dark); border-top: 4px solid var(--red); }
.login { width: min(400px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 18px; }
.login-brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.login-brand .brand-mark { width: 44px; height: 44px; font-size: 1.1rem; }
.login-brand strong { display: block; font-size: 1.2rem; }
.login-brand span:not(.brand-mark) { color: var(--orange); font-weight: 600; }
.login-card { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.login-card h1 { font-size: 1.3rem; }
.login-button { width: 100%; padding: 11px; }
.logout { margin: 0; display: flex; align-items: center; }
.logout .who { color: #bdb5b3; font-size: 0.85rem; margin-right: 10px; }
.logout button {
  padding: 7px 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: transparent; color: #d9d2d0; font: inherit;
}
.logout button:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

/* --- Corregir un producto (el vendedor le enseña al bot) ------------------------- */
.link-btn {
  display: inline-block; margin-top: 4px; padding: 0; border: 0; background: none;
  color: var(--red-dark); font: inherit; font-size: 0.85rem; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.link-btn:hover { color: var(--red); }
.fixed { margin-top: 4px; color: var(--green); font-size: 0.85rem; font-weight: 600; }
.fix-form {
  display: flex; flex-direction: column; gap: 10px; margin-top: 14px; padding: 14px;
  border: 1px solid var(--orange); border-radius: 10px; background: var(--orange-soft);
}
.fix-form[hidden] { display: none; }
.fix-title { margin: 0; font-weight: 700; }
.fix-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Panel sin contraseña (PANEL_LOGIN=false, solo en la PC de desarrollo) */
.dev-badge {
  padding: 6px 10px; border-radius: 999px; background: var(--orange-soft); color: var(--orange-dark);
  font-size: 0.78rem; font-weight: 700; white-space: nowrap;
}

/* --- Pantallas angostas y celular ------------------------------------------------- */
@media (max-width: 1560px) {
  .topbar { gap: 14px; }
  .brand-text { display: none; }
  .logout .who { display: none; }
  /* Solo el punto: verde encendido, rojo apagado */
  .bot-switch-state, .dev-badge-more { display: none; }
}
@media (max-width: 1200px) {
  .wa-meter { font-size: 0.8rem; padding: 5px 10px; }
  .card.hero { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1100px) {
  /* La barra en dos renglones: arriba la marca y los botones, abajo las solapas */
  :root { --topbar: 94px; }
  .topbar { flex-wrap: wrap; height: auto; row-gap: 6px; padding-top: 8px; }
  .brand { margin-right: auto; }
  .nav { order: 1; flex: 1 0 100%; align-self: auto; }
  .nav a { min-height: 42px; }
  .summary-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .topbar { gap: 10px; padding: 8px 12px 0; }
  .log li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .nav a { padding: 0 10px; }
  .bell { padding: 6px 10px; font-size: 0.85rem; }
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; min-height: calc(100vh - var(--topbar)); }
  .inbox-list { border-right: 0; }
  .inbox .inbox-detail { display: none; }
  .inbox.has-detail .inbox-list { display: none; }
  .inbox.has-detail .inbox-detail { display: block; }
  .detail { padding: 16px; }
  .back { display: inline-block; }
  .chat .bubbles { max-height: none; }
  .content { padding: 20px 16px 40px; }
  /* Pedidos: cada presupuesto en una tarjeta en vez de una tabla cortada */
  .orders-table thead { display: none; }
  .orders-table, .orders-table tbody { display: block; }
  .orders-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "number state" "customer total" "meta meta" "actions actions";
    gap: 4px 12px; padding: 14px 0; border-bottom: 1px solid var(--line);
  }
  .orders-table tbody tr:last-child { border-bottom: 0; }
  .orders-table td { display: block; padding: 0; border: 0; }
  .orders-table .c-number { grid-area: number; font-weight: 700; }
  .orders-table .c-state { grid-area: state; justify-self: end; }
  .orders-table .c-customer { grid-area: customer; }
  .orders-table .c-total { grid-area: total; text-align: right; }
  .orders-table .c-meta { grid-area: meta; display: block; color: var(--muted); font-size: 0.875rem; }
  .orders-table .c-when, .orders-table .c-delivery, .orders-table .c-items { display: none; }
  .orders-table .c-actions { grid-area: actions; padding-top: 6px; }
  .orders-table .row-actions { justify-content: flex-start; }
  .health li { grid-template-columns: 8px minmax(0, 1fr); }
  .health .value { grid-column: 2; }
  .funnel-row { grid-template-columns: minmax(0, 1fr) auto; }
  .funnel-row .meter-bar { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 600px) {
  :root { --topbar: 136px; }
  /* Precios: el nombre del archivo repite la fecha y saca de la pantalla lo que importa */
  .data-table .c-file { display: none; }
  .bell { display: none; }
  .bot-switch { padding: 6px 10px; }
  /* Las solapas en grilla: todas a la vista, sin correr de costado */
  .nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding-bottom: 6px; overflow: visible; }
  .nav a { min-height: 36px; padding: 0 4px; border-radius: 8px; font-size: 0.875rem; }
  .nav a.active { background: rgba(255, 255, 255, 0.14); }
  .nav a.active::after { display: none; }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  .card { padding: 14px; }
  .card-head .filters { justify-content: flex-start; }
  .card-head .input { max-width: none; }
  .order-table .unit-price { display: none; }
  .order-table td, .order-table th { padding-left: 4px; padding-right: 4px; }
  .card.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 12px 14px; border-top: 1px solid var(--line); margin-top: -1px; }
  .kpi strong { font-size: 1.45rem; }
  .hero-main { padding: 18px; }
  .hero-main strong { font-size: 2.8rem; }
  .hero-side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .content > header h1 { font-size: 1.4rem; }
}
