:root {
  --gp-yellow: #F5C518;
  --gp-yellow-dim: rgba(245, 197, 24, 0.12);
  --gp-yellow-border: rgba(245, 197, 24, 0.3);
  --gp-bg: #0E0E0E;
  --gp-surface: #1A1A1A;
  --gp-surface2: #242424;
  --gp-border: #2E2E2E;
  --gp-text: #F0F0F0;
  --gp-muted: #888;
  --gp-green: #22C55E;
  --gp-green-dim: rgba(34, 197, 94, 0.12);
  --gp-red: #EF4444;
  --gp-amber: #F59E0B;
  --gp-amber-dim: rgba(245, 158, 11, 0.12);
  --topbar-h: 52px;
  --nav-h: 42px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--gp-bg);
  color: var(--gp-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* ============ LOGIN ============ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gp-bg);
}

.login-wrap { width: 100%; max-width: 380px; padding: 20px; }

.login-card {
  background: var(--gp-surface);
  border: 1px solid var(--gp-border);
  border-radius: 14px;
  overflow: hidden;
}

.login-header {
  background: var(--gp-surface2);
  padding: 32px 28px 24px;
  text-align: center;
  border-bottom: 1px solid var(--gp-border);
}

.login-logo {
  font-size: 36px;
  margin-bottom: 10px;
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--gp-text);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 12px;
  color: var(--gp-muted);
}

.login-form {
  padding: 24px 28px 28px;
}

.alert-error {
  margin: 16px 28px 0;
  padding: 10px 14px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 6px;
  font-size: 13px;
  color: var(--gp-red);
}

/* ============ FIELDS ============ */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 11px;
  color: var(--gp-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.field input, .field textarea {
  width: 100%;
  background: var(--gp-surface2);
  border: 1px solid var(--gp-border);
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--gp-text);
  outline: none;
  transition: border-color .15s;
}

.field input:focus, .field textarea:focus {
  border-color: var(--gp-yellow-border);
}

.field input::placeholder, .field textarea::placeholder {
  color: var(--gp-muted);
}

/* ============ BUTTONS ============ */
.btn-primary {
  background: var(--gp-yellow);
  color: #000;
  border: none;
  border-radius: 7px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-primary:hover { opacity: .88; }
.btn-primary.full { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--gp-muted);
  border: 1px solid var(--gp-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}

.btn-ghost:hover {
  border-color: var(--gp-yellow-border);
  color: var(--gp-yellow);
}

.btn-resolve {
  background: var(--gp-green-dim);
  color: var(--gp-green);
  border: 1px solid rgba(34,197,94,.25);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-resolve:hover { opacity: .8; }

.yellow { color: var(--gp-yellow); }

/* ============ TOPBAR ============ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--gp-surface);
  border-bottom: 1px solid var(--gp-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.logo-icon {
  width: 30px;
  height: 30px;
  background: var(--gp-yellow);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.logo-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--gp-text);
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.agent-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--gp-surface2);
  border: 1px solid var(--gp-border);
  border-radius: 20px;
  padding: 4px 12px 4px 4px;
}

.agent-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gp-yellow);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.agent-name { font-size: 12px; color: var(--gp-text); }

.btn-logout {
  font-size: 12px;
  color: var(--gp-muted);
  text-decoration: none;
  padding: 5px 10px;
  border: 1px solid var(--gp-border);
  border-radius: 6px;
  transition: all .15s;
}

.btn-logout:hover { color: var(--gp-red); border-color: rgba(239,68,68,.3); }

/* ============ NAV TABS ============ */
.nav-tabs {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  height: var(--nav-h);
  background: var(--gp-surface);
  border-bottom: 1px solid var(--gp-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 4px;
  z-index: 99;
}

.nav-tab {
  padding: 5px 16px;
  font-size: 13px;
  color: var(--gp-muted);
  cursor: pointer;
  border-radius: 20px;
  transition: all .15s;
  border: 1px solid transparent;
}

.nav-tab:hover { color: var(--gp-text); }

.nav-tab.active {
  color: #000;
  background: var(--gp-yellow);
  border-color: var(--gp-yellow);
  font-weight: 600;
}

/* ============ TAB CONTENT ============ */
.tab-content {
  display: none;
  margin-top: calc(var(--topbar-h) + var(--nav-h));
  height: calc(100vh - var(--topbar-h) - var(--nav-h));
}

.tab-content.active { display: flex; }

/* ============ CHAT LAYOUT ============ */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--gp-surface);
  border-right: 1px solid var(--gp-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gp-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--gp-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.count-badge {
  background: var(--gp-yellow);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

.filter-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gp-border);
  flex-shrink: 0;
}

.ftab {
  flex: 1;
  padding: 5px 0;
  text-align: center;
  font-size: 11px;
  color: var(--gp-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all .15s;
}

.ftab:hover { color: var(--gp-text); }

.ftab.active {
  background: var(--gp-yellow-dim);
  color: var(--gp-yellow);
  font-weight: 500;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--gp-border); border-radius: 4px; }

.conv-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gp-border);
  cursor: pointer;
  transition: background .15s;
  border-left: 2px solid transparent;
}

.conv-item:hover { background: var(--gp-surface2); }

.conv-item.active {
  background: var(--gp-yellow-dim);
  border-left-color: var(--gp-yellow);
}

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 3px;
}

.conv-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--gp-text);
}

.conv-item.active .conv-name { color: var(--gp-yellow); }

.conv-time { font-size: 10px; color: var(--gp-muted); }

.conv-preview {
  font-size: 12px;
  color: var(--gp-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}

.conv-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.s-pendiente .status-dot { background: var(--gp-amber); }
.s-pendiente { color: var(--gp-amber); }
.s-activo .status-dot { background: var(--gp-green); }
.s-activo { color: var(--gp-green); }
.s-resuelto .status-dot { background: var(--gp-muted); }
.s-resuelto { color: var(--gp-muted); }

.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--gp-muted);
  font-size: 13px;
}

/* ============ CHAT AREA ============ */
.chat-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--gp-bg);
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gp-muted);
  gap: 10px;
}

.placeholder-icon { font-size: 40px; opacity: .4; }
.placeholder-text { font-size: 13px; }

.chat-head {
  background: var(--gp-surface);
  border-bottom: 1px solid var(--gp-border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-head-info {}
.chat-head-name { font-size: 14px; font-weight: 500; color: var(--gp-text); margin-bottom: 3px; }
.chat-head-meta { font-size: 12px; color: var(--gp-muted); display: flex; align-items: center; gap: 8px; }

.wa-badge {
  background: rgba(37,211,102,.15);
  color: #25D366;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 500;
}

.chat-head-actions { display: flex; gap: 8px; }

.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msgs::-webkit-scrollbar { width: 4px; }
.chat-msgs::-webkit-scrollbar-thumb { background: var(--gp-border); border-radius: 4px; }

.msg-group { display: flex; flex-direction: column; gap: 2px; }
.msg-label { font-size: 10px; color: var(--gp-muted); margin-bottom: 3px; }
.msg-label.right { text-align: right; }

.bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.bubble.cliente {
  background: var(--gp-surface2);
  color: var(--gp-text);
  border-radius: 2px 12px 12px 12px;
  align-self: flex-start;
}

.bubble.bot {
  background: var(--gp-surface);
  color: var(--gp-muted);
  border: 1px solid var(--gp-border);
  border-radius: 2px 12px 12px 12px;
  align-self: flex-start;
  font-style: italic;
  font-size: 12px;
}

.bubble.agente {
  background: var(--gp-yellow);
  color: #000;
  border-radius: 12px 2px 12px 12px;
  align-self: flex-end;
  font-weight: 500;
}

.msg-time { font-size: 10px; color: var(--gp-muted); }
.msg-time.right { text-align: right; }

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--gp-surface2);
  border-radius: 2px 12px 12px 12px;
  align-self: flex-start;
  width: 56px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gp-muted);
  animation: bounce 0.8s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* ============ REPLY AREA ============ */
.reply-area {
  padding: 12px 16px;
  border-top: 1px solid var(--gp-border);
  background: var(--gp-surface);
  flex-shrink: 0;
}

.reply-box { display: flex; gap: 8px; align-items: flex-end; }

.reply-input {
  flex: 1;
  background: var(--gp-surface2);
  border: 1px solid var(--gp-border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--gp-text);
  resize: none;
  height: 72px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}

.reply-input:focus { border-color: var(--gp-yellow-border); }
.reply-input::placeholder { color: var(--gp-muted); }

.send-btn {
  height: 72px;
  padding: 0 20px;
  background: var(--gp-yellow);
  color: #000;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}

.send-btn:hover { opacity: .88; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ============ KNOWLEDGE BASE ============ */
.knowledge-wrap {
  width: 100%;
  padding: 24px 32px;
  overflow-y: auto;
}

.knowledge-header { margin-bottom: 20px; }
.knowledge-header h2 { font-size: 18px; font-weight: 500; margin-bottom: 4px; }
.knowledge-header p { font-size: 13px; color: var(--gp-muted); }

.knowledge-search {
  margin-bottom: 20px;
}

.knowledge-search input {
  width: 100%;
  max-width: 480px;
  background: var(--gp-surface);
  border: 1px solid var(--gp-border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  color: var(--gp-text);
  outline: none;
  transition: border-color .15s;
}

.knowledge-search input:focus { border-color: var(--gp-yellow-border); }
.knowledge-search input::placeholder { color: var(--gp-muted); }

.guides-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.guide-card {
  background: var(--gp-surface);
  border: 1px solid var(--gp-border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color .15s;
}

.guide-card:hover { border-color: var(--gp-yellow-border); }

.guide-card-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--gp-border);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.guide-brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--gp-surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.guide-brand { font-size: 13px; font-weight: 500; color: var(--gp-text); }
.guide-model { font-size: 11px; color: var(--gp-muted); margin-top: 1px; }

.guide-toggle {
  margin-left: auto;
  font-size: 11px;
  color: var(--gp-muted);
  transition: transform .2s;
}

.guide-card.open .guide-toggle { transform: rotate(90deg); }

.guide-body {
  display: none;
  padding: 16px;
}

.guide-card.open .guide-body { display: block; }

.guide-section { margin-bottom: 14px; }
.guide-section:last-child { margin-bottom: 0; }

.guide-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--gp-yellow);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}

.guide-steps { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.guide-steps li {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--gp-text);
  line-height: 1.5;
}

.step-num {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--gp-yellow-dim);
  color: var(--gp-yellow);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.guide-note {
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--gp-surface2);
  border-radius: 6px;
  font-size: 11px;
  color: var(--gp-muted);
  border-left: 2px solid var(--gp-yellow-border);
}

/* Portal page */
.portal-page { overflow: hidden; height: 100vh; }

/* ============ LOGOS ============ */
.login-logo-img {
  max-width: 180px;
  height: auto;
  margin: 0 auto 12px;
  display: block;
}

.topbar-logo {
  height: 28px;
  width: auto;
  display: block;
}


}

.sidebar-toggle:hover {
  color: var(--gp-yellow);
  border-color: var(--gp-yellow-border);
}

/* ============ SIDEBAR COLAPSABLE ============ */
.sidebar.hidden {
  display: none;
}

/* ============ SIDEBAR TOGGLE ============ */
.sidebar-toggle {
  background: var(--gp-yellow);
  border: none;
  color: #000;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .15s;
  margin-left: auto;
}

.sidebar-toggle:hover {
  opacity: .85;
}

/* Sidebar colapsado en desktop */
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-right: none;
}

/* ============ MOBILE ============ */
@media (max-width: 640px) {
  .chat-layout {
    grid-template-columns: 1fr;
    position: relative;
    overflow: hidden;
  }

  /* Sidebar ocupa toda la pantalla en movil */
  .sidebar {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background: var(--gp-surface);
  }

  .sidebar.hidden {
    display: none;
  }

  /* Chat ocupa toda la pantalla */
  .chat-area {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
  }

  /* Boton volver al sidebar dentro del chat */
  .btn-back-sidebar {
    display: flex !important;
  }

  .knowledge-wrap {
    padding: 16px;
  }

  .guides-grid {
    grid-template-columns: 1fr;
  }

  .chat-head {
    flex-wrap: wrap;
    gap: 6px;
  }

  .chat-head-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* Boton volver — solo visible en movil */
.btn-back-sidebar {
  display: none;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--gp-border);
  background: transparent;
  color: var(--gp-muted);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  margin-right: 6px;
}

.btn-back-sidebar:hover {
  color: var(--gp-yellow);
  border-color: var(--gp-yellow-border);
}

/* ============ SIDEBAR REVEAL TAB ============ */
.sidebar-reveal {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  background: var(--gp-yellow);
  color: #000;
  border: none;
  border-radius: 0 8px 8px 0;
  padding: 32px 7px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: .08em;
  z-index: 20;
  transition: opacity .15s, padding .15s;
  white-space: nowrap;
  clip-path: polygon(0 8%, 100% 0%, 100% 100%, 0 92%);
  box-shadow: 2px 0 8px rgba(0,0,0,.3);
}

.sidebar-reveal:hover {
  opacity: .9;
  padding: 36px 8px;
}

.chat-area {
  position: relative;
  overflow: hidden;
}