:root {
  --bg: #090c14;
  --surface: #111624;
  --surface-2: #171e30;
  --surface-hover: #1d263d;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --text: #f3f6fc;
  --muted: #8c98b5;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  height: 62px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-sub {
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  margin-left: 4px;
}

.live-indicator {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

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

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.15s ease;
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
  color: #dbe3f4;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger-ghost {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}
.btn-danger-ghost:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-toggle {
  background: rgba(99, 102, 241, 0.14);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}
.btn-toggle.paused {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

.btn.full {
  width: 100%;
  padding: 10px 14px;
}

/* Workspace Layout */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-controls {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.search-input:focus {
  border-color: rgba(99, 102, 241, 0.7);
}

.status-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 4px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: inherit;
}
.tab.active {
  background: var(--surface-2);
  color: #fff;
}

.count {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 999px;
}
.count.badge-accent {
  background: rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.select-sm {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 9px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

.ticket-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-list {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 36px 16px;
}

.ticket-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  transition: all 0.14s ease;
  font-family: inherit;
  position: relative;
}

.ticket-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.ticket-item.active {
  background: rgba(99, 102, 241, 0.13);
  border-color: rgba(99, 102, 241, 0.45);
}

.ticket-item.unread {
  background: rgba(99, 102, 241, 0.07);
}

.ticket-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.ticket-code-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-weight: 700;
  color: #c7d2fe;
  display: flex;
  align-items: center;
  gap: 6px;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}

.ticket-time {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.ticket-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}

.ticket-preview {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ticket-item.unread .ticket-preview {
  color: #e2e8f0;
  font-weight: 500;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: #cbd5e1;
}

.pill-ayuda {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
}
.pill-sugerencias {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}
.pill-bugs {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}
.pill-domain {
  background: rgba(255, 255, 255, 0.06);
  color: #a5b4fc;
}
.pill-ai-off {
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}
.pill-urgent {
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

/* Chat Pane */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.empty-icon {
  font-size: 46px;
  margin-bottom: 12px;
}

.empty-chat h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 20px;
}

.empty-chat p {
  margin: 4px 0;
  max-width: 420px;
  line-height: 1.5;
  font-size: 14px;
}

.empty-tip {
  margin-top: 12px !important;
  font-size: 12.5px !important;
  color: #818cf8;
}

.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conv-header {
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.conv-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-back {
  display: none;
}

.conv-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.conv-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
}

.conv-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.conv-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 74%;
  gap: 4px;
}

.msg.user {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.bot,
.msg.admin {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-header {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.user .msg-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.bot .msg-bubble {
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.34);
  color: #e0e7ff;
  border-bottom-right-radius: 4px;
}

.msg.admin .msg-bubble {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-notice {
  padding: 8px 20px;
  font-size: 12px;
  background: rgba(99, 102, 241, 0.08);
  border-top: 1px solid var(--border);
  color: #a5b4fc;
}

.ai-notice.paused {
  background: rgba(16, 185, 129, 0.08);
  color: #6ee7b7;
}

.reply-form {
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.reply-form textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  outline: none;
}
.reply-form textarea:focus {
  border-color: rgba(99, 102, 241, 0.75);
}

.send-reply-btn {
  height: 44px;
  padding: 0 20px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal {
  width: 680px;
  max-width: 100%;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.modal-header,
.modal-footer {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.modal-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
}

.field-hint {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.toggles-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  cursor: pointer;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.telegram-test-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.inline-msg {
  font-size: 12.5px;
  color: var(--muted);
}
.inline-msg.ok { color: #6ee7b7; }
.inline-msg.err { color: #fca5a5; }

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

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.code-box code {
  font-size: 12px;
  color: #a5b4fc;
  word-break: break-all;
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 14, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.auth-card {
  width: 380px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 28px;
  text-align: center;
}

.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  margin: 0 auto 14px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 20px;
}

.auth-card p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.auth-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
}

.auth-error {
  color: #fca5a5;
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid rgba(99, 102, 241, 0.55);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  cursor: pointer;
  animation: toastIn 0.2s ease;
}

.toast-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 3px;
}

.toast-body {
  font-size: 12px;
  color: var(--muted);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .sidebar.mobile-hidden {
    display: none;
  }
  .chat-pane.mobile-hidden {
    display: none;
  }
  .mobile-back {
    display: inline-flex;
  }
  .topbar {
    height: auto;
    padding: 10px 12px;
    flex-wrap: wrap;
  }
}
