/* Адаптив: mobile-first — телефоны и планшеты (< 1024px) */

:root {
  --app-mobile-bar-h: 52px;
  --app-top-nav-h: 58px;
  --app-header-mobile-h: calc(var(--app-mobile-bar-h) + var(--app-top-nav-h));
  --app-safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-safe-top: env(safe-area-inset-top, 0px);
  --touch-min: 44px;
}

/* Быстрый отклик на тач (без задержки double-tap zoom ~300ms) */
@media (max-width: 1023px) {
  .app-header-mobile a,
  .app-header-mobile button,
  .app-top-nav__item {
    touch-action: manipulation;
  }
}

/* ========== App shell (по умолчанию = мобильный) ========== */
.layout-app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100dvh;
  min-width: 0;
  width: 100%;
}

.app-header-mobile {
  order: 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 120;
  width: 100%;
  padding-top: var(--app-safe-top);
  background: linear-gradient(180deg, #0c1730 0%, #091327 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.app-mobile-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: var(--app-mobile-bar-h);
  padding: 6px 12px 4px;
}

.app-menu-btn {
  flex-shrink: 0;
  width: var(--touch-min);
  height: var(--touch-min);
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.12);
}

.app-menu-btn:active {
  background: rgba(255, 255, 255, 0.16);
  transform: scale(0.94);
}

.app-menu-btn__icon,
.app-menu-btn__icon::before,
.app-menu-btn__icon::after {
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  position: relative;
}

.app-menu-btn__icon::before,
.app-menu-btn__icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.app-menu-btn__icon::before {
  top: -6px;
}

.app-menu-btn__icon::after {
  top: 6px;
}

.app-mobile-logo {
  flex: 1;
  display: flex;
  justify-content: center;
  min-width: 0;
}

.app-mobile-logo img {
  display: block;
  height: 28px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
}

.app-mobile-meta {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: #4ade80;
  white-space: nowrap;
}

.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 130;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.layout-app.is-nav-open .app-sidebar-backdrop:not([hidden]) {
  display: block;
}

.sidebar-app {
  order: 1;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 140;
  width: min(300px, 88vw);
  max-width: 100%;
  flex-shrink: 0;
  padding: calc(16px + var(--app-safe-top)) 18px calc(16px + var(--app-safe-bottom));
  transform: translateX(-105%);
  transition: transform 0.28s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 8px 0 40px rgba(0, 0, 0, 0.45);
}

.layout-app.is-nav-open .sidebar-app {
  transform: translateX(0);
}

.sidebar-app .logo-block {
  margin-left: 0;
  margin-top: 0;
  margin-bottom: 12px;
}

.sidebar-app .logo-block img {
  max-width: 200px;
}

.page-offroad .sidebar-app .logo-block img {
  max-width: 200px;
}

.main-app {
  order: 2;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 16px 14px calc(20px + var(--app-safe-bottom));
  overflow-x: hidden;
  overflow-y: auto;
}

.app-top-nav {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  min-height: var(--app-top-nav-h);
  padding: 4px 6px 8px;
  background: linear-gradient(180deg, rgba(10, 18, 38, 0.6) 0%, rgba(12, 23, 48, 0.95) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.app-top-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: var(--touch-min);
  padding: 2px 4px;
  border: none;
  background: transparent;
  color: #94a3b8;
  text-decoration: none;
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: 12px;
  -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
  user-select: none;
  -webkit-user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  .app-top-nav__item {
    transition: color 0.15s ease;
  }

  .app-top-nav__item:hover {
    color: #cbd5e1;
  }
}

.app-top-nav__item.is-pressed,
.app-top-nav__item:active {
  color: #fff;
}

.app-top-nav__item.is-active {
  color: #fff;
}

.app-top-nav__item.is-active .app-top-nav__icon-wrap {
  background: linear-gradient(145deg, rgba(255, 45, 45, 0.22) 0%, rgba(214, 0, 0, 0.12) 100%);
  border-color: rgba(255, 90, 90, 0.45);
  color: #ff8a8a;
  box-shadow: 0 4px 14px rgba(255, 45, 45, 0.2);
}

.app-top-nav__icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: inherit;
}

.app-top-nav__item.is-pressed .app-top-nav__icon-wrap,
.app-top-nav__item:active .app-top-nav__icon-wrap {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(0.92);
}

@media (hover: hover) and (pointer: fine) {
  .app-top-nav__icon-wrap {
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  }
}

.app-top-nav__icon {
  width: 22px;
  height: 22px;
  display: block;
}

.app-top-nav__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  line-height: 1.1;
}

body.app-nav-open {
  overflow: hidden;
}

.body-app .site-footer {
  padding-bottom: calc(12px + var(--app-safe-bottom));
}

/* Десктоп: классическая боковая панель */
@media (min-width: 1024px) {
  .layout-app {
    flex-direction: row;
    min-height: 0;
  }

  .app-header-mobile,
  .app-sidebar-backdrop {
    display: none !important;
  }

  .sidebar-app {
    position: static;
    order: 0;
    width: 260px;
    transform: none;
    transition: none;
    box-shadow: none;
    overflow-y: auto;
    padding: 24px 18px;
  }

  .page-offroad .sidebar-app .logo-block img {
    max-width: 430px;
  }

  .main-app {
    order: 0;
    padding: 28px;
    overflow-y: auto;
  }

  body.app-nav-open {
    overflow: auto;
  }

  .body-app .site-footer {
    padding-bottom: 1.25rem;
  }
}

/* === Тач-цели === */
@media (max-width: 1023px) {
  .menu-app a,
  .logout-btn,
  .btn,
  button,
  .back-btn,
  .pay-chip,
  .payments-submit,
  .mode-btn,
  .btn-profile,
  .btn-red,
  .page-offroad .btn,
  .page-offroad .back {
    min-height: var(--touch-min);
  }

  input,
  select,
  textarea,
  .input,
  .auth-form input,
  .payments-input {
    font-size: 16px;
    min-height: var(--touch-min);
  }

  .site-footer {
    font-size: 0.8rem;
    padding: 1rem 1rem 1.25rem;
    text-align: center;
  }
}

/* === Auth === */
@media (max-width: 600px) {
  .auth-body .auth-container {
    padding: 1rem 12px;
    align-items: flex-start;
  }

  .auth-card {
    padding: 22px 18px;
    border-radius: 18px;
  }
}

/* === Dashboard === */
@media (max-width: 768px) {
  .page-dashboard .container {
    padding: 0;
    max-width: 100%;
  }

  .page-dashboard .hero {
    min-height: 280px;
    padding: 20px 16px;
    border-radius: 18px;
  }

  .page-dashboard .hero h1 {
    font-size: clamp(1.5rem, 7vw, 2rem);
  }

  .page-dashboard .hero-buttons {
    flex-direction: column;
  }

  .page-dashboard .hero-buttons a {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .page-dashboard .cards-3 {
    grid-template-columns: 1fr;
  }

  .page-dashboard .dash-quests-head {
    flex-direction: column;
  }

  .page-dashboard .dash-quests-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-dashboard .dash-quests-grid--daily {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-dashboard .dash-quests-grid--weekly {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-dashboard .track-card {
    min-height: 180px;
  }
}

@media (max-width: 480px) {
  .page-dashboard .dash-quests-stats {
    grid-template-columns: 1fr;
  }

  .page-dashboard .dash-quests-grid--daily,
  .page-dashboard .dash-quests-grid--weekly {
    grid-template-columns: 1fr;
  }
}

/* === OFFROAD === */
@media (max-width: 900px) {
  .page-offroad .offroad-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .page-offroad .wrap {
    padding: 0 0 24px;
  }

  .page-offroad .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .page-offroad .back {
    text-align: center;
    display: block;
  }
}

@media (max-width: 600px) {
  .page-offroad .cars-track-tab {
    flex: 1 1 calc(50% - 8px);
    font-size: 13px;
    padding: 10px 12px;
  }
}

@media (max-width: 400px) {
  .page-offroad .cars-track-tab {
    flex: 1 1 100%;
  }
}

/* === Quests === */
@media (max-width: 768px) {
  .page-quests {
    padding: 0 0 1rem;
  }

  .quests-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .quests-grid {
    grid-template-columns: 1fr;
  }
}

/* === Payments === */
@media (max-width: 768px) {
  .page-payments {
    padding: 0 4px 24px;
  }

  .payments-input,
  .payments-submit {
    max-width: 100%;
    width: 100%;
  }

  .payments-submit {
    align-self: stretch;
    text-align: center;
  }

  .payments-table-wrap {
    margin: 0 -4px;
    border-radius: 12px;
    overflow-x: auto;
  }

  .payments-table {
    font-size: 13px;
    min-width: 480px;
  }

  .payments-table th,
  .payments-table td {
    padding: 10px 8px;
  }
}

/* === Sessions === */
@media (max-width: 768px) {
  .page-sessions {
    padding: 0 4px 24px;
  }

  .page-sessions .sessions-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-sessions .sessions-stats {
    grid-template-columns: 1fr;
  }
}

/* === Company in app === */
@media (max-width: 768px) {
  .page-company-app,
  .company-info-page {
    padding: 0 4px 24px;
  }
}

/* === Landing === */
@media (max-width: 768px) {
  .landing-top-inner {
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
  }

  .landing-nav {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }
}

/* === Control === */
@media (max-width: 480px) {
  .page-control .topbar-actions {
    width: 100%;
  }

  .page-control .back-btn {
    width: 100%;
    text-align: center;
  }

  .page-control .mode-switch-3 {
    flex-direction: column;
  }

  .page-control .mode-switch-3 .mode-btn {
    width: 100%;
  }
}
