/* ============================================================
   Panelchat — Global stylesheet
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ───────────────────────────────────────────── */
:root {
  --accent:        #478eda;
  --accent-hover:  #2d6ec5;
  --accent-light:  #eef5fd;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface2:      #f8fafc;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;
  --header-bg:     #0f172a;
  --msg-in:        #f1f5f9;
  --msg-out:       #478eda;
  --msg-out-text:  #ffffff;
  --danger:        #ef4444;
  --danger-light:  #fef2f2;
  --success:       #22c55e;
  --success-light: #f0fdf4;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:        0 4px 16px rgba(0,0,0,.08);
  --radius:        12px;
  --radius-sm:     8px;
  --sidebar-w:     320px;
}

body.dark {
  --accent-light:  #0f2540;
  --bg:            #0b1220;
  --surface:       #111827;
  --surface2:      #0f172a;
  --border:        #1e293b;
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --text-light:    #475569;
  --header-bg:     #020617;
  --msg-in:        #1e293b;
  --msg-out:       #2d6ec5;
  --danger-light:  #2d0a0a;
  --success-light: #052e16;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.3);
  --shadow:        0 4px 16px rgba(0,0,0,.4);
}

/* ── Base ────────────────────────────────────────────────── */
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s, color .2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ──────────────────────────────────────────────── */
header {
  background: var(--header-bg);
  color: #fff;
  height: 52px;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -.3px;
  color: #fff;
  text-decoration: none;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-icon svg { width: 16px; height: 16px; fill: #fff; }

.top-actions { display: flex; align-items: center; gap: 6px; }

.header-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color .15s, background .15s;
}

.header-link:hover {
  color: #fff;
  background: rgba(255,255,255,.08);
  text-decoration: none;
}

.header-sep { color: #334155; margin: 0 2px; }

.header-user {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
  padding: 6px 10px;
}

/* ── Toggle switch ───────────────────────────────────────── */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px 10px;
  user-select: none;
}

.toggle-track {
  width: 34px;
  height: 18px;
  background: #334155;
  border-radius: 99px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}

.toggle-track.on { background: var(--accent); }

.toggle-thumb {
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 99px;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left .2s;
}

.toggle-track.on .toggle-thumb { left: 18px; }

/* ── Shared buttons ──────────────────────────────────────── */
.btn {
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: background .15s, opacity .15s, transform .1s;
}

.btn:active:not([disabled]) { transform: scale(.97); }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not([disabled]) { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not([disabled]) { background: var(--border); }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.badge-active  { background: var(--success-light); color: #15803d; }
.badge-paused  { background: var(--danger-light);  color: #b91c1c; }

/* ── Form elements (shared) ──────────────────────────────── */
input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(71,142,218,.18);
}

input::placeholder,
textarea::placeholder { color: var(--text-light); }

/* ── Alert boxes ─────────────────────────────────────────── */
.error-box {
  margin-top: 14px;
  background: var(--danger-light);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 14px;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 500;
}

.dark .error-box { border-color: #7f1d1d; color: #fca5a5; }

.success-box {
  margin-top: 14px;
  background: var(--success-light);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 10px 14px;
  color: #15803d;
  font-size: 13px;
  font-weight: 500;
}


/* ============================================================
   Dashboard
   ============================================================ */

body.page-dashboard {
  height: 100vh;
  overflow: hidden;
}

/* ── App layout ──────────────────────────────────────────── */
.app {
  display: flex;
  height: calc(100vh - 52px);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: background .2s, border-color .2s;
}

.sidebar-top {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.search-box { display: flex; gap: 8px; }

.search-box input {
  flex: 1;
  border-radius: var(--radius-sm);
  font-size: 13px;
  padding: 9px 12px;
  /* El input del buscador no define type="", así que los estilos base no aplican */
  color: var(--text);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  outline: none;
}

/* Garantizar legibilidad del texto en modo oscuro */
body.dark .search-box input {
  color: #f1f5f9 !important;
  caret-color: #f1f5f9 !important;
  -webkit-text-fill-color: #f1f5f9 !important;
  background: var(--surface2);
}

body.dark .search-box input::placeholder {
  color: var(--text-light);
  opacity: 1;
  -webkit-text-fill-color: var(--text-light);
}

body.dark .search-box input:focus,
body.dark .search-box input:active {
  color: #f1f5f9 !important;
  background: var(--surface2);
}

body.dark .search-box input::selection {
  background: rgba(71,142,218,.35);
  color: #ffffff !important;
}

/* Autofill (Chrome/Edge) */
body.dark .search-box input:-webkit-autofill,
body.dark .search-box input:-webkit-autofill:hover,
body.dark .search-box input:-webkit-autofill:focus {
  -webkit-text-fill-color: #f1f5f9 !important;
  transition: background-color 9999s ease-in-out 0s;
}

.search-box button {
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}

.search-box button:hover { background: var(--accent-hover); }

.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(--border); border-radius: 99px; }

.conv-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}

.conv-item:hover  { background: var(--surface2); }
.conv-item.active { background: var(--accent-light); }

.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.conv-body  { flex: 1; min-width: 0; }

.conv-row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
}

.conv-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  font-size: 11px;
  color: var(--text-light);
  white-space: nowrap;
  flex-shrink: 0;
}

.conv-row2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.status-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.status-pill.active  { background: var(--success-light); color: #15803d; }
.status-pill.paused  { background: var(--danger-light);  color: #b91c1c; }
.status-pill.default { background: var(--surface2); color: var(--text-muted); }

.no-convs {
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Chat area ───────────────────────────────────────────── */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  transition: background .2s;
}

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

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-title    { font-size: 14px; font-weight: 700; color: var(--text); }
.chat-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

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

/* ── Feed ────────────────────────────────────────────────── */
.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-feed::-webkit-scrollbar { width: 4px; }
.chat-feed::-webkit-scrollbar-track { background: transparent; }
.chat-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

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

.empty-icon {
  width: 60px;
  height: 60px;
  background: var(--surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon svg { width: 28px; height: 28px; opacity: .4; }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  margin-bottom: 2px;
}

.msg.in  { align-self: flex-start; }
.msg.out { align-self: flex-end; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.msg.in  .msg-bubble { background: var(--msg-in); color: var(--text); border-bottom-left-radius: 4px; }
.msg.out .msg-bubble { background: var(--msg-out); color: var(--msg-out-text); border-bottom-right-radius: 4px; }

.msg-meta { font-size: 11px; color: var(--text-light); margin-top: 3px; padding: 0 4px; }
.msg.out .msg-meta { text-align: right; }

/* ── Chat input ──────────────────────────────────────────── */
.chat-input {
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  transition: background .2s;
}

#mensaje-input {
  flex: 1;
  border-radius: 12px;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  font-size: 13.5px;
}

#mensaje-input[disabled] { opacity: .5; }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.send-btn:hover:not([disabled])  { background: var(--accent-hover); }
.send-btn:active:not([disabled]) { transform: scale(.92); }
.send-btn[disabled] { opacity: .4; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Dashboard alert bars ────────────────────────────────── */
.error-bar {
  background: var(--danger-light);
  color: #b91c1c;
  font-size: 13px;
  padding: 8px 20px;
  border-bottom: 1px solid #fecaca;
}

.info-bar {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  padding: 6px 20px;
  font-weight: 500;
}

.dark .info-bar  { background: #0f2540; }
.dark .error-bar { background: #2d0a0a; border-bottom-color: #7f1d1d; }


/* ============================================================
   Auth pages (login / password reset)
   ============================================================ */

body.page-auth {
  background: linear-gradient(135deg, #0f172a 0%, #1a2e4a 50%, #0f172a 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.auth-logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-logo-icon svg { width: 22px; height: 22px; fill: #fff; }
.auth-logo-text { font-size: 20px; font-weight: 800; color: #0f172a; letter-spacing: -.4px; }

.auth-title    { font-size: 22px; font-weight: 800; color: #0f172a; letter-spacing: -.4px; margin-bottom: 6px; }
.auth-subtitle { font-size: 13px; color: #64748b; margin-bottom: 28px; line-height: 1.5; }

.auth-field { margin-bottom: 16px; }

.auth-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.auth-field input {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #0f172a;
}

.auth-field input:focus { background: #fff; }

.auth-submit {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.auth-submit:hover  { background: var(--accent-hover); }
.auth-submit:active { transform: scale(.98); }

.auth-footer {
  text-align: center;
  margin-top: 18px;
}

.auth-footer a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
}

.auth-footer a:hover { text-decoration: underline; }


/* ============================================================
   Users page
   ============================================================ */

body.page-users { min-height: 100vh; }

.page { max-width: 1000px; margin: 32px auto; padding: 0 20px; }

.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.4px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
}

.card-header {
  padding: 16px 24px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.card-body { padding: 24px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
}

.check-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-actions { margin-top: 20px; }

.btn-submit {
  padding: 11px 28px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn-submit:hover  { background: var(--accent-hover); }
.btn-submit:active { transform: scale(.97); }

.hint { font-size: 12px; color: var(--text-light); margin-top: 12px; }

/* ── Users table ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead { background: var(--surface2); }

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 13px 16px;
  font-size: 13.5px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface2); }

.td-muted { color: var(--text-muted); }

.badge-si {
  display: inline-block;
  padding: 2px 9px;
  background: var(--success-light);
  color: #15803d;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.badge-no {
  display: inline-block;
  padding: 2px 9px;
  background: var(--danger-light);
  color: #b91c1c;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.role-pill {
  display: inline-block;
  padding: 2px 9px;
  background: rgba(71,142,218,.12);
  color: var(--accent);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.no-data {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
