/* CodInventa WhatsApp Bot – estilos del panel (sobre Bootstrap 5.3) */
:root {
  --ci-blue: #1a6aef;
  --ci-blue-rgb: 26, 106, 239;
  --ci-navy: #070f1e;
  --ci-navy-2: #0c182c;
  --ci-navy-3: #12223c;
  --ci-muted: #a3b2c8;
  --ci-wa-green: #25d366;
  --ci-wa-bg: #efeae2;
  --ci-bubble-out: #d9fdd3;
  --ci-bubble-in: #ffffff;
  --ci-sidebar-w: 248px;

  --bs-primary: var(--ci-blue);
  --bs-primary-rgb: var(--ci-blue-rgb);
  --bs-link-color: var(--ci-blue);
  --bs-link-color-rgb: var(--ci-blue-rgb);
  --bs-link-hover-color: #0f55c9;
  --bs-body-font-family: Inter, 'Inter Variable', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --bs-body-bg: #f4f7fc;
}

[data-bs-theme='dark'] {
  --bs-body-bg: var(--ci-navy);
  --bs-body-color: #e7eef8;
  --bs-secondary-bg: var(--ci-navy-2);
  --bs-tertiary-bg: var(--ci-navy-3);
  --bs-border-color: #1f3150;
  --ci-wa-bg: #0b141a;
  --ci-bubble-out: #005c4b;
  --ci-bubble-in: #202c33;
  --bs-link-color: #5b97ff;
  --bs-link-color-rgb: 91, 151, 255;
}

[data-bs-theme='dark'] .card { --bs-card-bg: var(--ci-navy-2); }
[data-bs-theme='dark'] .text-bg-light { background-color: var(--ci-navy-3) !important; color: #e7eef8 !important; }

.btn-primary {
  --bs-btn-bg: var(--ci-blue);
  --bs-btn-border-color: var(--ci-blue);
  --bs-btn-hover-bg: #0f55c9;
  --bs-btn-hover-border-color: #0f55c9;
  --bs-btn-active-bg: #0d4bb3;
  --bs-btn-active-border-color: #0d4bb3;
  --bs-btn-disabled-bg: var(--ci-blue);
  --bs-btn-disabled-border-color: var(--ci-blue);
}
.btn-outline-primary {
  --bs-btn-color: var(--ci-blue);
  --bs-btn-border-color: var(--ci-blue);
  --bs-btn-hover-bg: var(--ci-blue);
  --bs-btn-hover-border-color: var(--ci-blue);
  --bs-btn-active-bg: var(--ci-blue);
}
.nav-pills { --bs-nav-pills-link-active-bg: var(--ci-blue); }
.form-check-input:checked { background-color: var(--ci-blue); border-color: var(--ci-blue); }
.text-bg-primary { background-color: var(--ci-blue) !important; }
.bg-primary { background-color: var(--ci-blue) !important; }
.text-primary { color: var(--ci-blue) !important; }
.list-group { --bs-list-group-active-bg: var(--ci-blue); --bs-list-group-active-border-color: var(--ci-blue); }
.min-w-0 { min-width: 0; }

/* ------------------------------------------------------------ Estructura */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--ci-sidebar-w);
  background: linear-gradient(180deg, var(--ci-navy) 0%, var(--ci-navy-2) 100%);
  color: #e7eef8;
  display: flex;
  flex-direction: column;
}
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
}
@media (max-width: 991.98px) {
  .sidebar.offcanvas-lg { --bs-offcanvas-width: var(--ci-sidebar-w); --bs-offcanvas-bg: var(--ci-navy); }
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand a { color: #fff; }
.sidebar-brand small { color: var(--ci-muted); font-size: .75rem; }
.sidebar-nav { padding: .75rem .5rem; display: flex; flex-direction: column; gap: 2px; flex-grow: 1; overflow-y: auto; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .7rem;
  color: var(--ci-muted); text-decoration: none;
  padding: .6rem .8rem; border-radius: .6rem; font-size: .925rem;
  transition: background .15s, color .15s;
}
.sidebar-nav a i { font-size: 1.1rem; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: rgba(var(--ci-blue-rgb), .22); color: #fff; box-shadow: inset 3px 0 0 var(--ci-blue); }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .8rem; }

.mode-pill { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .72rem; letter-spacing: .04em; padding: .3rem .65rem; border-radius: 999px; }
.mode-demo { background: rgba(255, 193, 7, .15); color: #e0a800; border: 1px solid rgba(255, 193, 7, .4); }
.mode-whatsapp { background: rgba(37, 211, 102, .15); color: #1fb557; border: 1px solid rgba(37, 211, 102, .45); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020;
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1.25rem;
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  backdrop-filter: blur(6px);
}
.topbar-title { font-size: 1.15rem; font-weight: 600; margin: 0; }
.app-content { padding: 1.25rem; flex: 1; }
@media (max-width: 575.98px) { .app-content { padding: .75rem; } }

.conn-indicator { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; color: var(--bs-body-color); padding: .25rem .6rem; border: 1px solid var(--bs-border-color); border-radius: 999px; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; }
.dot.bg-success { box-shadow: 0 0 0 3px rgba(25, 135, 84, .2); }

.card { border-color: var(--bs-border-color); border-radius: .85rem; }
.card-header { background: transparent; font-weight: 600; }

/* ------------------------------------------------------------ Dashboard */
.stat-card .card-body { position: relative; }
.stat-icon { position: absolute; top: 1rem; right: 1rem; width: 2.4rem; height: 2.4rem; border-radius: .7rem; display: grid; place-items: center; font-size: 1.2rem; }
.stat-label { font-size: .8rem; color: var(--bs-secondary-color); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .35rem; padding-right: 3rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: .8rem; color: var(--bs-secondary-color); margin-top: .35rem; }
.legend { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; vertical-align: middle; margin-right: .2rem; }
.week-chart { display: flex; gap: .5rem; height: 180px; align-items: stretch; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .35rem; }
.week-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--bs-border-color); }
.week-bars .bar { width: 38%; max-width: 22px; min-height: 2px; border-radius: 4px 4px 0 0; transition: height .3s; }
.week-col small { color: var(--bs-secondary-color); font-size: .72rem; text-transform: capitalize; }

/* ------------------------------------------------------------ Centro de atención */
.inbox { display: grid; grid-template-columns: 340px 1fr; gap: 1rem; height: calc(100vh - 7rem); min-height: 480px; }
.inbox-list, .inbox-thread { overflow: hidden; display: flex; flex-direction: column; }
.inbox-items { overflow-y: auto; flex: 1; }
.conv-item { border-left: 3px solid transparent; }
.conv-item.active { border-left-color: #fff; }
.conv-item.active .conv-preview, .conv-item.active .conv-time { color: rgba(255,255,255,.85) !important; }
.conv-preview, .conv-time { color: var(--bs-secondary-color); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: rgba(var(--ci-blue-rgb), .15); color: var(--ci-blue); font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.list-group-item.active .avatar { background: rgba(255,255,255,.25); color: #fff; }
.state-list { list-style: none; padding: 0; margin: 0; }
.state-list li { display: flex; justify-content: space-between; gap: .75rem; padding: .3rem 0; border-bottom: 1px dashed var(--bs-border-color); }
.state-list li span:first-child { color: var(--bs-secondary-color); }
.state-list li span:last-child { text-align: right; font-weight: 500; }
@media (max-width: 991.98px) {
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 6rem); }
  .inbox.has-selection .inbox-list { display: none; }
  .inbox:not(.has-selection) .inbox-thread { display: none; }
}

.chat-body {
  flex: 1; overflow-y: auto; padding: 1rem 1.25rem;
  background-color: var(--ci-wa-bg);
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
  background-size: 18px 18px;
  display: flex; flex-direction: column; gap: .35rem;
}
.bubble-row { display: flex; }
.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 560px); padding: .45rem .65rem .3rem; border-radius: .6rem;
  background: var(--ci-bubble-in); box-shadow: 0 1px .5px rgba(0,0,0,.13);
  font-size: .92rem; overflow-wrap: anywhere;
}
.bubble-row.out .bubble { background: var(--ci-bubble-out); }
.bubble.agent { border-right: 3px solid #f0ad4e; }
.bubble.failed { outline: 1px solid rgba(220, 53, 69, .6); }
.bubble-sender { font-size: .7rem; font-weight: 700; color: #1fa855; text-transform: uppercase; letter-spacing: .03em; }
.bubble.agent .bubble-sender { color: #d58512; }
.bubble-meta { font-size: .68rem; color: var(--bs-secondary-color); text-align: right; margin-top: .1rem; }
.bubble-error { font-size: .75rem; color: #dc3545; margin-top: .2rem; }
.composer textarea { resize: none; max-height: 160px; }

.wa-preview { background: var(--ci-wa-bg); border-radius: 0 0 .85rem .85rem; }
.wa-preview .bubble { max-width: 100%; }
.option-row { padding: .75rem; border: 1px solid var(--bs-border-color); border-radius: .6rem; margin-bottom: .6rem; }

/* ------------------------------------------------------------ Simulador */
.simulator { display: grid; grid-template-columns: 260px minmax(320px, 420px) 1fr; gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .simulator { grid-template-columns: 240px 1fr; } .sim-inspector { grid-column: 1 / -1; } }
@media (max-width: 767.98px) { .simulator { grid-template-columns: 1fr; } }
.sim-contacts .list-group { max-height: 560px; overflow-y: auto; }
.phone-frame {
  border: 10px solid #111; border-radius: 2rem; overflow: hidden;
  height: min(720px, calc(100vh - 12rem)); min-height: 480px;
  display: flex; flex-direction: column; background: var(--ci-wa-bg);
  box-shadow: 0 20px 50px rgba(7, 15, 30, .25);
}
.phone-header { background: #075e54; color: #fff; display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; }
[data-bs-theme='dark'] .phone-header { background: #202c33; }
.phone-header small { color: rgba(255,255,255,.75); font-size: .72rem; }
.avatar-bot { background: #fff; }
.phone-body { flex: 1; overflow-y: auto; padding: .75rem; display: flex; flex-direction: column; gap: .3rem;
  background-image: radial-gradient(rgba(0,0,0,.04) 1px, transparent 1px); background-size: 16px 16px; }
.phone-body .bubble { max-width: 85%; font-size: .88rem; }
.sim-empty { margin: auto; text-align: center; color: var(--bs-secondary-color); font-size: .9rem; padding: 1rem; }
.sim-divider { align-self: center; font-size: .7rem; background: rgba(var(--ci-blue-rgb), .12); color: var(--bs-body-color); padding: .15rem .6rem; border-radius: 999px; margin: .4rem 0; }
.phone-quick { display: flex; gap: .3rem; overflow-x: auto; padding: .4rem .5rem; background: rgba(0,0,0,.03); scrollbar-width: none; }
.phone-quick::-webkit-scrollbar { display: none; }
.phone-quick .btn { white-space: nowrap; border-radius: 999px; font-size: .75rem; }
.phone-composer { display: flex; gap: .4rem; padding: .5rem; background: var(--bs-tertiary-bg); }
.phone-composer .form-control { border-radius: 999px; }
.phone-composer .btn { width: 40px; height: 40px; padding: 0; flex-shrink: 0; background: var(--ci-wa-green); border-color: var(--ci-wa-green); }
.typing { align-self: flex-start; background: var(--ci-bubble-in); border-radius: .6rem; padding: .4rem .7rem; font-size: .8rem; color: var(--bs-secondary-color); }

/* ------------------------------------------------------------ Varios */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(1200px 600px at 10% 10%, rgba(var(--ci-blue-rgb), .25), transparent), linear-gradient(160deg, var(--ci-navy), var(--ci-navy-3)); }
.login-card { width: 100%; max-width: 420px; border-radius: 1.2rem; }
.json-view { max-height: 70vh; overflow: auto; font-size: .8rem; background: var(--bs-tertiary-bg); padding: 1rem; border-radius: .5rem; }
.log-table pre { white-space: pre-wrap; word-break: break-all; max-width: 60ch; }
.toast-container { z-index: 1090; }
