:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1c2030;
  --muted: #6b7185;
  --border: #e3e5ee;
  --primary: #4f46e5;
  --primary-text: #ffffff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131a;
    --surface: #1a1d27;
    --text: #e8eaf2;
    --muted: #9298ab;
    --border: #2a2e3b;
    --primary: #818cf8;
    --primary-text: #11131a;
    --success: #4ade80;
    --success-soft: #14321f;
    --danger: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, sans-serif;
  line-height: 1.7;
}

button, input { font: inherit; color: inherit; }

/* ───────── layout ───────── */

.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }

.container { max-width: 980px; margin: 0 auto; padding: 0 16px 48px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 20px 0; margin-bottom: 8px;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.brand small { color: var(--muted); font-weight: 400; margin-inline-start: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ───────── forms ───────── */

.form-card { width: 100%; max-width: 400px; padding: 28px; }
.form-card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.form-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: .92rem; }

label { display: block; font-size: .9rem; margin: 14px 0 6px; }
input {
  width: 100%; padding: 11px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  outline: none;
}
input:focus { border-color: var(--primary); }
input.ltr { direction: ltr; text-align: left; }

/* Country code + number, laid out left-to-right like a written phone number. */
.phone-row { display: flex; gap: 8px; direction: ltr; }
.phone-row select {
  flex: 0 0 auto; max-width: 46%; padding: 11px 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; color: inherit;
}
.phone-row input { flex: 1; min-width: 0; }

.notice {
  margin: 0 0 6px; padding: 10px 12px; border-radius: 10px;
  background: var(--bg); border: 1px dashed var(--border);
  color: var(--muted); font-size: .85rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; min-height: 44px;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--primary); color: var(--primary-text);
  font-weight: 500; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn.block { width: 100%; margin-top: 22px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }

.error { color: var(--danger); font-size: .88rem; margin-top: 12px; min-height: 1.2em; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 16px; text-align: center; }

/* ───────── platform grid ───────── */

.summary { color: var(--muted); margin: 0 0 18px; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}

.platform {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 18px; text-align: start; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.platform:hover { border-color: var(--primary); transform: translateY(-2px); }
.platform .name { font-weight: 700; }
.platform .status { font-size: .85rem; color: var(--muted); }
.platform.connected { border-color: var(--success); }
.platform.connected .status { color: var(--success); }

.logo {
  width: 46px; height: 46px; border-radius: 12px;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 1.2rem;
}

.tick {
  position: absolute; top: 14px; left: 14px;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--success); color: #fff;
}
.tick svg { width: 16px; height: 16px; }

/* ───────── platform login page ───────── */

.back { margin-bottom: 14px; }
.platform-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.platform-head h1 { margin: 0; font-size: 1.25rem; }
.platform-head p { margin: 0; color: var(--muted); font-size: .88rem; }

.qr { display: block; margin: 8px auto 4px; width: 260px; max-width: 100%; height: auto; aspect-ratio: 1; background: #fff; padding: 8px; border-radius: 10px; }
.qr-note { text-align: center; color: var(--muted); font-size: .88rem; }

.done { text-align: center; padding: 8px 0; }
.done .big-tick {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%;
  display: grid; place-items: center; background: var(--success-soft); color: var(--success);
}
.done .big-tick svg { width: 32px; height: 32px; }
.done .actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

.notice.bad { color: var(--danger); border-color: var(--danger); }
.platform .status.bad { color: var(--danger); }
.platform.soon { opacity: .7; }

a { color: var(--primary); }

label.check { display: flex; align-items: center; gap: 8px; margin-top: 16px; cursor: pointer; }
label.check input { width: auto; }

.terms {
  max-height: 260px; overflow: auto; white-space: pre-wrap;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); font-size: .88rem;
}

.tabs { display: flex; gap: 6px; margin-bottom: 8px; padding: 4px; background: var(--bg); border-radius: 10px; }
.tab {
  flex: 1; min-height: 40px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; font-size: .88rem;
}
.tab.active { background: var(--surface); box-shadow: var(--shadow); font-weight: 700; }

.pair-code {
  margin: 8px 0; text-align: center; font-size: 2rem; font-weight: 700; letter-spacing: .25em;
  font-family: ui-monospace, Consolas, monospace;
}

.spinner {
  width: 40px; height: 40px; margin: 12px auto;
  border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── products & AI ───────── */

.actions-row { display: flex; gap: 8px; flex-wrap: wrap; }
a.btn { text-decoration: none; }
.bad { color: var(--danger); }

.two-col { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; align-items: start; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }
.grid-2 { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }

.list { padding: 6px 0; }
.list > .qr-note, .list > .error { padding: 12px 16px; margin: 0; }
.product {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.product:last-child { border-bottom: 0; }
.product small { display: block; color: var(--muted); font-size: .82rem; }
.product .meta { display: flex; flex-direction: column; align-items: flex-end; font-size: .85rem; white-space: nowrap; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer;
}
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

.chat { padding: 18px; display: flex; flex-direction: column; }
.bubbles {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 280px; max-height: 460px; overflow-y: auto;
  padding: 10px; background: var(--bg); border-radius: 10px;
}
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; font-size: .92rem; }
.bubble.user { align-self: flex-start; background: var(--primary); color: var(--primary-text); }
.bubble.assistant { align-self: flex-end; background: var(--surface); border: 1px solid var(--border); }
.bubble.error { align-self: center; color: var(--danger); font-size: .85rem; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; min-width: 0; }

label.switch {
  display: flex; align-items: flex-start; gap: 10px; text-align: start;
  margin: 18px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
label.switch input { width: 20px; height: 20px; margin-top: 4px; flex: none; }
label.switch small { color: var(--muted); }

.intro { padding: 18px 20px; margin-bottom: 16px; }
.intro h2 { margin: 0 0 6px; font-size: 1.08rem; }
.intro p { margin: 0 0 8px; color: var(--muted); font-size: .92rem; }
.intro ol { margin: 0 0 8px; padding-inline-start: 20px; font-size: .92rem; }

h2.cat { margin: 0; padding: 12px 16px 4px; font-size: .95rem; }
h2.cat small { color: var(--muted); font-weight: 400; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); font-size: .8rem; cursor: pointer; text-align: start;
}
.chip:hover { border-color: var(--primary); }

details.fold > summary { cursor: pointer; font-weight: 700; }
details.fold[open] > summary { margin-bottom: 8px; }
textarea {
  width: 100%; padding: 11px 14px; resize: vertical;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; color: inherit; font-size: .88rem;
}

/* ───────── toast ───────── */

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  width: max-content; max-width: calc(100% - 32px);
  padding: 10px 18px; border-radius: 10px;
  background: var(--text); color: var(--bg);
  opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* connection kinds (own account / bot) and their switch status */
.badges { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 6px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600;
  border: 1px solid var(--border); color: var(--muted); background: var(--bg); white-space: nowrap;
}
/* platform availability: active = brand blue (so it never looks like "connected") */
.badge.on { color: var(--primary); border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
/* connection state */
.badge.conn-on { color: var(--success); border-color: var(--success); background: var(--success-soft); }
.badge.conn-wait { color: #b45309; border-color: #d97706; background: color-mix(in srgb, #f59e0b 12%, transparent); }
.badge.conn-bad { color: var(--danger); border-color: var(--danger); background: transparent; }
.badge.off { color: var(--danger); border-color: var(--danger); background: transparent; }
h2.section { margin: 28px 0 4px; font-size: 1.1rem; }
.notice .badge { margin-left: 6px; }

/* ───────── demo notice (opens on every visit) ───────── */
#demo-note {
  width: min(400px, calc(100% - 32px)); padding: 24px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow); text-align: center;
}
#demo-note::backdrop { background: rgb(0 0 0 / .45); }
#demo-note h2 { margin: 0 0 10px; font-size: 1.15rem; }
#demo-note p { margin: 6px 0; line-height: 1.9; }
#demo-note .muted { color: var(--muted); font-size: .88rem; }
