/* Мобильный хаб в духе Telegram (тёмная тема) */
:root {
  --tg-bg: #0e1621;
  --tg-bg2: #17212b;
  --tg-bubble: #182533;
  --tg-bubble-border: #2b5278;
  --tg-accent: #5288c1;
  --tg-text: #e4ecf2;
  --tg-muted: #8a9aa8;
  --tg-btn: #2b5278;
  --tg-btn-active: #3d6a9a;
  --tg-safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body.tg-app {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  padding-bottom: calc(12px + var(--tg-safe-bottom));
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--tg-accent);
  text-decoration: none;
}

a:active {
  opacity: 0.85;
}

.tg-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--tg-bg2);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.tg-topbar__back {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--tg-accent);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

body.tg-app.is-sub .tg-topbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tg-topbar__title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.tg-topbar__end {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mobile-auth-slot {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(160px, 38vw);
}

.mobile-auth-user {
  font-size: 12px;
  color: var(--tg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 72px;
}

.mobile-auth-login {
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-accent);
  text-decoration: none;
  white-space: nowrap;
}

.mobile-auth-logout {
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(43, 82, 120, 0.35);
  color: var(--tg-accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.mobile-auth-logout:active {
  opacity: 0.88;
}

.tg-app.is-guest .mi-editor-only,
.tg-app.is-user .mi-editor-only {
  display: none !important;
}

.tg-app.is-editor .mi-guest-only,
.tg-app.is-user .mi-guest-only {
  display: none !important;
}

body.tg-app.is-guest .tg-panel.mi-editor-only.tg-panel--active,
body.tg-app.is-user .tg-panel.mi-editor-only.tg-panel--active {
  display: none !important;
}

.tg-topbar__lang {
  flex-shrink: 0;
  min-width: 44px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(43, 82, 120, 0.35);
  color: var(--tg-accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tg-topbar__lang:active {
  opacity: 0.88;
}

.tg-chat {
  padding: 12px 10px 100px;
  max-width: 520px;
  margin: 0 auto;
}

.tg-bubble {
  background: var(--tg-bubble);
  border: 1px solid rgba(43, 82, 120, 0.45);
  border-radius: 12px 12px 12px 4px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 15px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.tg-bubble p {
  margin: 0 0 8px;
}

.tg-bubble p:last-child {
  margin-bottom: 0;
}

.tg-bubble .tg-muted {
  color: var(--tg-muted);
  font-size: 14px;
}

.tg-bubble .tg-stats {
  font-size: 14px;
  color: var(--tg-muted);
  margin-top: 6px;
}

.tg-keyboard {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 8px calc(8px + var(--tg-safe-bottom));
  background: linear-gradient(to top, var(--tg-bg2) 80%, transparent);
  max-width: 520px;
  margin: 0 auto;
}

.tg-keyboard__grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tg-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.tg-row--2 .tg-btn {
  flex: 1;
  min-width: 0;
}

.tg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: var(--tg-btn);
  color: var(--tg-text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  line-height: 1.25;
  transition: background 0.15s, transform 0.05s;
}

.tg-btn:active {
  background: var(--tg-btn-active);
  transform: scale(0.98);
}

a.tg-btn {
  text-decoration: none;
}

.tg-panel {
  display: none;
  padding: 0 10px 100px;
  max-width: 520px;
  margin: 0 auto;
}

body.tg-app.is-sub .tg-chat {
  display: none;
}

body.tg-app.is-sub .tg-keyboard--main {
  display: none;
}

body.tg-app.is-sub .tg-panel--active {
  display: block;
}

.tg-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--tg-bubble-border);
  background: var(--tg-bg2);
  color: var(--tg-text);
  font-size: 16px;
  margin-bottom: 10px;
}

.tg-input:focus {
  outline: none;
  border-color: var(--tg-accent);
}

.tg-results {
  margin-top: 12px;
}

.tg-result-card {
  display: block;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--tg-bubble);
  border: 1px solid rgba(43, 82, 120, 0.4);
  border-radius: 10px;
  color: inherit;
}

.tg-result-card--with-card {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 10px;
}

.tg-result-thumb {
  width: 88px;
  min-width: 88px;
  height: auto;
  aspect-ratio: 800 / 1080;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(43, 82, 120, 0.5);
  background: var(--tg-bg);
  flex-shrink: 0;
}

.tg-result-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
}

.tg-result-card--with-card strong,
.tg-result-card--with-card small {
  display: block;
}

.tg-result-card:active {
  background: var(--tg-bg2);
}

.tg-result-card strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
}

.tg-result-card small {
  color: var(--tg-muted);
  font-size: 13px;
}

.tg-empty {
  color: var(--tg-muted);
  font-size: 14px;
  padding: 16px 0;
}

.tg-note {
  font-size: 13px;
  color: var(--tg-muted);
  margin-top: 8px;
  line-height: 1.4;
}

.tg-btn--sm {
  min-height: 38px;
  padding: 8px 14px;
  font-size: 14px;
  width: auto;
  flex: 0 0 auto;
}

.tg-btn--ghost {
  background: transparent;
  border: 1px solid rgba(82, 136, 193, 0.45);
  margin-top: 8px;
}

.tg-results-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tg-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 10px;
  margin: 10px 0;
}

@media (min-width: 480px) {
  .tg-pick-grid {
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  }
}

.tg-pick-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 8px;
  border: 2px solid rgba(103, 58, 183, 0.55);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--tg-text);
  cursor: pointer;
  text-align: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.tg-pick-card:hover,
.tg-pick-card:focus-visible {
  border-color: #03e9f4;
  box-shadow: 0 0 12px rgba(3, 233, 244, 0.25);
  background: rgba(3, 233, 244, 0.06);
  outline: none;
}

.tg-pick-card:active {
  transform: scale(0.98);
}

.tg-pick-thumb {
  width: 88px;
  height: 88px;
  object-fit: cover;
  object-position: top center;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tg-pick-ph {
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(26, 0, 26, 0.85);
  color: #673ab7;
  font-size: 22px;
  font-weight: 700;
  border: 1px solid rgba(103, 58, 183, 0.45);
}

.tg-pick-name {
  font-size: 12px;
  line-height: 1.25;
  word-break: break-word;
  font-weight: 600;
  color: var(--tg-text);
}

.tg-pick-class {
  font-size: 10px;
  color: var(--tg-muted);
  text-transform: capitalize;
}

.tg-pick-desc {
  font-size: 10px;
  line-height: 1.35;
  color: var(--tg-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
}

.tg-pick-role {
  color: #b388ff;
  font-weight: 700;
}

.tg-pick-action {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: #03e9f4;
  letter-spacing: 0.04em;
}

.tg-pick-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 12px;
}

.tg-breq {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed rgba(82, 136, 193, 0.45);
  background: rgba(0, 0, 0, 0.15);
}

.tg-breq-label {
  display: block;
  font-size: 12px;
  color: var(--tg-muted);
  margin: 8px 0 4px;
}

.tg-breq-note {
  resize: vertical;
  min-height: 72px;
}

.tg-breq-status {
  margin-top: 8px;
  font-size: 13px;
}

.tg-bubble--ok {
  border-color: rgba(76, 175, 80, 0.45);
  background: rgba(76, 175, 80, 0.08);
}

@media (min-width: 768px) {
  html {
    font-size: 17px;
  }

  .tg-chat,
  .tg-keyboard,
  .tg-panel {
    max-width: 640px;
  }
}

@media (min-width: 1024px) {
  .tg-chat,
  .tg-keyboard,
  .tg-panel {
    max-width: 720px;
  }

  .tg-btn {
    min-height: 48px;
    font-size: 16px;
  }

  .mobile-auth-slot {
    max-width: 220px;
  }

  .mobile-auth-user {
    max-width: 120px;
  }
}
