:root {
  color-scheme: light dark;
  --page: var(--tg-theme-bg-color, #f4f7fb);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #172033);
  --muted: var(--tg-theme-hint-color, #6b7484);
  --link: var(--tg-theme-link-color, #1e5aa8);
  --button: var(--tg-theme-button-color, #0d766e);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --border: color-mix(in srgb, var(--text) 11%, transparent);
  --brand: #1e3a5f;
  --success: #07896f;
  --danger: #c33d4c;
  --shadow: 0 12px 32px rgba(16, 32, 55, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--page);
  font-family: Tahoma, Arial, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(100%, 540px);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-radius: 12px;
  color: #ffffff;
  background: var(--brand);
}

.brand-mark svg {
  width: 25px;
  fill: currentColor;
}

.brand-mark .brand-cut {
  fill: none;
  stroke: var(--success);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-name,
.brand-subtitle,
.eyebrow,
.hero-copy,
.account-name,
.account-email,
.loading-label,
.state-copy,
footer {
  margin: 0;
}

.brand-name {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  margin-top: -3px;
  color: var(--muted);
  font-size: 0.72rem;
}

.secure-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin-right: auto;
  padding-inline: 10px;
  border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
  border-radius: 999px;
  color: var(--success);
  background: color-mix(in srgb, var(--success) 8%, transparent);
  font-size: 0.68rem;
  font-weight: 700;
}

.secure-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 13%, transparent);
}

.hero {
  padding: 42px 2px 24px;
}

.eyebrow {
  color: var(--success);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

h1,
h2 {
  margin: 7px 0 0;
  line-height: 1.35;
  letter-spacing: -0.035em;
}

h1 {
  max-width: 390px;
  font-size: clamp(1.75rem, 8vw, 2.35rem);
  font-weight: 900;
}

h2 {
  font-size: 1.35rem;
}

.hero-copy {
  max-width: 430px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 1rem;
}

.account-panel,
.state-panel {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.account-panel {
  padding: 18px;
}

.account-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.account-avatar {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  place-items: center;
  border-radius: 15px;
  color: #ffffff;
  background: var(--brand);
  font-size: 1.12rem;
  font-weight: 900;
}

.account-person {
  min-width: 0;
  flex: 1;
}

.account-name {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-email {
  overflow: hidden;
  margin-top: 1px;
  color: var(--muted);
  direction: ltr;
  font-size: 0.76rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--success);
  font-size: 0.72rem;
  font-weight: 800;
}

.verified-badge svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin-top: 18px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--border);
}

.metric {
  display: flex;
  min-width: 0;
  min-height: 100px;
  padding: 13px 10px;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface);
}

.metric:first-child {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 32px minmax(0, 1fr);
  grid-template-rows: auto auto;
  min-height: 82px;
  align-content: center;
  column-gap: 11px;
}

.metric:first-child .metric-icon {
  grid-row: 1 / 3;
}

.metric:first-child .metric-label {
  margin-top: 0;
}

.metric-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 8px;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 9%, transparent);
}

.metric-icon svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.metric-label {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.68rem;
}

.metric-value {
  width: 100%;
  margin-top: 1px;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.metric:first-child .metric-value {
  font-size: 1rem;
}

.actions {
  margin-top: 16px;
}

.button {
  display: flex;
  width: 100%;
  min-height: 52px;
  padding: 12px 18px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 14px;
  font-weight: 800;
  text-decoration: none;
  touch-action: manipulation;
  transition: transform 160ms ease, opacity 160ms ease, background-color 160ms ease;
}

.button svg {
  width: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button-primary {
  border: 1px solid transparent;
  color: var(--button-text);
  background: var(--button);
}

.button-secondary {
  margin-top: 10px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
}

.button:hover {
  opacity: 0.92;
}

.button:active {
  transform: scale(0.985);
}

.button:focus-visible,
.text-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--link) 45%, transparent);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.security-note {
  display: flex;
  margin: 13px 2px 0;
  align-items: flex-start;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.security-note svg {
  width: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.state-panel {
  padding: 28px 20px;
  text-align: center;
}

.state-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-inline: auto;
  place-items: center;
  border-radius: 15px;
  font-size: 1.25rem;
  font-weight: 900;
}

.state-icon-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.redirect-loader {
  display: flex;
  width: max-content;
  min-height: 48px;
  margin: 0 auto 12px;
  align-items: center;
  gap: 8px;
}

.redirect-loader span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  animation: breathe 700ms ease-in-out infinite alternate;
}

.redirect-loader span:nth-child(2) {
  animation-delay: 120ms;
}

.redirect-loader span:nth-child(3) {
  animation-delay: 240ms;
}

.state-copy {
  margin: 8px auto 18px;
  color: var(--muted);
  font-size: 0.86rem;
}

.state-panel .button-primary,
.state-panel .button-secondary {
  margin-top: 12px;
}

.text-button {
  min-height: 44px;
  margin-top: 8px;
  padding-inline: 16px;
  border: 0;
  color: var(--link);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 700;
}

.state-page {
  display: grid;
  place-items: center;
}

.state-page .state-panel {
  width: 100%;
}

.direct-entry {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.direct-entry .state-panel {
  width: 100%;
  margin-block: auto;
}

.direct-entry footer {
  padding-top: 0;
}

.loading-label {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.skeleton {
  display: block;
  border-radius: 8px;
  background: color-mix(in srgb, var(--text) 9%, transparent);
  animation: breathe 1.3s ease-in-out infinite alternate;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 15px;
}

.skeleton-title {
  width: 58%;
  height: 14px;
}

.skeleton-line {
  width: 78%;
  height: 10px;
  margin-top: 9px;
}

.skeleton-metric {
  height: 90px;
  border-radius: 0;
}

.skeleton-metric:first-child {
  grid-column: 1 / -1;
  height: 70px;
}

footer {
  padding-top: 24px;
  color: var(--muted);
  font-size: 0.67rem;
  text-align: center;
}

[hidden] {
  display: none !important;
}

@keyframes breathe {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

@media (max-width: 360px) {
  .shell {
    padding-inline: 13px;
  }

  .secure-pill {
    padding-inline: 8px;
    font-size: 0.63rem;
  }

  .metric {
    padding-inline: 7px;
  }

  .metric-value {
    font-size: 0.7rem;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: var(--tg-theme-bg-color, #0f172a);
    --surface: var(--tg-theme-secondary-bg-color, #172033);
    --text: var(--tg-theme-text-color, #f4f7fb);
    --muted: var(--tg-theme-hint-color, #aab3c3);
    --border: rgba(255, 255, 255, 0.1);
    --brand: #3d6696;
    --success: #31b89e;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
