/* Messenger Bot portal styles. Tokens first, then the auth pages, then the app shell. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #1877f2;
  --primary-600: #0f63d6;
  --primary-soft: #e8f1fe;
  --accent: #7c3aed;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning-soft: #fffbeb;
  --warning-border: #fcd34d;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 30px 60px -30px rgba(15, 23, 42, .35), 0 1px 2px rgba(15, 23, 42, .06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
code { background: #eef2f7; padding: .1rem .35rem; border-radius: 6px; font-size: .9em; }

/* ---------- Form controls ---------- */

input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); vertical-align: -3px; }
label { display: block; font-size: 13.5px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.field { margin-top: 20px; }
.field:first-of-type { margin-top: 0; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.hint ul { margin: 4px 0 0; padding-left: 18px; }
.errorlist { list-style: none; margin: 8px 0 0; padding: 0; color: var(--danger); font-size: 13px; font-weight: 500; }
.errorlist li + li { margin-top: 4px; }

.input-wrap { position: relative; }
.input-wrap > svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: #94a3b8; pointer-events: none;
}
.input-wrap > input { padding-left: 44px; }
.input-wrap.has-toggle > input { padding-right: 70px; }
.toggle-password {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.toggle-password:hover { background: #f1f5f9; color: var(--text); }

/* ---------- Buttons ---------- */

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1;
  color: #fff; background: var(--primary);
  border: 1px solid transparent; border-radius: 10px; cursor: pointer; text-decoration: none;
  transition: background .15s, box-shadow .15s, transform .05s;
}
button:hover, .button:hover { background: var(--primary-600); text-decoration: none; }
button:active, .button:active { transform: translateY(1px); }
button:focus-visible, .button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary-soft); }
button.secondary, .button.secondary { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: #f8fafc; }
button.danger { color: var(--danger); background: var(--surface); border-color: #fecaca; }
button.danger:hover { background: var(--danger-soft); }
.btn-primary {
  min-height: 50px; font-size: 15px;
  background: linear-gradient(135deg, #1877f2 0%, #3b8bf5 100%);
  box-shadow: 0 10px 24px -12px rgba(24, 119, 242, .9);
}
.btn-primary:hover { background: linear-gradient(135deg, #0f63d6 0%, #2d7cea 100%); }
.btn-block { width: 100%; }
form.inline { display: inline; }

/* ---------- Alerts ---------- */

.flash, .alert {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px;
  font-size: 14px; border: 1px solid var(--warning-border); background: var(--warning-soft); color: #78350f;
}
.flash.error, .alert-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash.success { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.flash.info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e3a8a; }

/* ---------- Auth pages ---------- */

.auth-page { background: var(--bg); }
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }

.auth-hero {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px 64px; color: #fff;
  background:
    radial-gradient(900px 500px at 10% 0%, rgba(124, 58, 237, .55), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(56, 189, 248, .45), transparent 60%),
    linear-gradient(140deg, #0b1220 0%, #0d2a66 45%, #1877f2 100%);
}
.auth-hero::before, .auth-hero::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(2px); pointer-events: none;
  border: 1px solid rgba(255, 255, 255, .12);
}
.auth-hero::before { width: 520px; height: 520px; right: -160px; top: -120px; background: rgba(255, 255, 255, .04); }
.auth-hero::after { width: 320px; height: 320px; left: -100px; bottom: -120px; background: rgba(255, 255, 255, .05); }
.auth-hero > * { position: relative; z-index: 1; }

.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #1877f2, #7c3aed); color: #fff;
  box-shadow: 0 10px 24px -12px rgba(24, 119, 242, .9);
}
.brand-mark svg { width: 22px; height: 22px; }
.auth-hero .brand-mark { background: rgba(255, 255, 255, .14); box-shadow: none; backdrop-filter: blur(6px); }

.hero-copy { max-width: 520px; }
.hero-copy h2 { font-size: clamp(30px, 3.2vw, 40px); line-height: 1.12; font-weight: 700; letter-spacing: -.02em; }
.hero-copy p { margin: 18px 0 0; font-size: 16px; line-height: 1.6; color: rgba(255, 255, 255, .78); }
.hero-features { list-style: none; margin: 32px 0 0; padding: 0; display: grid; gap: 14px; }
.hero-features li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; color: rgba(255, 255, 255, .92); }
.hero-features svg { width: 22px; height: 22px; flex: none; color: #7dd3fc; margin-top: 1px; }
.hero-foot { margin: 0; font-size: 13px; color: rgba(255, 255, 255, .6); letter-spacing: .02em; }

.auth-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-card {
  width: 100%; max-width: 460px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 44px; box-shadow: var(--shadow-lg);
}
.brand-mobile { display: none; margin-bottom: 28px; }
.eyebrow { margin: 0 0 10px; font-size: 12.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }
.auth-card h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.auth-sub { margin: 10px 0 28px; color: var(--muted); font-size: 15px; }
.auth-form .btn-primary { margin-top: 26px; }
.auth-alt { margin: 26px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.auth-alt a { font-weight: 600; }
.auth-legal { max-width: 460px; margin: 22px 0 0; text-align: center; color: var(--muted); font-size: 12.5px; line-height: 1.55; }

@media (max-width: 920px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-panel { padding: 32px 16px; justify-content: flex-start; }
  .auth-card { padding: 32px 24px; }
  .brand-mobile { display: flex; }
}

/* ---------- App shell (signed-in pages) ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255, 255, 255, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.topbar .brand-mark svg { width: 18px; height: 18px; }
.topbar nav { display: flex; align-items: center; gap: 4px; margin-left: 20px; }
.topbar nav a { color: var(--text-2); font-weight: 500; font-size: 14px; padding: 8px 12px; border-radius: 8px; }
.topbar nav a:hover { background: #f1f5f9; text-decoration: none; color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user .who { color: var(--muted); font-size: 14px; }
.topbar-user button { min-height: 36px; padding: 0 14px; font-size: 13.5px; }

.container { max-width: 1040px; margin: 0 auto; padding: 32px 24px 64px; }
.container h1 { font-size: 26px; font-weight: 700; margin-bottom: 8px; }
.container h2 { font-size: 17px; font-weight: 700; margin: 32px 0 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 14px; }
.helptext { display: block; color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.container label { margin: 20px 0 8px; }
.container form button { margin-top: 8px; }

.msg { padding: 10px 14px; border-radius: 14px; margin: 6px 0; max-width: 75%; white-space: pre-wrap; font-size: 14.5px; }
.msg.user { background: #eef2f7; border-bottom-left-radius: 4px; }
.msg.assistant { background: var(--primary); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.split { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 10px 0; border-bottom: 1px solid var(--border); }
@media (max-width: 700px) {
  .split { grid-template-columns: 1fr; }
  .topbar nav { display: none; }
  .container { padding: 24px 16px 48px; }
}

/* ---------- Dashboard ---------- */

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13.5px; font-weight: 500; margin-bottom: 14px; }
.back:hover { color: var(--text); text-decoration: none; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; line-height: 1.1; }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: #bbf7d0; }
.badge.warn { background: var(--warning-soft); color: #b45309; border-color: #fde68a; }
.badge.off { background: #f1f5f9; color: var(--muted); border-color: var(--border); }
.badge.info { background: var(--primary-soft); color: var(--primary-600); border-color: #bfdbfe; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 30px 0 12px; }
.section-head h2 { margin: 0; }
.section-head .count { color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 8px; }

.fb-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.identity { display: flex; align-items: center; gap: 14px; min-width: 0; }
.fb-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.fb-icon svg { width: 22px; height: 22px; }
.identity .title { font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.identity .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.cta {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px;
  padding: 28px 30px; border-radius: var(--radius-lg); color: #fff;
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(124, 58, 237, .5), transparent 60%),
    linear-gradient(135deg, #0d2a66 0%, #1877f2 65%, #4f8ef7 100%);
  box-shadow: 0 24px 50px -30px rgba(24, 119, 242, .8);
}
.cta h2 { color: #fff; margin: 0 0 8px; font-size: 22px; }
.cta p { margin: 0 0 18px; color: rgba(255, 255, 255, .82); max-width: 460px; }
.cta .button { background: #fff; color: var(--primary-600); }
.cta .button:hover { background: #eef4ff; }
.cta ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 12px; align-content: center; }
.cta ol li { display: flex; gap: 12px; align-items: center; font-size: 14.5px; color: rgba(255, 255, 255, .92); }
.cta .step { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .18); font-size: 12.5px; font-weight: 700; }
@media (max-width: 800px) { .cta { grid-template-columns: 1fr; } }

.page-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 900px) { .page-grid { grid-template-columns: 1fr; } }
.page-card { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.avatar { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; background: linear-gradient(135deg, #1877f2, #7c3aed); flex: none; }
.page-card .name { font-weight: 700; font-size: 16px; }
.page-card .id, .avail .id { color: var(--muted); font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.page-card .meta { display: flex; gap: 20px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.page-card .meta strong { color: var(--text); font-weight: 600; }
.page-card .foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--border); margin-top: auto; }
.btn-sm, .button.btn-sm, button.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }

.avail { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.avail .avatar { width: 40px; height: 40px; border-radius: 10px; font-size: 15px; background: #eef2f7; color: var(--text-2); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #f1f5f9; color: var(--muted); font-size: 12px; margin-left: 8px; }

.empty { text-align: center; padding: 36px 24px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--muted); background: #fafbfe; font-size: 14px; }
.empty svg { width: 36px; height: 36px; color: #94a3b8; margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.copy-block { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; background: #0f172a; color: #e2e8f0; border-radius: var(--radius); padding: 12px 14px 12px 16px; margin-top: 30px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.copy-block .label { color: #94a3b8; font-family: var(--font); font-size: 12.5px; margin-right: 10px; }
.copy-block button { min-height: 32px; padding: 0 12px; font-size: 12.5px; color: #e2e8f0; background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .15); }
.copy-block button:hover { background: rgba(255, 255, 255, .18); }

/* ---------- Settings ---------- */

label.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; margin: 0 0 6px; font-weight: 600; color: var(--text); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 44px; height: 26px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 4px var(--primary-soft); }

.settings { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .settings { grid-template-columns: 1fr; } }
.settings form.card { padding: 24px; margin: 0; }
.settings .container-label, .settings label:not(.switch) { margin: 0 0 8px; }
.side-card h3 { font-size: 14px; margin-bottom: 8px; }
.side-card p, .side-card li { color: var(--muted); font-size: 13.5px; margin: 0; }
.side-card ul { padding-left: 18px; margin: 0; display: grid; gap: 6px; }

/* ---------- Conversations ---------- */

.chat-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 800px) { .chat-layout { grid-template-columns: 1fr; } }
.conv-list { padding: 6px; margin: 0; }
.conv-list a { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; color: inherit; }
.conv-list a:hover { background: #f8fafc; text-decoration: none; }
.conv-list a.active { background: var(--primary-soft); }
.conv-list .avatar { width: 38px; height: 38px; border-radius: 50%; font-size: 13px; background: #e2e8f0; color: var(--text-2); }
.conv-list .who { font-weight: 600; font-size: 14px; }
.conv-list .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.conv-list .when { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }
.chat { padding: 0; margin: 0; overflow: hidden; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-body { padding: 18px; display: flex; flex-direction: column; background: #fafbfe; min-height: 320px; }
.bubble { display: flex; flex-direction: column; max-width: 75%; margin: 4px 0; }
.bubble.assistant { align-self: flex-end; align-items: flex-end; }
.bubble .msg { max-width: none; margin: 0; }
.bubble .time { font-size: 11px; color: var(--muted); margin: 4px 8px 0; }
.settings form .field { margin-top: 22px; }

/* Facebook-first sign in */
.fb-button { margin-top: 4px; }
.reassure { list-style: none; margin: 22px 0 0; padding: 0; display: grid; gap: 8px; color: var(--muted); font-size: 13.5px; }
.reassure li { padding-left: 22px; position: relative; }
.reassure li::before { content: ""; position: absolute; left: 4px; top: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); opacity: .6; }
