:root {
  --azul: #0096C7; --azul-osc: #0A2540; --amarillo: #F5A623; --coral: #D85A30;
  --verde: #1E9E63; --bg: #F4F7FA; --card: #fff; --texto: #1B2A3A; --muted: #6B7C8F; --borde: #DDE5EC;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--texto); font-size: 14px; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 16px; color: var(--azul-osc); }
h1 small { font-size: 14px; color: var(--muted); font-weight: normal; }
h2 { font-size: 16px; margin: 24px 0 10px; color: var(--azul-osc); }
a { color: var(--azul); }
.muted { color: var(--muted); }
.error { color: var(--coral); min-height: 1em; }
.brand { font-weight: 800; font-size: 20px; color: #fff; letter-spacing: .3px; }
.brand span { color: var(--amarillo); }
.brand.big { font-size: 30px; color: var(--azul-osc); }
/* Logo de Herpo (blanco con amarillo: siempre sobre fondo oscuro) */
.brand img { display: block; width: 100%; max-width: 170px; height: auto; }
.brand span, .login-logo span { display: block; font-size: 11px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; color: var(--amarillo); margin-top: 2px; }
.login-logo { background: var(--azul-osc); margin: -32px -32px 8px; padding: 22px 32px 18px; border-radius: 14px 14px 0 0; }
.login-logo img { display: block; width: 220px; max-width: 100%; height: auto; margin: 0 auto; }

#app { display: flex; min-height: 100vh; }
.side { width: 210px; background: var(--azul-osc); padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a { color: #C9D6E3; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; }
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.active { background: var(--azul); color: #fff; font-weight: 600; }
.side .link { margin-top: auto; color: #C9D6E3; }
main { flex: 1; padding: 26px 30px; max-width: 1200px; min-width: 0; }

.badge { background: var(--coral); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.btn { background: var(--azul); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font-size: 14px; cursor: pointer; font-weight: 600; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: #fff; color: var(--azul); border: 1px solid var(--azul); }
.btn.warn { background: var(--amarillo); color: var(--azul-osc); }
.btn.danger { background: var(--coral); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.link { background: none; border: 0; color: var(--azul); cursor: pointer; padding: 0; font-size: 14px; }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--borde); border-radius: 8px; background: #fff; color: var(--texto); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(0,150,199,.25); border-color: var(--azul); }
textarea { width: 100%; min-height: 80px; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 5px; }
label.check { font-weight: normal; display: flex; gap: 8px; align-items: flex-start; }
.full { width: 100%; }

.head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.head h1 { margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radius); padding: 14px 16px; }
.card .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.card .val { font-size: 26px; font-weight: 700; color: var(--azul-osc); margin-top: 4px; }
.card .sub { color: var(--muted); font-size: 12px; }
.panel { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.notice { background: #FFF6E5; border: 1px solid var(--amarillo); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
.notice.err { background: #FCEDE8; border-color: var(--coral); }
.notice.ok { background: #E8F7EF; border-color: var(--verde); }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--borde); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--borde); vertical-align: top; }
th { background: #EEF3F7; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #F4FAFD; }
.table-wrap { overflow-x: auto; }
.tag { display: inline-block; background: #E3F4FA; color: #006F94; border-radius: 6px; padding: 1px 7px; margin: 1px 2px; font-size: 12px; }
.st { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.st.ok, .st.APPROVED, .st.done { background: #E3F6EC; color: #157347; }
.st.warn, .st.PENDING, .st.scheduled, .st.paused { background: #FFF2D9; color: #8A5A00; }
.st.err, .st.REJECTED, .st.cancelled, .st.PAUSED, .st.DISABLED { background: #FCE4DC; color: #A33A16; }
.st.sending { background: #DDF1F9; color: #006F94; }
.st.draft { background: #EEF1F4; color: #55667A; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.progress { height: 8px; background: #E6EDF2; border-radius: 5px; overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--azul); }

.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.wa-preview { background: #E7DED5; border-radius: var(--radius); padding: 14px; }
.wa-bubble { background: #fff; border-radius: 8px; padding: 9px 11px; max-width: 340px; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.1); font-size: 13.5px; }
.wa-bubble .h { font-weight: 700; margin-bottom: 4px; }
.wa-bubble .f { color: var(--muted); font-size: 12px; margin-top: 6px; }
.wa-bubble .media { background: #CFD8DC; color: #546E7A; border-radius: 6px; padding: 26px 10px; text-align: center; margin-bottom: 6px; font-size: 12px; }
.wa-btns { max-width: 340px; }
.wa-btns div { background: #fff; color: #0A84C2; text-align: center; border-radius: 8px; padding: 7px; margin-top: 3px; font-size: 13px; }

.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.varrow { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; align-items: center; margin-bottom: 6px; }
.varrow input, .varrow select { min-width: 0; width: 100%; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { font-weight: normal; margin: 0; border: 1px solid var(--borde); border-radius: 16px; padding: 4px 10px; cursor: pointer; background: #fff; display: flex; gap: 5px; align-items: center; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.inbox { display: grid; grid-template-columns: 300px 1fr; gap: 0; height: calc(100vh - 110px); background: #fff; border: 1px solid var(--borde); border-radius: var(--radius); overflow: hidden; }
.conv-list { border-right: 1px solid var(--borde); overflow-y: auto; }
.conv-list .search { padding: 10px; border-bottom: 1px solid var(--borde); display: flex; gap: 6px; }
.conv { padding: 11px 12px; border-bottom: 1px solid #EEF2F5; cursor: pointer; }
.conv:hover { background: #F4FAFD; }
.conv.active { background: #E3F4FA; }
.conv .n { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.conv .p { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--borde); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; background: #EFEAE2; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 7px 10px; border-radius: 8px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.in { background: #fff; align-self: flex-start; }
.msg.out { background: #D9FDD3; align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; }
.msg.camp { border-left: 3px solid var(--amarillo); }
.thread, .msgs { min-height: 0; } /* para que la conversación tenga su propia barra y baje al último mensaje */
.msg.auto { background: #EAF6FB; }
.chat-img { display: block; max-width: 260px; max-height: 300px; border-radius: 6px; margin-bottom: 4px; }
.chat-doc { display: inline-block; background: rgba(0,0,0,.05); border-radius: 6px; padding: 8px 10px; margin-bottom: 4px; text-decoration: none; }
audio { max-width: 240px; }
.reply-tools { display: flex; gap: 6px; padding: 8px 10px 0; border-top: 1px solid var(--borde); flex-wrap: wrap; }
.reply-tools + .reply { border-top: 0; }
.badge.warn { background: var(--amarillo); color: var(--azul-osc); }
/* Inicio: tarjetas, gráficas y clasificación */
.cards5 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.late-banner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: #FCEDE8; border: 1px solid var(--coral); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; font-size: 13px; }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: #191919; color: #fff; font-size: 12px; line-height: 1.4; padding: 6px 9px; border-radius: 6px; max-width: 240px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.cols-wrap { display: flex; gap: 6px; height: 170px; }
.cols-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: #666; padding-bottom: 18px; text-align: right; min-width: 22px; font-variant-numeric: tabular-nums; }
.cols { flex: 1; display: flex; align-items: stretch; gap: 2px; border-left: 1px solid #c2c2c2; min-width: 0; }
.col { flex: 1; display: flex; flex-direction: column; min-width: 0; cursor: default; }
.col-bar { flex: 1; display: flex; align-items: flex-end; border-bottom: 1px solid #c2c2c2; padding: 0 1px; }
.col-bar i { display: block; width: 100%; max-width: 26px; margin: 0 auto; background: #257de0; border-radius: 4px 4px 0 0; }
.col:hover .col-bar i { background: #1b64be; }
.col-lbl { height: 18px; font-size: 10px; color: #666; text-align: center; white-space: nowrap; overflow: visible; padding-top: 3px; }
.stack { display: flex; gap: 2px; height: 22px; border-radius: 4px; overflow: hidden; margin: 6px 0 10px; }
.stack i { display: block; min-width: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.goal { margin: 6px 0 12px; }
.goal-bar { position: relative; height: 14px; background: #EEF1F4; border-radius: 7px; margin-bottom: 6px; }
.goal-bar i { display: block; height: 100%; border-radius: 7px; }
.goal-bar b { position: absolute; top: -4px; width: 2px; height: 22px; background: #191919; }
.case-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--borde); background: #FAFBFC; font-size: 13px; }
.case-tag { font-size: 12px; }
.msg.sending { opacity: .75; }
.msg.sending.failed { opacity: 1; border: 1px solid var(--coral); }
.bar-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 6px; }
.bar { background: #EEF1F4; border-radius: 6px; height: 12px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--azul); }
.cat-pick { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.panel.quick { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px; margin-bottom: 8px; }
.cat-thumb { width: 100%; max-height: 180px; object-fit: cover; border-radius: 8px; margin-top: 8px; }
.auto-card.off { opacity: .65; }
.conv.store { background: #F2F8FB; border-left: 3px solid var(--azul); }
.store-card { border-left: 4px solid var(--azul); }
.switch { display: flex; gap: 6px; align-items: center; margin: 0; font-weight: 600; cursor: pointer; }
.reply { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--borde); }
.reply textarea { min-height: 42px; height: 42px; }
.photo-btn { font-size: 20px; padding: 0 12px; flex: none; }
.photo-prev { display: block; max-width: 100%; max-height: 50vh; margin: 0 auto 10px; border-radius: 8px; }
.photo-btn + input + .photo-btn { margin-left: -4px; }
.doc-prev { display: flex; gap: 12px; align-items: center; background: #F4F7FA; border-radius: 8px; padding: 14px; margin-bottom: 10px; word-break: break-all; }
.doc-prev > span { font-size: 34px; }
.thread.drop { outline: 3px dashed var(--azul); outline-offset: -6px; }
@media (max-width: 800px) { .photo-btn { padding: 0 9px; font-size: 18px; } }
.notif-btn { margin-top: auto; color: #fff; border-color: rgba(255,255,255,.35); background: transparent; }
.notif-btn + .link { margin-top: 0; }
.delta { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.delta.up { color: var(--verde); }
.delta.down { color: var(--coral); }
.city-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--borde); }
.report input[type=date] { width: auto; }

.modal { position: fixed; inset: 0; background: rgba(10,37,64,.45); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 10; overflow-y: auto; }
.modal-box { background: #fff; border-radius: 12px; padding: 22px; width: 100%; max-width: 560px; position: relative; }
.modal-x { position: absolute; right: 12px; top: 8px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--azul-osc); color: #fff; padding: 12px 18px; border-radius: 8px; z-index: 20; max-width: 420px; }
.toast.err { background: var(--coral); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--azul) 0%, var(--azul-osc) 100%); }
.login-box { background: #fff; padding: 32px; border-radius: 14px; width: 330px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.steps li { margin-bottom: 8px; }
code { background: #EEF3F7; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

@media (max-width: 800px) {
  #app { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 16px; }
  .grid2, .inbox { grid-template-columns: 1fr; }
  /* Celular: lista arriba (corta) y conversación debajo */
  .inbox { height: auto; }
  .conv-list { max-height: 35vh; border-right: 0; border-bottom: 1px solid var(--borde); }
  .thread { height: 70vh; }
  .msg { max-width: 88%; }
  .cards { grid-template-columns: 1fr 1fr; }
  .card .val { font-size: 22px; }
  .bar-row { grid-template-columns: 90px 1fr 32px; }
  .varrow { grid-template-columns: 1fr; }
}

/* Usuarios */
.who { font-size: 12px; padding: 8px 12px; color: rgba(255,255,255,.7); }
.perm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; margin: 8px 0 10px; }
#login-user { margin-bottom: 8px; }

/* Responder citando, leído, nota de voz y video */
.msg { position: relative; }
.msg-reply { position: absolute; top: 4px; right: 4px; border: 0; background: rgba(255,255,255,.85); border-radius: 50%; width: 24px; height: 24px; line-height: 24px; padding: 0; font-size: 13px; cursor: pointer; opacity: 0; transition: opacity .15s; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.msg.in .msg-reply { right: auto; left: calc(100% + 4px); }
.msg.out .msg-reply { right: calc(100% + 4px); }
.msg:hover .msg-reply, .msg-reply:focus { opacity: 1; }
@media (hover: none) { .msg-reply { opacity: .7; } }
.quote { border-left: 3px solid #0096C7; background: rgba(0,0,0,.05); border-radius: 6px; padding: 4px 8px; margin-bottom: 4px; font-size: 12px; display: flex; flex-direction: column; max-width: 100%; }
.quote b { color: #0096C7; font-size: 11px; }
.quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #444; }
.quote[data-goto] { cursor: pointer; }
.quote-bar { display: flex; align-items: center; gap: 8px; margin: 0 10px; padding: 6px 8px 0; }
.quote-bar .quote { flex: 1; min-width: 0; margin: 0; }
.msg.flash { animation: flash 1.5s; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px #FFC107; } 100% { box-shadow: none; } }
.seen { font-size: 11px; color: #0096C7; }
.seen.muted { color: inherit; }
.reply.recording > *:not(.rec-bar) { display: none !important; }
.rec-bar { display: flex; align-items: center; gap: 10px; flex: 1; padding: 4px 6px; }
.rec-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #dc3c3d; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.vr-wrap { position: relative; }
.vr-wrap video { width: 100%; max-height: 55vh; background: #000; border-radius: 8px; }
.vr-time { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); color: #fff; padding: 3px 10px; border-radius: 12px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
/* Caja de texto con 📷 📄 🎥 🎤: si no cabe todo en una línea, el texto va arriba a lo ancho y los botones abajo */
.reply { flex-wrap: wrap; align-items: stretch; }
.reply textarea { flex: 1 1 220px; min-width: 0; }
@media (max-width: 1100px) { .reply textarea { order: -1; flex-basis: 100%; } .reply #b-send { margin-left: auto; } }
