:root.tg-gate-open {
  overflow: hidden;
}

.tg-gate,
.tg-gate * {
  box-sizing: border-box;
}

.tg-gate {
  --tg-void: #09080f;
  --tg-panel: #12101b;
  --tg-panel-2: #191625;
  --tg-ink: #f5f2fb;
  --tg-muted: #a29bad;
  --tg-dim: #716a7d;
  --tg-violet: #b153f2;
  --tg-green: #2fe0a1;
  --tg-gold: #e2bd64;
  --tg-red: #ff657a;
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  color: var(--tg-ink);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

.tg-gate-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(3, 3, 8, 0.84);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tg-gate-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(100%, 430px);
  max-height: min(830px, calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow: hidden;
  border: 1px solid rgba(177, 83, 242, 0.52);
  border-radius: 8px;
  background: rgba(14, 12, 22, 0.97);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.68), 0 0 34px rgba(177, 83, 242, 0.16);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 180ms ease, transform 320ms cubic-bezier(.16, 1, .3, 1);
}

.tg-gate-panel.ready {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.tg-gate-topline {
  position: absolute;
  inset: 0 0 auto;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 0.62fr 0.34fr;
  height: 3px;
}

.tg-gate-topline span:nth-child(1) { background: var(--tg-violet); }
.tg-gate-topline span:nth-child(2) { background: var(--tg-green); }
.tg-gate-topline span:nth-child(3) { background: var(--tg-gold); }

.tg-gate-header {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 17px 18px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.tg-gate-kicker,
.tg-gate-agent,
.tg-gate-alert,
.tg-gate-readiness span,
.tg-gate-readiness strong,
.tg-gate-risk-title,
.tg-gate-setup-head,
.tg-gate-nodes,
.tg-gate-command,
.tg-gate-actions {
  font-family: "IBM Plex Mono", "Cascadia Mono", monospace;
  letter-spacing: 0;
}

.tg-gate-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c8c2d2;
  font-size: 10px;
  letter-spacing: 0.18em;
}

.tg-gate-kicker i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--tg-red);
  box-shadow: 0 0 12px rgba(255, 101, 122, 0.7);
  animation: tg-gate-pulse 1.4s ease-in-out infinite;
}

.tg-gate-agent {
  margin-top: 5px;
  color: var(--tg-dim);
  font-size: 9px;
  text-transform: uppercase;
}

.tg-gate-close {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
  color: #aaa3b6;
  font-size: 27px;
  line-height: 1;
}

.tg-gate-close:focus-visible,
.tg-gate-command button:focus-visible,
.tg-gate-actions a:focus-visible,
.tg-gate-actions button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.tg-gate-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(177, 83, 242, 0.55) transparent;
}

.tg-gate-hero {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}

.tg-gate-signal {
  position: relative;
  width: 62px;
  height: 62px;
  border: 1px solid rgba(255, 101, 122, 0.46);
  border-radius: 7px;
  background: rgba(255, 101, 122, 0.055);
}

.tg-gate-signal span {
  position: absolute;
  left: 13px;
  bottom: 13px;
  width: 7px;
  border-radius: 2px 2px 0 0;
  background: var(--tg-red);
  opacity: 0.35;
}

.tg-gate-signal span:nth-child(1) { height: 10px; }
.tg-gate-signal span:nth-child(2) { left: 25px; height: 20px; }
.tg-gate-signal span:nth-child(3) { left: 37px; height: 31px; }
.tg-gate-signal b {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 7px;
  height: 7px;
  border: 1px solid var(--tg-red);
  border-radius: 50%;
}

.tg-gate-alert {
  color: var(--tg-red);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.tg-gate h1 {
  margin: 4px 0 5px;
  color: var(--tg-ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: clamp(25px, 8vw, 34px);
  line-height: 1;
  letter-spacing: 0;
}

.tg-gate-hero p {
  margin: 0;
  color: var(--tg-muted);
  font-size: 13px;
  line-height: 1.45;
}

.tg-gate-readiness {
  margin-top: 18px;
  padding: 13px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.tg-gate-readiness > div:first-child,
.tg-gate-setup-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tg-gate-readiness span,
.tg-gate-readiness strong,
.tg-gate-setup-head {
  font-size: 8px;
  letter-spacing: 0.13em;
}

.tg-gate-readiness span { color: var(--tg-dim); }
.tg-gate-readiness strong { color: var(--tg-gold); }

.tg-gate-meter {
  height: 6px;
  margin: 9px 0;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
}

.tg-gate-meter i {
  display: block;
  width: 50%;
  height: 100%;
  background: var(--tg-green);
  transform-origin: left;
  animation: tg-gate-meter 520ms cubic-bezier(.16, 1, .3, 1) both;
}

.tg-gate-nodes {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 7.5px;
  letter-spacing: 0.1em;
}

.tg-gate-nodes .online { color: var(--tg-green); }
.tg-gate-nodes .offline { color: var(--tg-red); }
.tg-gate-nodes [data-telegram-onboarding-status="linked"] { color: var(--tg-green); }

.tg-gate-risk-title {
  margin: 17px 0 8px;
  color: var(--tg-dim);
  font-size: 8px;
  letter-spacing: 0.16em;
}

.tg-gate-risks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
}

.tg-gate-risks div {
  min-width: 0;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  padding: 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.tg-gate-risks div:nth-child(2n) { border-right: 0; }
.tg-gate-risks div:nth-last-child(-n+2) { border-bottom: 0; }
.tg-gate-risks span {
  grid-row: 1 / 3;
  color: var(--tg-red);
  font-family: "IBM Plex Mono", monospace;
  font-size: 9px;
}
.tg-gate-risks b {
  overflow-wrap: anywhere;
  font-size: 11px;
  line-height: 1.2;
}
.tg-gate-risks small {
  margin-top: 3px;
  color: var(--tg-dim);
  font-size: 9px;
  line-height: 1.25;
}

.tg-gate-setup {
  margin-top: 15px;
  padding: 13px;
  border: 1px solid rgba(226, 189, 100, 0.28);
  border-radius: 6px;
  background: rgba(226, 189, 100, 0.035);
}

.tg-gate-setup-head {
  color: var(--tg-gold);
}

.tg-gate-setup-head strong {
  color: var(--tg-dim);
  font-weight: 500;
}

.tg-gate-setup ol {
  display: grid;
  gap: 9px;
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.tg-gate-setup li {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
}

.tg-gate-setup li > span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(177, 83, 242, 0.48);
  border-radius: 4px;
  color: #d9a7ff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 9px;
}

.tg-gate-setup li b,
.tg-gate-setup li small {
  display: block;
}

.tg-gate-setup li b { font-size: 11px; }
.tg-gate-setup li small {
  margin-top: 2px;
  color: var(--tg-dim);
  font-size: 9px;
}

.tg-gate-command {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 45px;
  overflow: hidden;
  border: 1px solid rgba(177, 83, 242, 0.42);
  border-radius: 5px;
  background: rgba(5, 4, 9, 0.72);
}

.tg-gate-command code {
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 11px 12px;
  color: #e4c4ff;
  font-size: 12px;
}

.tg-gate-command button {
  align-self: stretch;
  min-width: 64px;
  border: 0;
  border-left: 1px solid rgba(177, 83, 242, 0.32);
  background: rgba(177, 83, 242, 0.15);
  color: #e4c4ff;
  font: 9px "IBM Plex Mono", monospace;
}

.tg-gate-command.unavailable {
  border-color: rgba(255, 101, 122, 0.3);
}

.tg-gate-command button:disabled {
  color: var(--tg-dim);
  background: transparent;
}

.tg-gate-result {
  min-height: 17px;
  padding-top: 9px;
  color: var(--tg-muted);
  font-size: 10px;
  line-height: 1.35;
}

.tg-gate-result[data-tone="success"] { color: var(--tg-green); }
.tg-gate-result[data-tone="error"] { color: var(--tg-red); }
.tg-gate-result[data-tone="checking"] { color: var(--tg-gold); }

.tg-gate-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  padding: 12px 18px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 8, 15, 0.96);
}

.tg-gate-actions a,
.tg-gate-actions button {
  min-width: 0;
  min-height: 47px;
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 5px;
  font: 9px "IBM Plex Mono", monospace;
  letter-spacing: 0.1em;
  text-align: center;
  text-decoration: none;
}

.tg-gate-actions a {
  border: 1px solid rgba(47, 224, 161, 0.65);
  background: rgba(47, 224, 161, 0.13);
  color: #78f5c8;
}

.tg-gate-actions button {
  border: 1px solid rgba(177, 83, 242, 0.58);
  background: rgba(177, 83, 242, 0.14);
  color: #dda9ff;
}

.tg-gate-actions button:disabled {
  opacity: 0.62;
}

.tg-gate.connected .tg-gate-panel {
  border-color: rgba(47, 224, 161, 0.7);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.68), 0 0 38px rgba(47, 224, 161, 0.2);
}

@keyframes tg-gate-meter {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes tg-gate-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

@media (max-width: 360px) {
  .tg-gate { padding-left: 8px; padding-right: 8px; }
  .tg-gate-header,
  .tg-gate-scroll { padding-left: 13px; padding-right: 13px; }
  .tg-gate-actions { padding-left: 13px; padding-right: 13px; }
  .tg-gate-hero { grid-template-columns: 52px minmax(0, 1fr); gap: 11px; }
  .tg-gate-signal { width: 50px; height: 58px; }
  .tg-gate-signal span { left: 9px; }
  .tg-gate-signal span:nth-child(2) { left: 20px; }
  .tg-gate-signal span:nth-child(3) { left: 31px; }
}

@media (prefers-reduced-motion: reduce) {
  .tg-gate-panel,
  .tg-gate-meter i,
  .tg-gate-kicker i {
    animation: none;
    transition-duration: 1ms;
  }
}
