/* === Reset & Base === */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0f172a; color: #e2e8f0; }

/* === App Layout === */
.app-layout { display: flex; height: 100vh; }

/* === Sidebar === */
.sidebar { width: 220px; background: #1e293b; border-right: 1px solid #334155; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 1.25rem 1rem; border-bottom: 1px solid #334155; }
.sidebar-header h1 { font-size: 1.1rem; color: #38bdf8; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.85rem; border-radius: 8px; color: #94a3b8; text-decoration: none; font-size: 0.9rem; transition: all 0.15s; }
.sidebar-link:hover { background: #334155; color: #e2e8f0; }
.sidebar-link.active { background: #0f172a; color: #38bdf8; font-weight: 600; }
.sidebar-footer { padding: 1rem; border-top: 1px solid #334155; display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; }
.sidebar-user { color: #94a3b8; }
.sidebar-logout { color: #64748b; text-decoration: none; }
.sidebar-logout:hover { color: #f87171; }

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

/* === Login Page === */
.login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.login-box { background: #1e293b; padding: 2rem; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,0.3); }
.login-box h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.4rem; color: #38bdf8; }
.login-error { background: #7f1d1d; color: #fca5a5; padding: 0.75rem; border-radius: 8px; margin-bottom: 1rem; text-align: center; font-size: 0.9rem; }

/* === Forms === */
input, textarea, select { width: 100%; padding: 0.7rem; margin-bottom: 0.75rem; border: 1px solid #334155; border-radius: 8px; background: #0f172a; color: #e2e8f0; font-size: 0.9rem; font-family: inherit; }
input:focus, textarea:focus, select:focus { outline: none; border-color: #38bdf8; }
label { display: block; font-size: 0.85rem; color: #94a3b8; margin-bottom: 0.3rem; }

/* Checkbox / radio: el reset de input { width:100% } los rompia (se estiraban a lo ancho del card y el texto del label quedaba en otra linea). */
input[type="checkbox"], input[type="radio"] {
  width: auto;
  margin: 0;
  padding: 0;
  cursor: pointer;
  accent-color: #38bdf8;
  flex-shrink: 0;
}
/* Label que envuelve un checkbox: pone el cuadrado y el texto en la misma linea, color normal (no muted). */
label.checkbox-row,
.settings-section .card label.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  color: #e2e8f0;
  font-size: 0.9rem;
  margin: 0.6rem 0;
}

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.65rem 1.2rem; border: none; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: #38bdf8; color: #0f172a; }
.btn-primary:hover { background: #7dd3fc; }
.btn-danger { background: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid #334155; }
.btn-ghost:hover { background: #334155; color: #e2e8f0; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* === Page Header === */
.page-header { padding: 1rem 1.5rem; border-bottom: 1px solid #334155; display: flex; justify-content: space-between; align-items: center; background: #1e293b; }
.page-header h2 { font-size: 1.1rem; color: #e2e8f0; font-weight: 600; }

/* === Cards === */
.card { background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 1.25rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)); gap: 1rem; padding: 1.5rem; }

/* === Badges === */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.7rem; font-weight: 600; }
.badge-green { background: #14532d; color: #86efac; }
.badge-yellow { background: #713f12; color: #fde68a; }
.badge-red { background: #7f1d1d; color: #fca5a5; }
.badge-blue { background: #1e3a5f; color: #7dd3fc; }
.badge-gray { background: #334155; color: #94a3b8; }

/* === Chats Page === */
.chats-layout { display: flex; flex: 1; overflow: hidden; }

.conv-list { width: 340px; border-right: 1px solid #334155; overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column; }
.conv-list .page-header { flex-shrink: 0; }
.conv-list > #convItems { flex: 1; overflow-y: auto; }
.conv-filters { display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.5rem 0.75rem; border-bottom: 1px solid #334155; background: #1a2332; flex-shrink: 0; }
.conv-filter { background: transparent; border: 1px solid #334155; color: #94a3b8; padding: 0.3rem 0.6rem; font-size: 0.75rem; border-radius: 999px; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 0.35rem; }
.conv-filter:hover { background: #334155; color: #e2e8f0; }
.conv-filter.active { background: #0f172a; color: #38bdf8; border-color: #38bdf8; font-weight: 600; }
.conv-filter-count { font-size: 0.65rem; padding: 1px 6px; border-radius: 999px; background: #334155; color: #cbd5e1; min-width: 12px; text-align: center; line-height: 1.4; }
.conv-filter-count:empty { display: none; }
.conv-filter-count.badge-red { background: #7f1d1d; color: #fca5a5; }
.conv-item { display: flex; gap: 0.75rem; padding: 0.85rem 1rem; border-bottom: 1px solid #1e293b; cursor: pointer; transition: background 0.1s; }
.conv-item:hover { background: #1e293b; }
.conv-item.active { background: #1e293b; border-left: 3px solid #38bdf8; }
.conv-avatar { width: 40px; height: 40px; border-radius: 50%; background: #334155; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 0.9rem; font-weight: 600; flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 0.9rem; font-weight: 500; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 0.8rem; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-meta { text-align: right; flex-shrink: 0; }
.conv-time { font-size: 0.7rem; color: #64748b; }
.conv-line { font-size: 0.65rem; color: #475569; margin-top: 2px; }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-active { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-header { padding: 0.85rem 1.25rem; border-bottom: 1px solid #334155; background: #1e293b; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.chat-header-name { font-size: 1rem; font-weight: 600; }
.chat-header-phone { font-size: 0.8rem; color: #64748b; }
.chat-messages { flex: 1 1 0%; min-height: 0; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-empty { flex: 1; display: flex; justify-content: center; align-items: center; color: #475569; font-size: 0.95rem; }

.msg { max-width: 70%; padding: 0.6rem 0.9rem; border-radius: 12px; font-size: 0.88rem; line-height: 1.4; word-wrap: break-word; }
.msg-in { background: #334155; color: #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }
.msg-out { background: #0c4a6e; color: #e0f2fe; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg-time { font-size: 0.65rem; color: #64748b; margin-top: 2px; }

.chat-input { display: flex; gap: 0.5rem; padding: 0.75rem 1.25rem; border-top: 1px solid #334155; background: #1e293b; flex-shrink: 0; }
.chat-input input { margin-bottom: 0; flex: 1; }

/* === Conexiones Page === */
.phone-list { margin-top: 0.75rem; }
.phone-item { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-top: 1px solid #0f172a; font-size: 0.85rem; }
.phone-number { color: #e2e8f0; }
.phone-name { color: #64748b; font-size: 0.8rem; }

/* === Empty states === */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #475569; gap: 0.5rem; }
.empty-state svg { opacity: 0.3; }

/* === Modal === */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal-overlay.hidden { display: none; }
.modal { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 1.5rem; width: 100%; max-width: 480px; }
.modal h3 { margin-bottom: 1rem; font-size: 1.1rem; color: #e2e8f0; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* === Stats === */
.stats-row { display: flex; gap: 1rem; padding: 1.5rem; flex-wrap: wrap; }
.stat-card { background: #1e293b; padding: 1rem 1.25rem; border-radius: 10px; border: 1px solid #334155; min-width: 150px; }
.stat-label { font-size: 0.8rem; color: #94a3b8; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: #38bdf8; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* === Settings Page (tabs) === */
.settings-layout { display: flex; flex: 1; overflow: hidden; min-height: 0; }
.settings-tabs { width: 200px; border-right: 1px solid #334155; padding: 0.75rem 0.5rem; display: flex; flex-direction: column; gap: 2px; flex-shrink: 0; background: #1a2332; }
.settings-tab { background: transparent; border: 0; color: #94a3b8; padding: 0.65rem 0.85rem; text-align: left; font-size: 0.88rem; border-radius: 8px; cursor: pointer; font-family: inherit; }
.settings-tab:hover { background: #334155; color: #e2e8f0; }
.settings-tab.active { background: #0f172a; color: #38bdf8; font-weight: 600; }
.settings-panel { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.settings-section { display: flex; flex-direction: column; gap: 1rem; }
.settings-section[hidden] { display: none; }
.settings-section .card label { margin-top: 0.6rem; }
.settings-section .card label:first-of-type { margin-top: 0; }
.settings-actions { position: sticky; bottom: 0; padding: 0.75rem 0; background: linear-gradient(to top, #0f172a 60%, transparent); display: flex; justify-content: flex-end; }

.ga-item { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0; border-top: 1px solid #0f172a; gap: 0.75rem; }
.ga-item:first-child { border-top: 0; }
.ga-main { flex: 1; min-width: 0; }
.ga-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.gac-add { display: grid; grid-template-columns: 1fr 1fr 1fr auto auto; gap: 0.4rem; margin-top: 1rem; }
.gac-add input { margin-bottom: 0; }
@media (max-width: 720px) { .gac-add { grid-template-columns: 1fr; } }

/* === Utilities === */
.text-muted { color: #64748b; }
.text-sm { font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.gap-1 { gap: 0.5rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
