:root {
  --bg: #10151b;
  --panel: #17202a;
  --surface: #223140;
  --surface-strong: #263748;
  --ink: #e6edf5;
  --muted: #9bb0c5;
  --line: #35506a;
  --accent: #179b67;
  --warning: #d49a1f;
  --warning-soft: #4b3814;
  --info: #4a9eff;
  --danger: #cf4d4d;
  --accent-ink: #f4fff9;
  --chip: #203244;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -20%, #1f2b2a 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #2c2224 0%, transparent 45%),
    var(--bg);
  height: 100vh;
  overflow: hidden;
}

.app {
  width: min(100%, 1366px);
  margin: 0 auto;
  padding: 10px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.mobile-topbar-row {
  display: none;
}

.mobile-topbar-title h1,
.mobile-topbar-title p {
  margin: 0;
}

.mobile-topbar-title p {
  color: var(--muted);
  font-size: 0.72rem;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.83rem;
}

.controls label,
.controls .muted {
  font-size: 0.8rem;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--ink);
  font-size: 0.8rem;
}

.toggle-availability {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  gap: 8px;
}

.toggle-availability > span:last-child {
  color: #ffb0b0;
}

.toggle-availability input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-slider {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: #334657;
  border: 1px solid #47627c;
  transition: background 140ms ease, border-color 140ms ease;
  flex-shrink: 0;
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e6edf5;
  transition: transform 140ms ease;
}

.toggle-availability input:checked + .switch-slider {
  background: #17392d;
  border-color: #21845f;
}

.toggle-availability input:checked + .switch-slider::after {
  transform: translateX(16px);
}

.toggle-availability input:checked + .switch-slider + span {
  color: #c7ffeb;
}

.toggle input {
  width: auto;
  accent-color: var(--accent);
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 8px;
}

input {
  width: 120px;
}

select {
  min-width: 104px;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header h2 {
  margin: 0;
  font-size: 0.84rem;
}

.chats-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  flex: 1;
}

.chat-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 9px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

.chat-item:hover {
  transform: translateY(-1px);
  background: var(--surface-strong);
}

.chat-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.chat-item-new {
  border-color: var(--warning);
  box-shadow: inset 0 0 0 1px var(--warning);
  background: linear-gradient(180deg, #314253 0%, var(--surface) 100%);
}

.chat-title {
  font-weight: 700;
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.15;
}

.chat-topline,
.chat-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chat-topline {
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-meta {
  margin: 1px 0 0;
  font-size: 0.74rem;
  line-height: 1.25;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.badge-estado-menu,
.badge-estado-cerrada {
  background: #3a2b2d;
  border-color: #7b4b52;
  color: #ffd8de;
}

.badge-estado-en-cola {
  background: var(--warning-soft);
  border-color: #916314;
  color: #ffdf94;
}

.badge-estado-asignada {
  background: #17392d;
  border-color: #21845f;
  color: #c7ffeb;
}

.badge-flujo {
  background: var(--chip);
  border-color: #416281;
  color: #d7e8fb;
}

.badge-new {
  background: #3a3014;
  border-color: var(--warning);
  color: #ffdf94;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
  font-size: 0.76rem;
}

.chat-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.queue-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.queue-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 2px 9px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.queue-card strong {
  font-size: 0.84rem;
}

.queue-card .summary-label {
  font-size: 0.66rem;
  letter-spacing: 0.02em;
}

.summary-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 4px 6px;
  min-height: 42px;
  display: grid;
  gap: 2px;
}

.summary-card strong {
  font-size: 0.76rem;
  word-break: break-word;
}

.summary-label {
  color: var(--muted);
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.historial {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.msg {
  margin-bottom: 7px;
  max-width: 78%;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #2a3541;
  font-size: 0.78rem;
}

.msg-in {
  margin-right: auto;
  background: #243144;
}

.msg-out {
  margin-left: auto;
  background: #1f3a31;
}

.msg-sys {
  margin-left: auto;
  margin-right: auto;
  background: #3a3020;
}

.msg-error {
  border-color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(207, 77, 77, 0.35);
}

.msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.msg-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-link {
  color: #9fd3ff;
  text-decoration: underline;
  font-weight: 600;
}

.msg-link-danger {
  color: #ffb0b0;
}

.msg-media {
  border-style: solid;
}

.msg-media .msg-text {
  display: grid;
  gap: 6px;
}

.msg-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.media-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.msg-media-document {
  background: #334557;
}

.msg-media-image {
  background: #294740;
}

.msg-media-audio {
  background: #5a421c;
}

.msg small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
  font-size: 0.72rem;
}

.composer {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  flex-shrink: 0;
}

.composer-actions {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.composer-actions select {
  min-width: 106px;
}

.sr-only {
  display: none;
}

.modal-template-preview {
  display: block;
  margin-top: 4px;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: left;
}

textarea {
  width: 100%;
  resize: none;
  min-height: 38px;
  max-height: 140px;
  overflow-y: auto;
}

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.74rem;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn-copy-pending,
.btn-copy-success,
.btn-copy-error {
  transition: transform 140ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

.btn-copy-pending {
  transform: scale(0.98);
}

.btn-copy-success {
  background: #1f8f5f;
  border-color: #1f8f5f;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(31, 143, 95, 0.18);
  animation: copy-pop 240ms ease-out;
}

.btn-copy-error {
  background: #a33b3b;
  border-color: #a33b3b;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(163, 59, 59, 0.18);
}

@keyframes copy-pop {
  0% {
    transform: scale(0.96);
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-mobile-back {
  display: none;
}

.btn-mobile-toggle {
  display: none;
}

.chat-meta-section {
  display: contents;
}

.muted {
  color: var(--muted);
}

.selected-chat {
  font-size: 0.79rem;
  margin-bottom: 6px;
  line-height: 1.25;
}

.status {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  flex-shrink: 0;
  font-size: 0.76rem;
}

.hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 15, 0.7);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal-card {
  width: min(480px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.modal-header,
.modal-actions,
.transfer-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.modal-body {
  display: grid;
  gap: 8px;
  max-height: min(320px, 45vh);
  overflow: auto;
}

.modal-body label {
  font-size: 0.74rem;
  color: var(--muted);
}

.modal-body input,
.modal-body textarea {
  width: 100%;
}

.mensaje-detalle-texto {
  min-height: 240px;
  resize: vertical;
  white-space: pre-wrap;
  line-height: 1.45;
}

.transfer-option {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
  cursor: pointer;
}

.transfer-option:hover {
  background: var(--surface-strong);
}

.transfer-option.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.transfer-option strong {
  display: block;
  font-size: 0.88rem;
  color: #fff;
}

.transfer-option small {
  color: var(--muted);
}

.msg-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.msg-detail-trigger {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 8px;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.msg-detail-trigger:hover {
  color: #fff;
  border-color: var(--accent);
}

@media (max-height: 820px) and (min-width: 1000px) {
  .app {
    padding: 8px;
    gap: 6px;
  }

  .topbar,
  .panel {
    border-radius: 10px;
  }

  .topbar {
    padding: 7px 8px;
  }

  .layout {
    grid-template-columns: 286px minmax(0, 1fr);
    gap: 6px;
  }

  .queue-summary {
    gap: 5px;
    margin-bottom: 6px;
  }

  .queue-card,
  .summary-card,
  .chat-item,
  .historial {
    border-radius: 8px;
  }

  .chat-item {
    padding: 7px 8px;
  }

  .msg {
    max-width: 82%;
  }
}

@media (max-width: 900px) {
  body {
    height: 100dvh;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 100dvh;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: hidden;
    min-height: 0;
  }

  .layout-mobile-list .chat-panel {
    display: none;
  }

  .layout-mobile-chat .chats-panel {
    display: none;
  }

  .layout-mobile-list .chats-panel,
  .layout-mobile-chat .chat-panel {
    display: flex;
    height: 100%;
    min-height: 0;
  }

  .btn-mobile-back {
    display: inline-flex;
  }

  .btn-mobile-toggle {
    display: inline-flex;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .mobile-topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-topbar-title {
    flex: 1;
    min-width: 0;
  }

  .brand {
    display: none;
  }

  .topbar.topbar-mobile-collapsed .controls {
    display: none;
  }

  .chat-panel.chat-panel-mobile-collapsed .selected-chat,
  .chat-panel.chat-panel-mobile-collapsed .chat-summary,
  .chat-panel.chat-panel-mobile-collapsed .actions > :not(.btn-mobile-toggle) {
    display: none;
  }

  .chat-panel.chat-panel-mobile-collapsed .panel-header {
    margin-bottom: 2px;
  }

  .chat-panel.chat-panel-mobile-collapsed .chat-header-title {
    gap: 0;
  }

  .chats-panel {
    max-height: none;
  }

  .msg {
    max-width: 92%;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .chat-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 6px;
  }

  .chat-panel {
    min-height: 0;
  }

  .chat-panel .panel-header {
    align-items: center;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
  }

  .chat-panel .actions {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .chat-panel .actions .btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .selected-chat {
    margin-bottom: 4px;
    font-size: 0.72rem;
    line-height: 1.15;
  }

  .summary-card {
    min-height: 0;
    padding: 4px 5px;
    gap: 1px;
  }

  .summary-card strong {
    font-size: 0.7rem;
  }

  .summary-label {
    font-size: 0.5rem;
  }

  .historial {
    min-height: 0;
    flex: 1;
  }

  .composer {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    padding-top: 6px;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .queue-summary {
    grid-template-columns: 1fr;
  }
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  display: grid;
  gap: 10px;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.15rem;
}
