/* ==========================================================================
   my.telegram.org Official Design System & Stylesheet
   ========================================================================== */

:root {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #0f1419;
  --text-2: #6b7480;
  --text-3: #9aa3ad;
  --line: #e4e7eb;
  --accent: #1d98dc;
  --accent-strong: #0e8ed4;
  --accent-hover: #0e8ed4;
  --accent-soft: #e8f5fd;
  --danger: #e5484d;
  --danger-strong: #d43a3f;
  --danger-soft: #fdecec;
  --danger-fg: var(--danger);
  --success: #30a46c;
  --success-soft: #e9f6ef;
  --warn-soft: #fff6e0;
  --warn: #b97a00;
  --warn-callout-text: #483813;
  --callout-text: var(--text-2);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17212b;
    --surface: #232e3c;
    --surface-2: #2b3847;
    --text: #e9edf1;
    --text-2: #828d99;
    --text-3: #66717d;
    --line: rgba(255, 255, 255, .08);
    --accent: #3390ec;
    --accent-strong: #5eb0f3;
    --accent-hover: #5eb0f3;
    --accent-soft: rgba(51, 144, 236, .16);
    --danger-strong: #f06a6e;
    --danger-fg: #f27578;
    --danger-soft: #3a1d22;
    --success-soft: #16301f;
    --warn: #f0b54a;
    --warn-soft: rgba(240, 181, 74, .13);
    --callout-text: var(--text);
    --warn-callout-text: var(--text);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17212b;
  --surface: #232e3c;
  --surface-2: #2b3847;
  --text: #e9edf1;
  --text-2: #828d99;
  --text-3: #66717d;
  --line: rgba(255, 255, 255, .08);
  --accent: #3390ec;
  --accent-strong: #5eb0f3;
  --accent-hover: #5eb0f3;
  --accent-soft: rgba(51, 144, 236, .16);
  --danger-strong: #f06a6e;
  --danger-fg: #f27578;
  --danger-soft: #3a1d22;
  --success-soft: #16301f;
  --warn: #f0b54a;
  --warn-soft: rgba(240, 181, 74, .13);
  --callout-text: var(--text);
  --warn-callout-text: var(--text);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f1f3f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #0f1419;
  --text-2: #6b7480;
  --text-3: #9aa3ad;
  --line: #e4e7eb;
  --accent: #1d98dc;
  --accent-strong: #0e8ed4;
  --accent-hover: #0e8ed4;
  --accent-soft: #e8f5fd;
  --danger: #e5484d;
  --danger-strong: #d43a3f;
  --danger-soft: #fdecec;
  --danger-fg: var(--danger);
  --success: #30a46c;
  --success-soft: #e9f6ef;
  --warn-soft: #fff6e0;
  --warn: #b97a00;
  --warn-callout-text: #483813;
  --callout-text: var(--text-2);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  color-scheme: light;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Inter", "Roboto", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.my-hide, .hidden { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 14px;
  height: 64px; padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 17px; letter-spacing: -.02em;
  color: var(--text); text-decoration: none;
}

.brand-logo { width: 32px; height: 32px; display: block; }

.crumbs {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-2); font-size: 14px;
}

.crumbs svg { width: 14px; height: 14px; opacity: .6; }

.crumbs a, .crumbs span {
  color: var(--text-2); text-decoration: none; font-weight: 500;
}

.topbar .spacer { flex: 1; }

.server-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--success-soft); color: var(--success);
}

.server-badge .dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}

.account {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 500;
}

.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(160deg, #37bbfe, #1d93d2);
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
}

/* theme toggle */
.theme-toggle {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-2); display: grid; place-items: center;
  cursor: pointer; transition: color .15s, background .15s, transform .25s; flex: none;
}

.theme-toggle:hover { color: var(--text); background: var(--surface-2); }
.theme-toggle:active { transform: rotate(-20deg) scale(.94); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle .moon { display: none; }
}

/* ---------- layout ---------- */
.page {
  max-width: 1040px; width: 100%; margin: 0 auto;
  padding: 40px 24px 96px; display: grid;
  grid-template-columns: 220px 1fr; gap: 40px;
  flex: 1;
}

.page.narrow {
  grid-template-columns: 1fr;
  max-width: 440px;
  padding-top: 64px;
}

.side {
  position: sticky; top: 104px; align-self: start;
  display: flex; flex-direction: column; gap: 4px;
}

.side a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  color: var(--text-2); text-decoration: none;
  font-size: 14.5px; font-weight: 500;
  transition: all .15s;
}

.side a svg { width: 20px; height: 20px; flex: none; stroke-width: 2; }
.side a:hover { background: var(--surface); color: var(--text); }
.side a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.side a.danger { color: var(--danger-fg); }
.side a.danger:hover { background: var(--danger-soft); color: var(--danger-fg); }
.side hr { border: 0; border-top: 1px solid var(--line); margin: 10px 12px; }

.main-content { min-width: 0; }

.head { margin-bottom: 24px; }
.head h1 { font-size: 28px; line-height: 1.2; letter-spacing: -.02em; margin: 0 0 8px; font-weight: 700; }
.head p { margin: 0; color: var(--text-2); max-width: 580px; font-size: 15px; }

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

.card + .card { margin-top: 20px; }
.card h2 { font-size: 18px; margin: 0 0 6px; font-weight: 600; letter-spacing: -.01em; }
.card h3 { font-size: 16px; margin: 0 0 6px; font-weight: 600; }
.card .sub, .card .hint { color: var(--text-2); font-size: 14px; margin: 0 0 20px; }

/* ---------- auth section (my.telegram.org exact replica) ---------- */
.auth { text-align: center; }
.auth .hero-logo {
  width: 104px; height: 104px; display: block; margin: 0 auto 16px;
  filter: drop-shadow(0 12px 28px rgba(29, 152, 220, .35));
}
.auth h1 { font-size: 26px; margin: 0 0 8px; letter-spacing: -.02em; font-weight: 700; }
.auth > p { color: var(--text-2); margin: 0 0 28px; line-height: 1.5; }
.auth .card { text-align: left; }

.field { position: relative; margin-bottom: 20px; }

.field > input[type="text"],
.field > input[type="tel"],
.field > input[type="password"],
.field > input[type="number"],
.field > textarea,
.field > select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1.5px solid transparent; border-radius: 12px;
  padding: 24px 14px 8px; outline: none;
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.field label {
  position: absolute; left: 15px; top: 17px;
  line-height: 22px; color: var(--text-3);
  pointer-events: none; transition: all .15s; font-size: 15px;
}

.field > input:focus, .field > textarea:focus, .field > select:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field > input:focus + label,
.field > input:not(:placeholder-shown) + label,
.field > textarea:focus + label,
.field > textarea:not(:placeholder-shown) + label,
.field.has-val label {
  top: 7px; font-size: 12px; line-height: 1.5; color: var(--text-2);
}

.field > input:focus + label,
.field > textarea:focus + label {
  color: var(--accent-strong);
}

.field .hint {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12.5px; color: var(--text-3); margin: 6px 4px 0;
}

/* ---------- country picker ---------- */
.phone-field .country-btn {
  position: absolute; left: 6px; top: 6px; height: 46px; padding: 0 8px 0 10px;
  display: flex; align-items: center; gap: 6px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
  z-index: 2;
}
.phone-field .country-btn::after { content: ''; position: absolute; right: -6px; top: 11px; bottom: 11px; width: 1px; background: var(--line); }
.phone-field .country-btn:hover { background: rgba(127, 127, 127, .12); }
.phone-field .country-btn .flag { font-size: 18px; line-height: 1; }
.phone-field .country-btn .code { font-weight: 500; font-size: 14px; }
.phone-field .country-btn .chev { width: 16px; height: 16px; color: var(--text-2); transition: transform 220ms cubic-bezier(.2, 0, 0, 1); }
.phone-field.open .country-btn .chev { transform: rotate(180deg); }
.phone-field.open .country-btn { background: var(--accent-soft); color: var(--accent-strong); }

.phone-field > input {
  padding-left: 104px !important;
}
.phone-field > label {
  left: 104px !important;
}

.country-pop {
  position: absolute; left: 0; right: 0; top: 62px; z-index: 50;
  background: var(--surface); border-radius: 14px; overflow: hidden;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .06), 0 18px 40px rgba(16, 24, 40, .16);
  border: 1px solid var(--line);
  opacity: 0; transform: translateY(-6px) scaleY(.94); transform-origin: 50% 0; pointer-events: none;
  transition: opacity 160ms ease-out, transform 220ms cubic-bezier(.2, 0, 0, 1);
}
:root[data-theme="dark"] .country-pop { box-shadow: 0 18px 40px rgba(0, 0, 0, .45); }
.phone-field.open .country-pop { opacity: 1; transform: none; pointer-events: auto; }
.country-search { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text-3); }
.country-search svg { width: 18px; height: 18px; flex: none; }
.country-search input { flex: 1; border: 0; outline: 0; background: transparent; font: inherit; color: var(--text); padding: 0; font-size: 14px; }
.country-search input::placeholder { color: var(--text-3); }
.country-list { list-style: none; margin: 0; padding: 6px; max-height: 288px; overflow-y: auto; }
.country-list li {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; transition: background .12s; font-size: 14.5px;
}
.country-list li:hover { background: rgba(127, 127, 127, .1); }
.country-list li.sel { background: var(--accent-soft); }
.country-list li.sel .name { color: var(--accent-strong); font-weight: 500; }
.country-list .flag { font-size: 20px; line-height: 1; width: 26px; text-align: center; }
.country-list .name { flex: 1; color: var(--text); }
.country-list .dial { color: var(--text-2); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13.5px; }
.country-list li.empty { cursor: default; color: var(--text-3); justify-content: center; }
.country-list li.empty:hover { background: transparent; }

.code-input {
  font-family: var(--mono) !important; font-weight: 600; letter-spacing: .12em;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 24px; border-radius: 999px; border: 0;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1;
  cursor: pointer; transition: background .15s, transform .1s, box-shadow .15s;
  text-decoration: none;
}

.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .08); }
.btn.primary:hover { background: var(--accent-hover); box-shadow: 0 6px 16px -4px var(--accent-soft), 0 0 0 4px var(--accent-soft); }
.btn.primary svg { transition: transform 260ms cubic-bezier(.2, 0, 0, 1); }
.btn.primary:hover svg { transform: translateX(3px); }

.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-strong); }
.btn.ghost { background: transparent; color: var(--accent-strong); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--line); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .6; pointer-events: none; }

a.link { color: var(--accent-strong); text-decoration: none; }
a.link:hover { text-decoration: underline; }

/* ---------- callouts / alerts ---------- */
.alert-slot:empty { display: none; }
.callout {
  display: flex; gap: 12px; padding: 14px 16px; border-radius: 14px;
  font-size: 14px; margin-bottom: 20px;
}
.callout svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.callout.danger { background: var(--danger-soft); color: var(--danger-fg); }
.callout.info { background: var(--accent-soft); color: var(--accent-strong); }
.callout.success { background: var(--success-soft); color: var(--success); }
.callout p { margin: 0; color: var(--callout-text); }

/* ---------- credentials (my.telegram.org exact grid) ---------- */
.creds { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; margin-bottom: 20px; }
.cred { background: var(--surface-2); border-radius: 14px; padding: 16px 18px 14px; }
.cred .k { font-size: 12.5px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.cred-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 4px 6px 4px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.cred-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.cred-input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .02em;
  padding: 6px 0;
  cursor: text;
}
.cred-input::placeholder {
  color: var(--text-muted);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 13.5px;
  opacity: 0.7;
}
.copy-btn.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 0;
  background: var(--surface-2);
  color: var(--accent-strong);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  flex: none;
}
.copy-btn.btn-sm:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.copy-btn.copied {
  background: rgba(48, 164, 108, 0.15) !important;
  color: #2b9964 !important;
}

.meta-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 15px 0; border-top: 1px solid var(--line); font-size: 14.5px;
}
.meta-row:first-of-type { border-top: 0; }
.meta-row .l { color: var(--text-2); min-width: 0; font-weight: 500; }
.meta-row .r { text-align: right; min-width: 0; font-weight: 600; color: var(--text); }
.meta-row .mono { font-family: var(--mono); font-size: 14px; }

/* ---------- grid & forms ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.platforms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.chip {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--text-2); font-size: 13px;
  font-weight: 500; cursor: pointer; transition: all .15s; text-align: center;
}
.chip svg { width: 22px; height: 22px; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- sessions list ---------- */
.sessions-list { display: flex; flex-direction: column; gap: 12px; }
.session-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; background: var(--surface-2); border-radius: 14px;
  border: 1px solid var(--line); transition: all .15s;
}
.session-item.current {
  border-color: rgba(48, 164, 108, .4);
  background: var(--success-soft);
}
.session-title { font-weight: 600; font-size: 15px; color: var(--text); display: flex; align-items: center; gap: 10px; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.blue { background: var(--accent-soft); color: var(--accent-strong); }
.session-details { font-size: 13px; color: var(--text-2); margin-top: 4px; display: flex; gap: 14px; }

/* ---------- snippets ---------- */
.snippet-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.snippet-tab-btn {
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-2); padding: 8px 16px; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.snippet-tab-btn.active {
  background: var(--accent-soft); border-color: var(--accent);
  color: var(--accent-strong);
}
pre {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px; font-family: var(--mono);
  font-size: 13.5px; line-height: 1.6; color: var(--text); overflow-x: auto;
}

.spin-icon { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .page { grid-template-columns: 1fr; padding: 24px 16px 64px; gap: 20px; }
  .side { display: flex; flex-direction: row; overflow-x: auto; padding-bottom: 8px; }
  .side hr { display: none; }
  .grid2, .creds { grid-template-columns: 1fr; }
  .platforms { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 20px; }
  .topbar { padding: 0 16px; }
  .head h1 { font-size: 24px; }
  .page.narrow { padding-top: 40px; }
}
