:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --text: #121826;
  --muted: #667085;
  --line: #e3e7ef;
  --accent: #2453d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(36, 83, 214, .1);
  --ok: #138a4b;
  --ok-soft: rgba(19, 138, 75, .12);
  --wait: #b26b00;
  --wait-soft: rgba(212, 136, 6, .14);
  --bad: #c8321f;
  --bad-soft: rgba(200, 50, 31, .1);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 20px rgba(16, 24, 40, .06);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b25;
    --surface-2: #1c2431;
    --text: #e8ecf3;
    --muted: #94a0b4;
    --line: #273142;
    --accent: #6d8dff;
    --accent-ink: #0d1117;
    --accent-soft: rgba(109, 141, 255, .14);
    --ok: #3ccf7f;
    --ok-soft: rgba(60, 207, 127, .14);
    --wait: #f0b44c;
    --wait-soft: rgba(240, 180, 76, .14);
    --bad: #ff7a66;
    --bad-soft: rgba(255, 122, 102, .13);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

/* Inside Telegram the panel takes the chat's own colours */
body.tg {
  --bg: var(--tg-theme-secondary-bg-color, #f3f5f9);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --surface-2: var(--tg-theme-secondary-bg-color, #f2f4f8);
  --text: var(--tg-theme-text-color, #121826);
  --muted: var(--tg-theme-hint-color, #667085);
  --line: var(--tg-theme-section-separator-color, rgba(127, 127, 127, .2));
  --accent: var(--tg-theme-button-color, #2453d6);
  --accent-ink: var(--tg-theme-button-text-color, #ffffff);
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 24px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 650; }
h4 { font-size: 14px; font-weight: 650; margin: 18px 0 6px; color: var(--muted); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.err { color: var(--bad); font-size: 14px; }
.hidden { display: none !important; }

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

/* layout */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 0 10px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.brand .title { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--line);
}
.avatar.xl { width: 104px; height: 104px; box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--line), var(--shadow); }
.who { text-align: right; line-height: 1.3; }
.who .name { font-weight: 600; font-size: 14px; }

.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 6px 0 22px;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  flex: 1; text-align: center; white-space: nowrap; padding: 9px 14px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.tabs a.on { background: var(--accent-soft); color: var(--accent); }

.intro { margin-bottom: 16px; }
.intro p { margin-top: 4px; }

.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid { grid-template-columns: 1fr 1fr; align-items: start; } }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card + .card { margin-top: 0; }
.stack-cards { display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; gap: 12px; }
.card-head .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .card-head { flex-wrap: wrap; row-gap: 6px; }
  .card-head .grow { flex: 1 1 calc(100% - 54px); }
  .card-head .pill { margin-left: 54px; }
}
.icon { width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center; }
.icon svg { width: 24px; height: 24px; }
.i-whatsapp { background: #25d366; }
.i-instagram { background: linear-gradient(45deg, #f9a23a, #e6365f 50%, #8a3ab9); }
.i-telegram, .i-channel { background: #2aa3df; }
.i-vk { background: #0077ff; }

.pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
  padding: 4px 10px; border-radius: 99px; white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.off { color: var(--muted); background: var(--surface-2); }
.pill.wait { color: var(--wait); background: var(--wait-soft); }
.pill.err { color: var(--bad); background: var(--bad-soft); }

.facts { display: flex; flex-wrap: wrap; gap: 8px; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; min-width: 0; }
.fact b { display: block; font-size: 17px; font-weight: 700; }
.fact span { font-size: 12.5px; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note { font-size: 13px; color: var(--muted); }
.box { background: var(--surface-2); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }

/* buttons and fields */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; padding: 9px 15px; border-radius: 11px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  transition: transform .06s ease, opacity .15s ease, background .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 50px; font-size: 16px; padding: 12px 22px; border-radius: 14px; }
.btn.small { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.busy::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }

form.stack, .stack { display: flex; flex-direction: column; gap: 10px; }
form.row { display: flex; gap: 8px; flex-wrap: wrap; }
form.row > input, form.row > select { flex: 1; min-width: 160px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, textarea, select {
  font: inherit; font-size: 15px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; width: 100%; min-height: 42px;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .two { grid-template-columns: 1fr; } }

details.howto { background: var(--surface-2); border-radius: 14px; padding: 2px 14px; }
details.howto summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 14px; list-style: none; }
details.howto summary::-webkit-details-marker { display: none; }
details.howto summary::before { content: "›"; display: inline-block; margin-right: 8px; transition: transform .15s; }
details.howto[open] summary::before { transform: rotate(90deg); }
ol.steps { margin: 0 0 12px; padding-left: 20px; display: flex; flex-direction: column; gap: 5px; }
ol.steps code, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px;
}

/* WhatsApp linking */
.pair { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.qr {
  width: 220px; height: 220px; flex: none; background: #fff; border-radius: 16px; padding: 12px;
  box-shadow: 0 0 0 1px var(--line);
}
.qr svg { width: 100%; height: 100%; display: block; }
.code {
  font: 700 30px/1.1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .12em;
  background: var(--surface-2); border-radius: 14px; padding: 14px 18px; display: inline-block;
}
.pair .grow { min-width: 220px; }

/* people and journal */
ul.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
ul.list li { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
ul.list li:first-child { border-top: 0; }
ul.list select { width: auto; min-height: 34px; padding: 5px 10px; font-size: 13.5px; }
ul.list .ctl { display: flex; gap: 8px; align-items: center; }
@media (max-width: 560px) { ul.list .ctl { flex-basis: 100%; padding-left: 46px; } }
.brand .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ava {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px;
}
.log-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; width: 92px; flex: none; }
.copy { display: flex; gap: 8px; align-items: center; }
.copy input { font-size: 13px; }

/* login */
.login { max-width: 380px; width: 100%; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.login h1 { font-size: 28px; margin-top: 6px; }
.login .btn.big { width: 100%; }
.login .wait { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { height: 120px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 10; width: min(92vw, 440px); }
.toast {
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25); opacity: 0; transform: translateY(8px); transition: all .2s ease;
}
.toast.err { background: var(--bad); color: #fff; }
.toast.show { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
