:root {
  --bg: #0f1419;
  --surface: #182028;
  --surface-alt: #1f2933;
  --border: #2c3846;
  --text: #e8eef4;
  --muted: #93a3b5;
  --primary: #25d366;
  --primary-dark: #1da851;
  --danger: #ef4444;
  --warn: #f59e0b;
  --info: #38bdf8;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary);
}

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

.subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
}

.pill.ok {
  border-color: rgba(37, 211, 102, 0.5);
}

.pill.warn {
  border-color: rgba(245, 158, 11, 0.6);
}

.pill.err {
  border-color: rgba(239, 68, 68, 0.6);
}

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

.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.badge {
  background: var(--primary);
  color: #082012;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.grid-2-wide {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.45fr);
  gap: 1rem;
}

.grid-2-inbox {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(380px, 1.5fr);
  gap: 1rem;
}

.grid-2-tight {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 900px) {
  .grid-2,
  .grid-2-wide,
  .grid-2-inbox,
  .grid-2-tight {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.card h3 {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.95rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-header h2 {
  margin: 0;
}

.form-group {
  margin-bottom: 0.8rem;
}

label {
  display: block;
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

input[type='text'],
input[type='password'],
input[type='search'],
input[type='file'],
select,
textarea {
  width: 100%;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 1px solid var(--primary);
  border-color: var(--primary);
}

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.52rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

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

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--primary);
  color: #072011;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--muted);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.row {
  display: flex;
  align-items: center;
}

.wrap {
  flex-wrap: wrap;
}

.gap-xs {
  gap: 0.35rem;
}

.gap-sm {
  gap: 0.6rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stack-xs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.mt-xs {
  margin-top: 0.4rem;
}

.mt-sm {
  margin-top: 0.75rem;
}

.mt-md {
  margin-top: 1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.3rem 0 0;
}

.hidden {
  display: none !important;
}

.alert {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.alert.info {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.4);
}

.alert.warn {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

.alert.err {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.alert.ok {
  background: rgba(37, 211, 102, 0.12);
  border-color: rgba(37, 211, 102, 0.45);
  color: #bbf7d0;
}

.source-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.mode-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.8rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

.chip {
  background: var(--surface-alt);
  color: var(--info);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--info);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.status-tag {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-PENDIENTE {
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

.status-PROCESANDO,
.status-EN_PROCESO {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
}

.status-ENVIADO,
.status-COMPLETADO {
  background: rgba(37, 211, 102, 0.18);
  color: #86efac;
}

.status-ERROR,
.status-COMPLETADO_CON_ERRORES {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

.status-PAUSADO {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.status-CANCELADO {
  background: rgba(100, 116, 139, 0.25);
  color: #94a3b8;
}

.batch-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--surface-alt);
  cursor: pointer;
}

.batch-item.selected {
  border-color: var(--primary);
}

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  margin-top: 0.45rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.25s ease;
}

.conv-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  background: var(--surface-alt);
  cursor: pointer;
}

.conv-item.selected {
  border-color: var(--primary);
}

.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.chat-stream {
  flex: 1;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.msg-bubble {
  max-width: 82%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-bubble.IN {
  align-self: flex-start;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.msg-bubble.OUT {
  align-self: flex-end;
  background: #134e32;
  border: 1px solid rgba(37, 211, 102, 0.35);
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.reply-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.qr-box {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.qr-box img {
  max-width: 240px;
  background: #fff;
  padding: 0.6rem;
  border-radius: 8px;
}

.callout {
  background: rgba(37, 211, 102, 0.08);
  border: 1px solid rgba(37, 211, 102, 0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.84rem;
}

.callout ul {
  margin: 0.4rem 0 0 1.1rem;
  padding: 0;
}

.kv-list {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.88rem;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  cursor: pointer;
}

.checkbox-inline input {
  width: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.login-screen {
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-box {
  width: min(420px, 100%);
  padding: 1.5rem;
}
