/* ===== Fanpage Manager — giao diện chuyên nghiệp ===== */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e5e9f2;
  --text: #1a2233;
  --muted: #6b7690;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --sidebar-bg: #101a33;
  --sidebar-text: #aab4cf;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 26, 51, .06), 0 4px 16px rgba(16, 26, 51, .05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

#app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 10;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.brand-icon { font-size: 26px; }
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; opacity: .7; }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-ico { font-size: 16px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 20px;
}
.nav-badge.on { background: rgba(22,163,74,.25); color: #4ade80; }
.nav-badge.off { background: rgba(220,38,38,.25); color: #f87171; }

.sidebar-pages {
  margin-top: auto;
  padding: 14px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-pages-title { font-size: 10px; letter-spacing: 1px; opacity: .6; margin-bottom: 8px; }
.sidebar-page {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 8px; margin-bottom: 4px;
  font-size: 12.5px; color: #dbe2f2;
}
.sidebar-page .pageava {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}

/* Ảnh đại diện page thật đè lên chữ viết tắt (fallback khi ảnh lỗi) */
.pageava { position: relative; overflow: hidden; }
.pageava img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: inherit;
}
.sidebar-page .status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
  margin-left: auto; flex-shrink: 0;
}

/* ===== Main ===== */
.main { margin-left: 250px; flex: 1; padding: 28px 32px; max-width: 1280px; }

.view { display: none; }
.view.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.view-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
h1 { font-size: 22px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; margin-bottom: 10px; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-title { font-weight: 700; font-size: 14.5px; margin-bottom: 12px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===== Stats ===== */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 18px;
}
@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 2px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat.accent-blue .stat-value { color: var(--primary); }
.stat.accent-red .stat-value { color: var(--danger); }
.stat.accent-green .stat-value { color: var(--success); }

/* ===== Chart ===== */
.chart {
  display: flex; align-items: flex-end; gap: 6px;
  height: 160px; padding-top: 8px;
}
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; position: relative; }
.chart-col .bar { border-radius: 3px 3px 0 0; min-height: 2px; transition: height .3s; }
.bar-scanned { background: #bfd3fe; }
.bar-hidden { background: var(--danger); }
.chart-col .chart-x {
  text-align: center; font-size: 9.5px; color: var(--muted); margin-top: 4px;
}
.chart-col:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 4px 8px; border-radius: 6px;
  font-size: 11px; white-space: nowrap; z-index: 5;
}
.chart-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.dot-scanned { background: #bfd3fe; }
.dot-hidden { background: var(--danger); }

/* ===== Reason breakdown ===== */
.reason-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.reason-name { width: 130px; font-size: 13px; }
.reason-bar-wrap { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.reason-bar { height: 100%; background: var(--primary); border-radius: 4px; }
.reason-count { width: 40px; text-align: right; font-weight: 700; font-size: 13px; }

/* ===== Activity ===== */
.act-row {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.act-row:last-child { border-bottom: none; }
.act-ico {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.act-ico.auto_hide { background: var(--danger-soft); }
.act-ico.manual_hide, .act-ico.manual_unhide { background: var(--warning-soft); }
.act-ico.reply, .act-ico.private_reply { background: var(--primary-soft); }
.act-ico.system { background: var(--success-soft); }
.act-ico.error { background: var(--danger-soft); }
.act-ico.delete { background: var(--danger-soft); }
.act-ico.message_in, .act-ico.message_out { background: var(--primary-soft); }
.act-msg { font-size: 13px; }
.act-detail {
  font-size: 12px; color: var(--muted); font-style: italic;
  background: var(--bg); padding: 4px 10px; border-radius: 6px; margin-top: 4px;
  border-left: 3px solid var(--border);
}
.act-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ===== Comments layout ===== */
.comments-layout {
  display: grid; grid-template-columns: 340px 1fr; gap: 18px;
  align-items: start;
}
@media (max-width: 1000px) { .comments-layout { grid-template-columns: 1fr; } }

.post-list { padding: 8px; max-height: 75vh; overflow-y: auto; }
.post-item {
  padding: 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s;
}
.post-item:hover { background: var(--bg); }
.post-item.active { background: var(--primary-soft); border-color: #c5d6fb; }
.post-msg {
  font-size: 13px; font-weight: 500;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-meta { font-size: 11.5px; color: var(--muted); margin-top: 5px; display: flex; gap: 12px; }

.comment-panel { max-height: 75vh; overflow-y: auto; }
.cmt {
  display: flex; gap: 10px; padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.cmt:last-child { border-bottom: none; }
.cmt-ava {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.cmt-body { flex: 1; min-width: 0; }
.cmt-bubble {
  background: var(--bg); border-radius: 12px; padding: 8px 12px;
  display: inline-block; max-width: 100%;
}
.cmt.hidden-cmt .cmt-bubble { background: var(--danger-soft); opacity: .75; }
.cmt-name { font-weight: 700; font-size: 12.5px; }
.cmt-text { font-size: 13.5px; word-wrap: break-word; }
.cmt-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cmt-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
}
.badge-hidden { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-ad { background: #ede9fe; color: #7c3aed; }
.badge-bm { background: var(--primary-soft); color: var(--primary-dark); }

.reply-box { display: flex; gap: 8px; margin-top: 8px; }
.reply-box .input { flex: 1; }

/* ===== Inbox (Messenger) ===== */
.inbox-layout {
  display: grid; grid-template-columns: 320px 1fr; gap: 18px;
  align-items: start;
}
@media (max-width: 1000px) { .inbox-layout { grid-template-columns: 1fr; } }

.conv-list { padding: 8px; max-height: 75vh; overflow-y: auto; }
.conv-item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  transition: background .15s;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-soft); }
.conv-body { flex: 1; min-width: 0; }
.conv-name { font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.conv-snippet {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-time { font-size: 10.5px; color: var(--muted); flex-shrink: 0; }
.unread-dot {
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--primary); color: #fff;
  font-size: 10.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.thread-panel {
  display: flex; flex-direction: column;
  max-height: 75vh; padding: 0; overflow: hidden;
}
.thread-head {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; display: flex; align-items: center; gap: 10px;
}
.thread-msgs {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg);
}
.msg { max-width: 70%; display: flex; flex-direction: column; }
.msg.from-user { align-self: flex-start; }
.msg.from-page { align-self: flex-end; }
.msg-bubble {
  padding: 8px 13px; border-radius: 16px;
  font-size: 13.5px; word-wrap: break-word; line-height: 1.45;
}
.from-user .msg-bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.from-page .msg-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 6px; }
.from-page .msg-time { text-align: right; }

.thread-composer {
  display: flex; gap: 8px; padding: 12px 14px;
  border-top: 1px solid var(--border); background: var(--card);
}
.thread-composer .input { flex: 1; }

/* ===== Rules ===== */
.rule-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.rule-row:last-child { border-bottom: none; }
.rule-name { font-weight: 600; font-size: 13.5px; }
.rule-desc { font-size: 12px; color: var(--muted); margin-top: 1px; }
.rule-danger .rule-name { color: var(--danger); }

/* ===== Switch ===== */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #cbd2e0; border-radius: 22px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(18px); }
.switch-lg { width: 52px; height: 28px; }
.switch-lg .slider:before { height: 22px; width: 22px; }
.switch-lg input:checked + .slider:before { transform: translateX(24px); }

/* ===== Chips ===== */
.chip-input { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-soft); color: var(--primary-dark);
  font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px;
}
.chip .chip-x { cursor: pointer; font-weight: 700; opacity: .6; }
.chip .chip-x:hover { opacity: 1; }

/* ===== Forms & buttons ===== */
.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; font-family: inherit; background: #fff;
  color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea.input { resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  border: 1px solid transparent; cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: #fee2e2; }
.btn-success-soft { background: var(--success-soft); color: var(--success); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.row-gap { margin-top: 12px; }
.row-gap.right { display: flex; justify-content: flex-end; gap: 8px; }

.code {
  font-family: Consolas, monospace; font-size: 12px;
  background: var(--bg); padding: 2px 7px; border-radius: 5px;
  word-break: break-all;
}
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 13px; align-items: center; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-ico { font-size: 40px; margin-bottom: 10px; }

.test-verdict { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; }
.test-verdict.hide { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }
.test-verdict.pass { background: var(--success-soft); color: var(--success); border: 1px solid #bbf7d0; }

/* ===== Connected pages in settings ===== */
.cpage {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; margin-top: 8px;
}
.cpage .pageava {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.cpage-name { font-weight: 700; font-size: 13.5px; }
.cpage-meta { font-size: 11.5px; color: var(--muted); }

/* ===== Facebook connect ===== */
.setup-note {
  background: var(--primary-soft);
  border: 1px solid #c5d6fb;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--text);
  margin-bottom: 4px;
}
.fbpage-list-title { font-weight: 700; font-size: 13px; margin: 10px 0 4px; }
.setup-steps { margin: 8px 0 0 18px; padding: 0; }
.setup-steps li { margin-bottom: 6px; line-height: 1.55; }
.setup-steps a { color: var(--primary); font-weight: 600; }
.app-valid {
  margin-top: 8px; padding: 8px 12px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600;
}
.app-valid.ok { background: var(--success-soft); color: var(--success); }
.app-valid.bad { background: var(--danger-soft); color: var(--danger); }
.scope-option {
  display: flex; gap: 8px; align-items: flex-start;
  margin-top: 12px; font-size: 12px; color: var(--muted);
  cursor: pointer;
}
.scope-option input { margin-top: 3px; flex-shrink: 0; }

.config-id-note {
  margin-top: 12px; padding: 12px 14px;
  background: var(--warning-soft); border: 1px solid #fde68a;
  border-radius: 10px; font-size: 12.5px;
}
details summary::-webkit-details-marker { color: var(--muted); }

/* ===== Auth screen ===== */
#authScreen {
  position: fixed; inset: 0; z-index: 50;
  background: linear-gradient(135deg, #101a33 0%, #1d3a8f 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  background: #fff; border-radius: 16px; padding: 32px 30px;
  width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,.35);
}
.auth-brand { text-align: center; font-size: 22px; margin-bottom: 6px; }
.auth-tabs {
  display: flex; gap: 6px; margin: 18px 0 6px;
  background: var(--bg); border-radius: 10px; padding: 4px;
}
.auth-tab {
  flex: 1; padding: 9px; border: none; border-radius: 8px;
  background: transparent; font-family: inherit; font-size: 13.5px;
  font-weight: 600; color: var(--muted); cursor: pointer;
}
.auth-tab.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.auth-err {
  margin-top: 12px; padding: 10px 13px; border-radius: 9px;
  background: var(--danger-soft); color: var(--danger);
  font-size: 13px; font-weight: 600;
}

/* ===== Language toggle (cờ, cố định góc phải) ===== */
#langToggle {
  position: fixed; top: 12px; right: 16px; z-index: 60;
  display: flex; gap: 3px;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 4px; box-shadow: var(--shadow); backdrop-filter: blur(4px);
}
#langToggle .lang-btn {
  border: none; background: transparent; padding: 3px 5px; border-radius: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: .45; transition: opacity .15s, background .15s;
}
#langToggle .lang-btn:hover { opacity: .8; }
#langToggle .lang-btn.active { opacity: 1; background: var(--primary-soft); }
#langToggle .lang-btn svg {
  width: 24px; height: 16px; border-radius: 3px; display: block;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .1);
}

/* Chừa chỗ cho nút cờ ở góc phải để không đè lên nút/select top-right */
.view-head { padding-right: 78px; }
@media (max-width: 640px) { .view-head { padding-right: 0; } #langToggle { top: 8px; right: 10px; } }

/* ===== Sidebar user ===== */
.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.sidebar-user .pageava {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.sidebar-user-name {
  color: #fff; font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user-role { font-size: 10.5px; opacity: .6; }
.sidebar-user .btn { padding: 4px 8px; background: transparent; border-color: rgba(255,255,255,.2); color: #dbe2f2; }

/* ===== User management ===== */
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.user-row:last-child { border-bottom: none; }
.user-row .u-info { flex: 1; min-width: 0; }
.user-row .u-name { font-weight: 700; }
.user-row .u-meta { font-size: 11.5px; color: var(--muted); }
.user-row.disabled-user { opacity: .5; }

/* Ẩn mục hệ thống với tài khoản thường */
body.role-user .admin-only { display: none !important; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast-item {
  background: var(--text); color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: toastIn .25s ease;
}
.toast-item.error { background: var(--danger); }
.toast-item.success { background: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cbd2e0; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
