: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 {
  max-width: 1300px;
  margin: 0 auto;
  padding: 16px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

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

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.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: 8px 10px;
}

input {
  width: 120px;
}

select {
  min-width: 120px;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  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: 8px;
}

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

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

.chat-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  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 0 4px;
}

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

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

.chat-meta {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  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: 32px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--chip);
  border: 1px solid var(--line);
}

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

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

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

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

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

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

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

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

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

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

.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: 4px;
}

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

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

.msg small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

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

textarea {
  width: 100%;
  resize: vertical;
  min-height: 42px;
}

.actions {
  display: flex;
  gap: 8px;
}

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

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

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

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

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

.selected-chat {
  font-size: 0.92rem;
  margin-bottom: 8px;
}

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

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

  .app {
    height: auto;
    min-height: 100vh;
  }

  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .chats-panel {
    max-height: 240px;
  }

  .msg {
    max-width: 92%;
  }

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

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

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

  .chat-summary {
    grid-template-columns: 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;
}
