/* ==========================================================================
   DARK THEME TOKENS, SHELL, SPLASH SCREEN, MINIMAL HEADER & BOTTOM NAV
   ========================================================================== */
:root {
  --outer-bg: #070A10;
  --app-bg: #0D111A;
  --surface: #151C28;
  --surface-elevated: #1C2536;
  --surface-subtle: #111722;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);

  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #7E8BA3;

  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --primary-glow: rgba(59, 130, 246, 0.28);
  --chip-bg: rgba(59, 130, 246, 0.14);
  --chip-text: #93C5FD;
  --chip-border: rgba(59, 130, 246, 0.34);

  --star-active: #FBBF24;
  --star-inactive: #334155;

  --badge-amber-bg: rgba(245, 158, 11, 0.14);
  --badge-amber-text: #FCD34D;
  --badge-amber-border: rgba(245, 158, 11, 0.3);

  --badge-green-bg: rgba(34, 197, 94, 0.14);
  --badge-green-text: #4ADE80;
  --badge-green-border: rgba(34, 197, 94, 0.3);

  --badge-coral-bg: rgba(249, 115, 22, 0.15);
  --badge-coral-text: #FDBA74;
  --badge-coral-border: rgba(249, 115, 22, 0.32);

  --badge-red-bg: rgba(239, 68, 68, 0.15);
  --badge-red-text: #FCA5A5;
  --badge-red-border: rgba(239, 68, 68, 0.32);

  --badge-sky-bg: rgba(56, 189, 248, 0.14);
  --badge-sky-text: #7DD3FC;
  --badge-sky-border: rgba(56, 189, 248, 0.3);

  --radius-card: 18px;
  --radius-md: 13px;
  --radius-pill: 999px;
  --shadow-phone: 0 28px 70px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.06);
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.22);
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --header-height: 66px;
  --nav-height: 64px;
  --tg-top-inset: env(safe-area-inset-top, 0px);
  --tg-bottom-inset: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  background-color: var(--app-bg);
  overflow-x: clip;
  overscroll-behavior-x: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--app-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
  overflow-x: clip;
  overscroll-behavior-x: none;
  -webkit-font-smoothing: antialiased;
  -webkit-overflow-scrolling: touch;
  color-scheme: dark;
}

@media (min-width: 501px) {
  html:not(.is-tg-mobile) body {
    background: radial-gradient(circle at top center, #131B2E 0%, var(--outer-bg) 70%);
  }
}

html.in-chat-mode,
html.in-chat-mode body {
  height: 100%;
  overflow: hidden;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

a {
  color: #60A5FA;
  text-decoration: none;
}

/* Native document scroll shell with truly fixed header & bottom nav */
.viewport-wrapper {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app-shell {
  width: 100%;
  max-width: 450px;
  min-height: 100dvh;
  background-color: var(--app-bg);
  box-shadow: var(--shadow-phone);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}

html.is-tg-mobile .app-shell {
  max-width: 100%;
  box-shadow: none;
  border-left: none;
  border-right: none;
}

html.in-chat-mode .viewport-wrapper {
  height: var(--app-viewport-height, var(--tg-viewport-height, 100dvh));
  min-height: 0;
  overflow: hidden;
}

html.in-chat-mode .app-shell {
  position: fixed;
  top: var(--vv-offset-top, 0px);
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 450px;
  height: var(--app-viewport-height, var(--tg-viewport-height, 100dvh));
  min-height: 0;
  overflow: hidden;
  z-index: 35;
}

html.in-chat-mode.is-tg-mobile .app-shell {
  left: 0;
  right: 0;
  transform: none;
  max-width: 100%;
}

@media (max-width: 500px) {
  .app-shell {
    max-width: 100%;
    box-shadow: none;
    border-left: none;
    border-right: none;
  }
  html.in-chat-mode .app-shell {
    left: 0;
    right: 0;
    transform: none;
    max-width: 100%;
  }
}

/* ==========================================================================
   STARTUP SPLASH SCREEN
   ========================================================================== */
.splash-screen {
  position: absolute;
  inset: 0;
  z-index: 90;
  background: radial-gradient(circle at 50% 35%, #17233B 0%, #0B0F17 75%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  border-radius: inherit;
  transition: opacity 0.42s var(--ease-smooth), transform 0.42s var(--ease-smooth), visibility 0.42s;
}

.splash-screen.is-hidden {
  opacity: 0;
  transform: scale(1.03);
  visibility: hidden;
  pointer-events: none;
}

.splash-orb {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.26) 0%, rgba(99, 102, 241, 0.18) 100%);
  border: 1px solid rgba(96, 165, 250, 0.4);
  color: #60A5FA;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 36px rgba(59, 130, 246, 0.35);
  animation: splashFloat 2.2s ease-in-out infinite;
}

.splash-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(90deg, #F8FAFC 0%, #93C5FD 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.splash-sub {
  font-size: 13px;
  color: var(--text-muted);
}

.splash-dots {
  display: flex;
  gap: 7px;
  margin-top: 8px;
}

.splash-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background-color: #60A5FA;
  animation: dotPulse 1.1s ease-in-out infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.18s; }
.splash-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes splashFloat {
  0%, 100% { transform: translateY(0); box-shadow: 0 0 30px rgba(59, 130, 246, 0.28); }
  50% { transform: translateY(-5px); box-shadow: 0 0 44px rgba(59, 130, 246, 0.45); }
}

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.15); }
}

/* ==========================================================================
   MINIMALIST FIXED HEADER (POSITION: FIXED)
   ========================================================================== */
.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 450px;
  z-index: 40;
  min-height: calc(var(--header-height) + var(--tg-top-inset, 0px));
  background: rgba(13, 17, 26, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--tg-top-inset, 0px) + 4px) 16px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

html.is-tg-mobile .app-header {
  left: 0;
  transform: none;
  max-width: 100%;
}

@media (max-width: 500px) {
  .app-header {
    left: 0;
    transform: none;
    max-width: 100%;
  }
}

.header-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}

.header-logo-badge {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.24), rgba(37, 99, 235, 0.14));
  border: 1px solid rgba(96, 165, 250, 0.34);
  color: #60A5FA;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-mode-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--chip-text);
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  padding: 2px 7px;
  border-radius: 999px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13.5px;
  font-weight: 600;
  color: #60A5FA;
  padding: 6px 10px 6px 4px;
  border-radius: 10px;
  transition: background-color 0.2s var(--ease-smooth), transform 0.15s ease;
}

.header-back-btn:hover { background-color: rgba(59, 130, 246, 0.12); }
.header-back-btn:active { transform: scale(0.96); }

.header-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  background-color: var(--surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
  white-space: nowrap;
  transition: all 0.2s var(--ease-smooth);
}

.header-pill-btn:hover {
  border-color: var(--chip-border);
  color: var(--text-primary);
  background-color: #243045;
}

.header-pill-btn.is-admin {
  background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
  color: #FFFFFF;
  border-color: transparent;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.header-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  transition: all 0.2s var(--ease-smooth);
}
.header-icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.header-pill-btn .count-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background-color: var(--primary);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
}

/* Main content area (native document scroll for pages; fixed height for chat mode) */
.app-main {
  flex: 1 0 auto;
  padding: calc(var(--header-height) + var(--tg-top-inset, 0px) + 14px) 14px calc(24px + var(--tg-bottom-inset, 0px));
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
}

.app-main.has-bottom-nav {
  padding-bottom: calc(var(--nav-height) + var(--tg-bottom-inset, 0px) + 20px);
}

html.is-keyboard-open:not(.in-chat-mode) .app-main,
html.is-keyboard-open:not(.in-chat-mode) .app-main.has-bottom-nav {
  padding-bottom: calc(var(--keyboard-height, 260px) + 48px);
}

.app-main.chat-mode,
.app-main.chat-mode.has-bottom-nav,
html.is-keyboard-open .app-main.chat-mode,
html.is-keyboard-open .app-main.chat-mode.has-bottom-nav {
  flex: 1 1 0;
  height: auto;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  gap: 0;
}

html.in-chat-mode .app-header,
html.in-chat-mode .bottom-nav {
  position: static;
  left: auto;
  transform: none;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
}

.view-wrap {
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
}

.view-wrap.view-animate {
  animation: viewEnter 0.22s var(--ease-smooth);
}

.app-main.chat-mode .view-wrap {
  gap: 0;
  flex: 1 1 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

@keyframes viewEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Fixed Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 450px;
  z-index: 40;
  min-height: calc(var(--nav-height) + var(--tg-bottom-inset, 0px));
  background: rgba(17, 23, 34, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 5px 8px calc(6px + var(--tg-bottom-inset, 0px));
}

html.is-tg-mobile .bottom-nav {
  left: 0;
  transform: none;
  max-width: 100%;
}

@media (max-width: 500px) {
  .bottom-nav {
    left: 0;
    transform: none;
    max-width: 100%;
  }
}

.bottom-nav.hidden,
html.is-keyboard-open .bottom-nav {
  display: none !important;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  border-radius: 12px;
  transition: color 0.2s var(--ease-smooth), transform 0.15s ease, background-color 0.2s ease;
  position: relative;
  padding: 4px;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.9;
  transition: transform 0.2s var(--ease-smooth);
}

.nav-item.active {
  color: #60A5FA;
  font-weight: 600;
}

.nav-item.active svg {
  transform: translateY(-1px) scale(1.06);
}

.nav-item:active {
  transform: scale(0.93);
  background-color: rgba(255, 255, 255, 0.04);
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 18px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background-color: var(--primary);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #111722;
}
