/* ===== Chatbot Vui Vẻ — giao diện quản trị ===== */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #29261f;
  --muted: #7a7466;
  --line: #e6e1d5;
  --primary: #0f766e;       /* teal đậm */
  --primary-hover: #0d5f58;
  --accent: #f59e0b;        /* hổ phách */
  --danger: #b91c1c;
  --success-bg: #ecfdf3;
  --success-ink: #027a48;
  --error-bg: #fef3f2;
  --error-ink: #b42318;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ---- Topbar ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; height: 58px;
}
.brand { font-weight: 700; font-size: 17px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--primary); color: #fff; }
.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user-email { font-size: 13px; color: var(--muted); }
.inline-form { display: inline; }

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px; width: 100%; flex: 1; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 14px 0; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 22px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ---- Card ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.card h2 { margin-top: 0; font-size: 17px; }
.card.narrow { max-width: 440px; margin: 40px auto; }
.card.center { text-align: center; }
.error-title { font-size: 22px; }

/* ---- Stat ---- */
.stat { text-align: center; padding: 18px 12px; }
.stat .stat-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat .stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---- Form ---- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.form-group .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
input[type="number"], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
textarea { min-height: 90px; resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---- Buttons ---- */
.btn {
  display: inline-block; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); color: #3b2b06; border-color: var(--accent); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f1c0c0; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { display: block; width: 100%; text-align: center; }

/* ---- Table ---- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---- Badge ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.badge-on { background: var(--success-bg); color: var(--success-ink); border-color: transparent; }
.badge-off { background: #f3f4f6; color: #6b7280; border-color: transparent; }
.badge-admin { background: var(--accent); color: #3b2b06; border-color: transparent; }

/* ---- Flash ---- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash-success { background: var(--success-bg); color: var(--success-ink); }
.flash-error { background: var(--error-bg); color: var(--error-ink); }
.flash-info { background: #eff8ff; color: #175cd3; }

/* ---- Page card (fanpage list) ---- */
.page-card { display: flex; gap: 14px; align-items: flex-start; }
.page-avatar { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; background: var(--bg); }
.page-card-body { flex: 1; min-width: 0; }
.page-card-body h3 { margin: 0 0 4px; font-size: 16px; }
.page-links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.toggle-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---- Livechat ---- */
.chat-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 540px; }
.chat-sidebar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-y: auto; max-height: 640px; }
.chat-conv {
  display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  color: inherit; align-items: center;
}
.chat-conv:hover { background: var(--bg); text-decoration: none; }
.chat-conv.selected { background: #e6f2f1; }
.chat-conv .avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg); flex-shrink: 0; }
.chat-conv .conv-info { flex: 1; min-width: 0; }
.chat-conv .conv-name { font-weight: 600; font-size: 14px; }
.chat-conv .conv-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv .unread { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.chat-main { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; }
.chat-header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; max-height: 480px; }
.bubble { max-width: 70%; padding: 9px 13px; border-radius: 16px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble-in { background: #efece3; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble-out { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .bubble-meta { display: block; font-size: 10px; opacity: .7; margin-top: 3px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; }
.chat-empty { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--muted); }

@media (max-width: 800px) {
  .chat-layout { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 20px; }
}
