/* PageAI Pro Admin Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:          #080C14;
  --bg2:         #0F1623;
  --bg3:         #111827;
  --border:      #1A2A40;
  --border2:     #1E3A5F;
  --text:        #E2E8F0;
  --text2:       #94A3B8;
  --text3:       #64748B;
  --text4:       #475569;
  --blue:        #38BDF8;
  --blue-d:      #0EA5E9;
  --green:       #22C55E;
  --yellow:      #F59E0B;
  --red:         #EF4444;
  --red-l:       #F87171;
  --purple:      #A78BFA;
  --indigo:      #6366F1;
  --sidebar-w:   210px;
  --topbar-h:    54px;
  --radius:      10px;
  --radius-lg:   14px;
  --font:        'DM Sans', sans-serif;
  --font-head:   'Space Grotesk', sans-serif;
  --font-mono:   'JetBrains Mono', monospace;
}

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

html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

a { color: var(--blue); text-decoration: none; }
a:hover { opacity: .8; }

/* ── TOPBAR ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar-h);
  background: #0A0F1A;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
}
.topbar-left  { display: flex; align-items: center; width: var(--sidebar-w); flex-shrink: 0; }
.topbar-center { flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { width: 30px; height: 30px; background: linear-gradient(135deg, var(--blue-d), var(--indigo)); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.logo-name { font-family: var(--font-head); font-size: 14px; font-weight: 700; color: #F0F9FF; }
.logo-sub { font-size: 9px; color: var(--text3); letter-spacing: 1px; }

.global-search { display: flex; align-items: center; gap: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; max-width: 420px; }
.global-search input { flex: 1; background: none; border: none; outline: none; font-size: 13px; color: var(--text); font-family: var(--font); }
.global-search input::placeholder { color: var(--text3); }
.search-icon { color: var(--text3); font-size: 13px; }
.search-kbd { font-family: var(--font-mono); font-size: 11px; color: var(--text4); background: var(--bg); padding: 2px 5px; border-radius: 4px; border: 1px solid var(--border); }

.topbar-alert { display: flex; align-items: center; gap: 5px; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); border-radius: 6px; padding: 5px 10px; font-size: 12px; font-weight: 600; color: var(--red-l); }
.topbar-user { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; transition: background .2s; }
.topbar-user:hover { background: rgba(255,255,255,.04); }
.user-avatar { width: 28px; height: 28px; background: linear-gradient(135deg, var(--blue-d), var(--indigo)); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: white; }
.user-name { font-size: 12px; font-weight: 600; color: var(--text); }
.user-role { font-size: 10px; font-weight: 600; }
.topbar-logout { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; background: var(--bg2); border: 1px solid var(--border); border-radius: 7px; font-size: 14px; color: var(--text3); transition: all .2s; }
.topbar-logout:hover { color: var(--red-l); border-color: rgba(239,68,68,.4); }

/* ── LAYOUT ── */
.layout { display: flex; padding-top: var(--topbar-h); min-height: calc(100vh - var(--topbar-h)); }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: #0A0F1A;
  border-right: 1px solid var(--border);
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding: 12px 0;
  z-index: 50;
}

.nav { flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 16px;
  font-size: 13px; font-weight: 500; color: var(--text2);
  border-left: 2px solid transparent;
  transition: all .15s;
  position: relative;
}
.nav-item:hover { background: rgba(56,189,248,.06); color: var(--text); opacity: 1; }
.nav-item.active { background: rgba(56,189,248,.1); color: var(--blue); border-left-color: var(--blue); }
.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-badge { background: var(--red); color: white; border-radius: 10px; padding: 1px 6px; font-size: 10px; font-weight: 700; }
.nav-divider { height: 1px; background: var(--border); margin: 8px 12px; }
.nav-section { padding: 4px 0; }
.nav-section > .nav-label { display: block; padding: 8px 16px 4px; font-size: 10px; font-weight: 700; color: var(--text4); letter-spacing: 1px; text-transform: uppercase; }
.nav-item-sm { padding: 7px 16px; font-size: 12px; }


.sidebar-status { margin: 0 12px 12px; padding: 10px 12px; background: rgba(56,189,248,.05); border: 1px solid rgba(56,189,248,.12); border-radius: 9px; }
.sidebar-status-label { font-size: 9px; font-weight: 700; color: var(--text3); letter-spacing: 1px; margin-bottom: 6px; }
.sidebar-status-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--blue); font-weight: 600; }
.sidebar-status-sub { font-size: 10px; color: var(--text3); margin-top: 3px; }

/* ── MAIN ── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px;
  min-height: 100%;
}

/* ── PAGE HEADER ── */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.page-header-left h1 { font-family: var(--font-head); font-size: 20px; font-weight: 700; color: #F0F9FF; }
.page-header-left p  { color: var(--text3); font-size: 13px; margin-top: 3px; }
.page-header-actions { display: flex; gap: 8px; }

/* ── CARD ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card:hover { border-color: var(--border2); }
.card-title { font-size: 13px; font-weight: 700; color: #F0F9FF; margin-bottom: 16px; }

/* ── STAT CARDS ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; position: relative; overflow: hidden; }
.stat-card::before { content: attr(data-icon); position: absolute; top: -10px; right: -10px; font-size: 56px; opacity: .06; }
.stat-label { font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-family: var(--font-head); font-size: 24px; font-weight: 700; }
.stat-sub { font-size: 11px; color: var(--text3); margin-top: 4px; }

/* ── GRID ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ── TABLE ── */
.table-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: var(--bg); padding: 10px 16px; text-align: left; font-size: 10px; font-weight: 700; color: var(--text3); letter-spacing: .5px; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,.02); }

/* ── BADGES ── */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; letter-spacing: .3px; }
.badge-blue    { background: rgba(56,189,248,.12); color: var(--blue); }
.badge-green   { background: rgba(34,197,94,.12); color: var(--green); }
.badge-yellow  { background: rgba(245,158,11,.12); color: var(--yellow); }
.badge-red     { background: rgba(239,68,68,.12); color: var(--red-l); }
.badge-purple  { background: rgba(167,139,250,.12); color: var(--purple); }
.badge-gray    { background: rgba(100,116,139,.12); color: var(--text3); }

/* ── BUTTONS ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font); border: none; transition: opacity .2s; text-decoration: none; }
.btn:hover { opacity: .85; }
.btn-primary { background: linear-gradient(135deg, var(--blue-d), var(--indigo)); color: white; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text2); }
.btn-outline:hover { border-color: var(--border2); color: var(--text); opacity: 1; }
.btn-green  { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.3); color: var(--green); }
.btn-red    { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); color: var(--red-l); }
.btn-yellow { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: var(--yellow); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 5px; }

/* ── FORMS ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 11px; font-weight: 700; color: var(--text3); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.form-input, .form-select, .form-textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 13px;
  font-size: 13px; color: var(--text); font-family: var(--font);
  outline: none; transition: border-color .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--blue-d); }
.form-input::placeholder { color: var(--text4); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-select { cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text4); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* Toggle Switch */
.toggle { position: relative; display: inline-block; width: 34px; height: 18px; }
.toggle input { display: none; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 9px; cursor: pointer; transition: .2s; }
.toggle-slider:before { content: ''; position: absolute; width: 12px; height: 12px; background: white; border-radius: 50%; top: 3px; left: 3px; transition: .2s; }
.toggle input:checked + .toggle-slider { background: var(--blue-d); }
.toggle input:checked + .toggle-slider:before { transform: translateX(16px); }

/* ── DOTS & STATUS ── */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.pulse { animation: pulse-anim 2s infinite; }
@keyframes pulse-anim { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── CHAT ── */
.chat-layout { display: grid; grid-template-columns: 260px 1fr 220px; gap: 16px; height: calc(100vh - var(--topbar-h) - 80px); }
.chat-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.chat-item { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; cursor: pointer; transition: all .15s; }
.chat-item:hover, .chat-item.active { border-color: rgba(56,189,248,.35); background: rgba(56,189,248,.08); }
.chat-window { display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-input-bar { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.chat-input { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 13px; font-size: 13px; color: var(--text); font-family: var(--font); outline: none; }
.chat-input:focus { border-color: var(--blue-d); }
.msg-bubble { max-width: 360px; padding: 9px 13px; border-radius: 4px 12px 12px 12px; font-size: 13px; line-height: 1.6; }
.msg-bubble.ai { background: linear-gradient(135deg, #0C4A6E, #1E3A8A); border-radius: 12px 4px 12px 12px; }
.msg-bubble.customer { background: var(--bg3); }
.msg-bubble.system { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.2); color: var(--yellow); font-size: 11px; max-width: none; text-align: center; border-radius: 8px; }
.msg-meta { font-size: 10px; color: var(--text4); margin-top: 3px; }

/* ── MODALS ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(3px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; animation: modal-in .2s ease; }
.modal-lg { max-width: 720px; }
@keyframes modal-in { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-family: var(--font-head); font-size: 16px; font-weight: 700; color: #F0F9FF; }
.modal-close { width: 28px; height: 28px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; color: var(--text2); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }

/* ── PAGINATION ── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; }
.page-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 6px; background: var(--bg2); border: 1px solid var(--border); font-size: 13px; color: var(--text2); cursor: pointer; transition: all .15s; text-decoration: none; }
.page-btn:hover { border-color: var(--blue); color: var(--blue); opacity: 1; }
.page-btn.active { background: var(--blue-d); border-color: var(--blue-d); color: white; }

/* ── MISC ── */
.mono { font-family: var(--font-mono); }
.text-blue { color: var(--blue); }
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red { color: var(--red-l); }
.text-purple { color: var(--purple); }
.text-muted { color: var(--text3); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.fw-7 { font-weight: 700; }
.fw-6 { font-weight: 600; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 32px; }
.login-card h2 { font-family: var(--font-head); font-size: 20px; font-weight: 700; color: #F0F9FF; margin-bottom: 6px; }
.login-card p { color: var(--text3); font-size: 13px; margin-bottom: 24px; }

/* Responsive */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .chat-layout { grid-template-columns: 240px 1fr; }
  .chat-layout > :last-child { display: none; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

/* Spinner */
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Meta Sync specific */
.pipeline { display: flex; align-items: center; gap: 0; overflow-x: auto; padding: 4px 0; }
.pipeline-step { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; }
.pipeline-icon { width: 50px; height: 50px; border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.pipeline-label { font-size: 11px; font-weight: 700; text-align: center; }
.pipeline-sub { font-size: 10px; color: var(--text3); text-align: center; }
.pipeline-arrow { width: 40px; height: 2px; margin: 0 4px; margin-bottom: 24px; position: relative; flex-shrink: 0; }
.pipeline-arrow::after { content: ''; position: absolute; right: -1px; top: -4px; width: 0; height: 0; border-left: 6px solid var(--text4); border-top: 4px solid transparent; border-bottom: 4px solid transparent; }

/* Audience card */
.audience-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: relative; overflow: hidden; }
.audience-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; }
