@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #0c0c1d;
  --bg-card: #13132b;
  --bg-elevated: #1a1a3e;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --text: #e2e2e8;
  --text-muted: #6c6c82;
  --text-dim: #44445a;
  --primary: #FF6600;
  --primary-hover: #e65c00;
  --primary-soft: rgba(255,102,0,0.08);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --neutral: #64748b;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-full: 50%;
  --bubble-cliente: #2a2a3e;
  --bubble-ia: #1a3a5c;
  --bubble-vendedor: #1a3c2a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

/* ===== LOGIN ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 32px;
  width: 320px;
}

.login-box h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text);
}

.login-box input {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.login-box input:focus {
  border-color: var(--border-hover);
}

.login-box .login-error {
  color: var(--error);
  font-size: 12px;
  margin-bottom: 8px;
  display: none;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity 0.12s;
  color: #fff;
}

.btn:hover {
  opacity: 0.85;
}

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

.btn-sm {
  padding: 4px 12px;
  font-size: 12px;
}

/* ===== LAYOUT ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.app-header h1 {
  font-size: 16px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-body {
  display: flex;
  height: calc(100vh - 49px);
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 200px;
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  padding: 16px 12px;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-section h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.sidebar-radio {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-radio label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.sidebar-radio label:hover {
  background: rgba(255,255,255,0.02);
}

.sidebar-radio input[type="radio"] {
  accent-color: var(--primary);
}

.sidebar-radio input[type="radio"]:checked + span {
  color: var(--text);
}

.search-input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.search-input:focus {
  border-color: var(--border-hover);
}

/* ===== TABS ===== */
.tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  position: relative;
  padding: 6px 16px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.tab-btn:hover {
  background: rgba(255,255,255,0.02);
}

.tab-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(255,102,0,0.20);
}

.tab-count {
  margin-left: 4px;
  font-size: 10px;
  color: var(--text-dim);
}

.tab-btn.active .tab-count {
  color: var(--primary);
}

.tab-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--primary);
  display: none;
}

.tab-btn.has-activity .tab-dot {
  display: block;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

/* ===== TICKET GRID ===== */
.ticket-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.ticket-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color 0.12s;
  max-height: calc(100vh - 160px);
}

.ticket-card:hover {
  border-color: var(--border-hover);
}

.ticket-card.has-new {
  animation: border-pulse 1s ease-in-out 3;
}

@keyframes border-pulse {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--primary); }
}

.ticket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.ticket-contact {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.ticket-meta {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ticket-id {
  font-size: 10px;
  color: var(--text-dim);
}

.ticket-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.status-open {
  background: rgba(34,197,94,0.10);
  color: var(--success);
  border: 1px solid rgba(34,197,94,0.20);
}

.status-pending {
  background: rgba(245,158,11,0.10);
  color: var(--warning);
  border: 1px solid rgba(245,158,11,0.20);
}

.status-closed {
  background: rgba(100,116,139,0.10);
  color: var(--neutral);
  border: 1px solid rgba(100,116,139,0.20);
}

/* ===== CHAT AREA ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
}

.chat-overlay-top,
.chat-overlay-bottom {
  position: sticky;
  left: 0;
  right: 0;
  height: 24px;
  pointer-events: none;
  flex-shrink: 0;
  z-index: 1;
}

.chat-overlay-top {
  top: 0;
  background: linear-gradient(to bottom, var(--bg-card), transparent);
}

.chat-overlay-bottom {
  bottom: 0;
  background: linear-gradient(to top, var(--bg-card), transparent);
}

.msg-bubble {
  max-width: 85%;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  font-size: 12px;
  word-break: break-word;
  line-height: 1.5;
}

.msg-body {
  overflow-wrap: break-word;
  word-break: break-word;
}

.msg-body b { font-weight: 600; }
.msg-body i { font-style: italic; }
.msg-body s { text-decoration: line-through; color: var(--text-muted); }

.msg-body pre.msg-code-block {
  background: rgba(0,0,0,0.3);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  overflow-x: auto;
  margin: 4px 0;
  white-space: pre-wrap;
}

.msg-body code.msg-code-inline {
  background: rgba(0,0,0,0.25);
  padding: 1px 4px;
  border-radius: 2px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
}

a.msg-link {
  color: var(--info);
  text-decoration: underline;
  word-break: break-all;
}

.msg-system {
  color: var(--text-dim);
  font-style: italic;
  font-size: 10px;
}

/* === Media elements === */
.msg-img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: block;
  margin: 4px 0;
}

.msg-sticker {
  max-width: 100px;
  max-height: 100px;
  display: block;
  margin: 4px 0;
}

.msg-audio {
  width: 100%;
  max-width: 220px;
  height: 32px;
  display: block;
  margin: 4px 0;
}

.msg-video {
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius-sm);
  display: block;
  margin: 4px 0;
}

.msg-caption {
  margin-top: 4px;
  font-size: 12px;
}

.msg-media-label {
  color: var(--text-dim);
  font-size: 10px;
  font-style: italic;
}

/* Document */
.msg-document {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.msg-doc-icon {
  background: rgba(59,130,246,0.15);
  color: var(--info);
  font-size: 10px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

a.msg-doc-name {
  color: var(--info);
  text-decoration: underline;
  font-size: 11px;
  word-break: break-all;
}

/* VCard */
.msg-vcard {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.msg-vcard-icon {
  background: rgba(34,197,94,0.15);
  color: var(--success);
  font-size: 9px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.msg-vcard-tel {
  font-size: 10px;
  color: var(--text-muted);
}

/* Notes */
.msg-note {
  background: rgba(245,158,11,0.08);
  border-left: 2px solid var(--warning);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--warning);
}

/* === Template messages === */
.tpl-container {
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tpl-header {
  padding: 8px;
  font-weight: 600;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.tpl-body {
  padding: 8px;
  font-size: 12px;
}

.tpl-footer {
  padding: 4px 8px;
  font-size: 10px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

.tpl-buttons {
  border-top: 1px solid var(--border);
}

.tpl-btn {
  text-align: center;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: default;
  border-top: 1px solid var(--border);
}

.tpl-btn:first-child { border-top: none; }

.tpl-btn-reply {
  color: var(--info);
}

.tpl-btn-url {
  color: var(--info);
}

.tpl-btn-phone {
  color: var(--success);
}

.tpl-list-section {
  padding: 4px 8px;
}

.tpl-list-row {
  padding: 2px 0;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}

.tpl-list-row:last-child { border-bottom: none; }

/* Lightbox */
.img-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}

.img-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
}

.msg-bubble.cliente {
  align-self: flex-start;
  background: var(--bubble-cliente);
}

.msg-bubble.ia {
  align-self: flex-end;
  background: var(--bubble-ia);
}

.msg-bubble.vendedor {
  align-self: flex-end;
  background: var(--bubble-vendedor);
}

.msg-time {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

.msg-sender-tag {
  font-size: 10px;
  font-weight: 600;
  margin-bottom: 2px;
}

.msg-bubble.ia .msg-sender-tag {
  color: var(--info);
}

.msg-bubble.vendedor .msg-sender-tag {
  color: var(--success);
}

.msg-bubble.cliente .msg-sender-tag {
  color: var(--warning);
}

.ticket-expand {
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
}

.ticket-expand button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
  transition: opacity 0.12s;
}

.ticket-expand button:hover {
  opacity: 0.85;
  color: var(--text-muted);
}

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.pagination button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.12s;
}

.pagination button:hover:not(:disabled) {
  opacity: 0.85;
  border-color: var(--border-hover);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: default;
}

.pagination span {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== DIALOG / MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 90vw;
  max-width: 700px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 14px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.12s;
}

.modal-close:hover {
  opacity: 0.85;
}

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

/* ===== KANBAN ===== */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px;
  height: 100%;
}

.kanban-column {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kanban-col-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-col-count {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
}

.kanban-col-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 60px;
}

.kanban-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: grab;
}

.kanban-card:active {
  cursor: grabbing;
}

.kanban-card-name {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
}

.kanban-card-meta {
  font-size: 10px;
  color: var(--text-dim);
}

.kanban-card-preview {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* SortableJS ghost */
.sortable-ghost {
  opacity: 0.4;
}

/* ===== VIEW TOGGLE ===== */
.view-toggle {
  display: flex;
  gap: 4px;
}

.view-toggle button {
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.view-toggle button.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(255,102,0,0.20);
}

.view-toggle button:hover:not(.active) {
  background: rgba(255,255,255,0.02);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1400px) {
  .ticket-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .ticket-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .sidebar {
    width: 160px;
  }
  .kanban-board {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .ticket-grid {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .kanban-board {
    grid-template-columns: 1fr;
  }
}
