:root {
  --navy: #0B1F3A; --blue: #1565C0; --light-blue: #1E88E5;
  --bg: #EDF2F7; --white: #FFFFFF; --border: #E2E8F0;
  --text-dark: #1A202C; --text-mid: #4A5568; --gray: #718096;
  --danger: #D64545; --success: #1E8C5A;
}
* , *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Segoe UI', Arial, sans-serif; color: var(--text-dark);
  background: var(--bg);
}
.admin-topbar {
  background: var(--navy); color: #fff; padding: 0 1.5rem; height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.admin-topbar-brand { font-weight: 800; letter-spacing: .04em; font-size: 1.05rem; }
.admin-topbar-brand em { color: var(--light-blue); font-style: normal; }
.admin-topbar-right { display: flex; align-items: center; gap: 1rem; font-size: .85rem; }
.admin-topbar a { color: rgba(255,255,255,.8); text-decoration: none; }
.admin-topbar a:hover { color: #fff; }

.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.admin-auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--navy), #12335E);
  padding: 1.5rem;
}
.admin-auth-card {
  background: #fff; border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 380px;
  box-shadow: 0 24px 60px rgba(5,12,24,.35);
}
.admin-auth-title { font-size: 1.4rem; font-weight: 800; color: var(--navy); margin: 0 0 .5rem; }
.admin-auth-desc { font-size: .85rem; color: var(--text-mid); margin: 0 0 1.5rem; line-height: 1.5; }

label { display: block; font-size: .78rem; font-weight: 700; color: var(--text-mid); margin: 1rem 0 .35rem; }
label:first-of-type { margin-top: 0; }
input[type="text"], input[type="password"], input[type="email"], textarea, select {
  width: 100%; padding: .65rem .8rem; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: .92rem; font-family: inherit; color: var(--text-dark);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--blue); }
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(135deg, #1565C0, #1E88E5); color: #fff; border: none;
  border-radius: 8px; padding: .7rem 1.3rem; font-size: .88rem; font-weight: 700;
  cursor: pointer; text-decoration: none; transition: filter .15s, transform .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn-block { width: 100%; margin-top: 1.2rem; }
.btn-ghost {
  background: none; border: 1.5px solid var(--border); color: var(--text-mid);
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); filter: none; }
.btn-danger { background: var(--danger); }
.btn-sm { padding: .4rem .8rem; font-size: .78rem; }

.alert { border-radius: 8px; padding: .8rem 1rem; font-size: .85rem; margin-bottom: 1rem; line-height: 1.5; }
.alert-error { background: #FDECEC; color: #A83232; border: 1px solid #F3C6C6; }
.alert-success { background: #E7F6EE; color: var(--success); border: 1px solid #BFE6D3; }
.alert-info { background: #EAF3FC; color: var(--blue); border: 1px solid #C5DCF5; }

.admin-card {
  background: #fff; border-radius: 14px; padding: 1.5rem; margin-bottom: 1.25rem;
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
}
.admin-card h2 { margin: 0 0 .25rem; font-size: 1.15rem; color: var(--navy); }
.admin-card .muted { color: var(--gray); font-size: .82rem; }

.cat-row-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: .75rem;
}
.cat-row-head-left { display: flex; align-items: center; gap: .6rem; }
.cat-icon-badge {
  width: 34px; height: 34px; border-radius: 8px; background: var(--navy);
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0;
}
.cat-actions { display: flex; gap: .4rem; }

table.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.admin-table th {
  text-align: left; background: var(--bg); padding: .55rem .7rem; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--gray);
}
table.admin-table td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.admin-table tr:last-child td { border-bottom: none; }
table.admin-table img.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--bg); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }
.form-grid .full { grid-column: 1 / -1; }

.repeat-row { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: center; }
.repeat-row input { flex: 1; }
.repeat-add { font-size: .8rem; color: var(--blue); background: none; border: none; cursor: pointer; padding: .3rem 0; font-weight: 700; }
.repeat-remove {
  background: #FDECEC; color: var(--danger); border: none; border-radius: 6px;
  width: 30px; height: 30px; flex-shrink: 0; cursor: pointer; font-size: .9rem;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(8,18,32,.6); display: none;
  align-items: flex-start; justify-content: center; padding: 3vh 1rem; z-index: 500; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 2rem; width: 100%; max-width: 640px;
  box-shadow: 0 30px 80px rgba(5,12,24,.4); margin-bottom: 3vh;
}
.modal-box h3 { margin: 0 0 1.25rem; color: var(--navy); font-size: 1.2rem; }

/* ── Panel de conversaciones de Ovri (chats.php) ── */
.chatlog-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .9rem; margin-bottom: 1.25rem;
}
.chatlog-stat {
  background: #fff; border-radius: 12px; padding: .9rem 1.1rem;
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
}
.chatlog-stat strong { display: block; font-size: 1.5rem; color: var(--navy); line-height: 1.1; }
.chatlog-stat span { display: block; font-size: .74rem; color: var(--gray); margin-top: .2rem; }

.chatlog-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .chatlog-layout { grid-template-columns: 1fr; } }

.chatlog-search { display: flex; gap: .5rem; margin-bottom: .75rem; }
.chatlog-search input { flex: 1; min-width: 0; }
.chatlog-search-info { font-size: .78rem; color: var(--gray); margin-bottom: .6rem; line-height: 1.5; }
.chatlog-search-info a { color: var(--blue); }
.chatlog-warn { color: #A87332; }

.chatlog-list {
  background: #fff; border-radius: 14px; box-shadow: 0 2px 14px rgba(0,0,0,.06);
  overflow: hidden; max-height: 70vh; overflow-y: auto;
}
.chatlog-empty { padding: 1.5rem; font-size: .84rem; color: var(--gray); text-align: center; }
.chatlog-item {
  display: block; padding: .8rem 1rem; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit; border-left: 3px solid transparent;
}
.chatlog-item:last-child { border-bottom: none; }
.chatlog-item:hover { background: #F7FAFD; }
.chatlog-item.active { background: #EAF3FC; border-left-color: var(--blue); }
.chatlog-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.chatlog-item-name { font-weight: 700; font-size: .88rem; color: var(--navy); }
.chatlog-item-date { font-size: .72rem; color: var(--gray); flex-shrink: 0; }
.chatlog-item-meta { font-size: .75rem; color: var(--blue); margin-top: .15rem; }
.chatlog-item-snippet {
  font-size: .78rem; color: var(--text-mid); margin-top: .3rem; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chatlog-muted { color: var(--gray); }
.chatlog-tag {
  display: inline-block; margin-top: .4rem; font-size: .68rem; font-weight: 700;
  padding: .15rem .5rem; border-radius: 20px;
}
.chatlog-tag-wa { background: #E7F6EE; color: #157A4C; }

.chatlog-pager {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-top: .8rem; font-size: .76rem; color: var(--gray);
}

.chatlog-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .8rem 1.25rem; margin-top: 1.1rem;
}
.chatlog-facts > div { min-width: 0; }
.chatlog-facts span {
  display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--gray); font-weight: 700; margin-bottom: .1rem;
}
.chatlog-facts strong { font-size: .85rem; font-weight: 600; color: var(--text-dark); word-break: break-word; }
.chatlog-referrer { margin: 1rem 0 0; word-break: break-all; font-size: .75rem; }

.chatlog-thread { display: flex; flex-direction: column; gap: .7rem; }
.chatlog-msg { max-width: 80%; }
.chatlog-msg.user { align-self: flex-end; }
.chatlog-msg.bot { align-self: flex-start; }
.chatlog-msg-who { font-size: .68rem; color: var(--gray); margin-bottom: .2rem; }
.chatlog-msg.user .chatlog-msg-who { text-align: right; }
.chatlog-msg-text {
  font-size: .85rem; line-height: 1.55; padding: .6rem .85rem; border-radius: 12px;
  word-break: break-word;
}
.chatlog-msg.user .chatlog-msg-text { background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.chatlog-msg.bot .chatlog-msg-text { background: var(--bg); color: var(--text-dark); border-bottom-left-radius: 4px; }
.chatlog-nota {
  align-self: stretch; background: #FFF6E5; border: 1px solid #F0DDB5; color: #8A6323;
  border-radius: 10px; padding: .6rem .8rem; font-size: .76rem; line-height: 1.5;
}
