/**
 * Mobile-First Responsive Design
 * Breakpoints: 320px+ mobile, <600px mobile, 600px–1024px tablet, >1024px desktop
 */
:root {
  --bp-mobile: 600px;
  --bp-tablet: 1024px;
  --bottom-nav-height: 56px;
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --touch-min: 44px;
}

html, body {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.app-root, .app-body, .app-panels, .app-panel {
  min-width: 0;
  overflow-x: hidden;
}

/* ========== Touch targets: минимум 44×44px для интерактивных элементов ========== */
button:not(.bottom-nav-link):not(.lang-option),
input[type="text"],
input[type="number"],
input[type="url"],
input[type="password"],
input[type="datetime-local"],
select,
textarea {
  min-height: var(--touch-min);
}
button:not(.bottom-nav-link):not(.lang-option) {
  min-width: var(--touch-min);
  padding: 10px 14px;
  cursor: pointer;
}
a[href] {
  cursor: pointer;
}
/* Кнопки в хедере и мелкие контролы — минимум 44×44px для тапа */
#userInfoCopyId {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 599px) {
  #apiWidgetButton,
  #planBadge,
  #btnLocation,
  .lang-option,
  #btnLogin,
  #btnLogout {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    padding: 10px 12px;
  }
  .lang-option {
    min-width: 40px;
  }
}

/* ========== Main app layout ========== */
/* Mobile: single column, bottom nav; reserve space for nav */
.app-root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.app-body {
  flex: 1;
  padding-bottom: 0;
}
@media (max-width: 599px) {
  .app-body {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom));
  }
}
@media (max-width: 420px) {
  :root {
    --bottom-nav-height: 100px;
  }
}

/* Bottom navigation — visible only on mobile */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: auto;
  min-height: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom));
  padding: 8px env(safe-area-inset-right, 0) calc(8px + var(--safe-area-inset-bottom)) env(safe-area-inset-left, 0);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(51, 65, 85, 0.8);
  z-index: 50;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
@media (max-width: 599px) {
  .bottom-nav {
    display: flex;
  }
}
@media (min-width: 600px) {
  .bottom-nav {
    display: none !important;
  }
  .desktop-panel-nav {
    display: flex !important;
  }
}
.desktop-panel-nav .desktop-panel-link.active {
  background: rgba(37, 99, 235, 0.2);
  border-color: #2563eb;
  color: #e2e8f0;
}
.bottom-nav a,
.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  min-width: 64px;
  color: #94a3b8;
  font-size: 10px;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.bottom-nav a:hover,
.bottom-nav button:hover {
  color: #e2e8f0;
  background: rgba(51, 65, 85, 0.5);
}
.bottom-nav a.active,
.bottom-nav button.active {
  color: #2563eb;
}
.bottom-nav .nav-icon {
  font-size: 1.25rem;
  line-height: 1;
}
@media (max-width: 599px) {
  .bottom-nav-link {
    min-width: 44px;
    min-height: 44px;
    flex: 1 1 auto;
    padding: 6px 4px;
    font-size: 9px;
  }
  .bottom-nav {
    justify-content: space-around;
  }
}
.bottom-nav-more-wrap {
  position: relative;
}
.more-menu-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  padding: 6px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(51, 65, 85, 0.9);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 60;
}
.more-menu-panel:not(.hidden) {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.more-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  color: #e2e8f0;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.more-menu-item:hover {
  background: rgba(51, 65, 85, 0.6);
}

/* Main content grid: mobile 1 col → tablet 2 col → desktop 2 col wider */
.responsive-main-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .responsive-main-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
}
@media (min-width: 1024px) {
  .responsive-main-grid {
    grid-template-columns: minmax(0, 2.2fr) minmax(0, 2.5fr);
    gap: 1.5rem;
  }
}

/* Панели: одна активна, остальные скрыты; переключение кнопками снизу */
.app-panels {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.app-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.app-panel.panel-active {
  display: flex;
  animation: panelFadeIn 0.25s ease;
}
@keyframes panelFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Card/section polish: depth and focus */
.device-features-section,
.app-body section[class*="rounded-2xl"][class*="border"] {
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
@media (min-width: 600px) {
  .device-features-section,
  .app-body section[class*="rounded-2xl"][class*="border"] {
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  }
}

/* Hero/summary row */
.responsive-hero-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 600px) {
  .responsive-hero-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 1024px) {
  .responsive-hero-grid {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  }
}

/* Coach chat: full-screen overlay on mobile when opened */
.coach-section-wrap {
  position: relative;
}
@media (max-width: 599px) {
  .coach-chat-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom) + 1rem);
  }
  .coach-chat-fullscreen .coach-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
  }
  .coach-chat-fullscreen #coachChat {
    flex: 1;
    min-height: 120px;
    max-height: none;
  }
  .coach-chat-fullscreen .coach-chat-actions {
    margin-top: 0.75rem;
  }
  .coach-chat-fullscreen #coachFullscreenClose {
    display: inline-flex !important;
  }
  .coach-chat-fullscreen #coachFullscreenBtn {
    display: none !important;
  }
}

/* Container max-width and padding (safe-area для выреза экрана) */
.responsive-container {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: max(1rem, var(--safe-area-inset-left));
  padding-right: max(1rem, var(--safe-area-inset-right));
  box-sizing: border-box;
}
@media (max-width: 599px) {
  .responsive-container {
    padding-left: max(0.75rem, var(--safe-area-inset-left));
    padding-right: max(0.75rem, var(--safe-area-inset-right));
  }
}

/* Блок «Связь по ID»: кнопки не вылезают за экран на Android, минимум 44×44px */
#videoCallTargetId,
#videoCallVoice,
#videoCallStart,
#contactByIdMessage,
#videoCallHangup {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  box-sizing: border-box;
}
@media (max-width: 400px) {
  .app-panel .flex-wrap.gap-2.items-center {
    gap: 0.5rem;
  }
  #videoCallTargetId {
    width: 100%;
    min-width: 0;
  }
}

/* Дашборд: брейкпоинт 768px (совпадает с Adaptive UI Kernel device) */
@media (max-width: 768px) {
  .app-root,
  .app-body,
  .app-panels,
  .app-panel {
    min-width: 0;
    width: 100%;
    max-width: 100vw;
  }
  .responsive-main-grid,
  .responsive-hero-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  .responsive-container {
    padding-left: max(0.75rem, var(--safe-area-inset-left));
    padding-right: max(0.75rem, var(--safe-area-inset-right));
  }
}
@media (min-width: 600px) {
  .responsive-container {
    max-width: 1024px;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
@media (min-width: 1024px) {
  .responsive-container {
    max-width: 1152px;
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

/* Hide on mobile, show from tablet */
.show-from-tablet {
  display: none !important;
}
@media (min-width: 600px) {
  .show-from-tablet {
    display: flex !important;
  }
}
@media (min-width: 600px) {
  .hide-from-tablet {
    display: none !important;
  }
}

/* Tables: horizontal scroll on small screens */
.table-responsive-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive-wrap table {
  min-width: 480px;
}

/* Modals: full width on mobile */
@media (max-width: 599px) {
  .modal-overlay .modal-content,
  .fixed.inset-0 .rounded-2xl {
    max-width: calc(100vw - 2rem);
    margin: 1rem;
  }
}

/* Список задач: фиксированная высота, окно не меняется */
.task-list-fixed {
  min-height: 120px;
  max-height: 280px;
  -webkit-overflow-scrolling: touch;
}
.task-list-fixed li {
  flex-shrink: 0;
}

/* Системный баннер: в потоке документа, не перекрывает контент */
.system-banner {
  width: 100%;
  background-color: #f8f9fa;
  padding: 10px;
  border-bottom: 1px solid #dee2e6;
  text-align: center;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #212529;
}
.system-banner.hidden {
  display: none !important;
}

/* ========== Глобальный голосовой командный центр (FAB + Toast) ========== */
.voice-fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height, 56px) + var(--safe-area-inset-bottom, 0px) + 16px);
  right: 16px;
  z-index: 45;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(37, 99, 235, 0.6);
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
}
.voice-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}
.voice-fab:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.5);
}
.voice-fab--listening {
  background: linear-gradient(135deg, #b91c1c 0%, #dc2626 100%);
  border-color: rgba(220, 38, 38, 0.8);
  animation: voice-pulse 1s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4); }
  50% { box-shadow: 0 4px 24px rgba(220, 38, 38, 0.7); }
}
.voice-fab-icon {
  font-size: 1.5rem;
  line-height: 1;
}
@media (min-width: 600px) {
  .voice-fab {
    bottom: 24px;
  }
}

.voice-toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-height, 56px) + var(--safe-area-inset-bottom, 0px) + 80px);
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  z-index: 60;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.voice-toast--show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.voice-toast--success {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%);
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
}
.voice-toast--error {
  background: linear-gradient(135deg, #991b1b 0%, #b91c1c 100%);
  box-shadow: 0 4px 14px rgba(185, 28, 28, 0.4);
}
@media (min-width: 600px) {
  .voice-toast {
    bottom: 100px;
  }
}

/* Утилита: явный минимум для зоны нажатия */
.touch-target-min {
  min-height: var(--touch-min);
  min-width: var(--touch-min);
}

/* Экраны от 320px: базовая читаемость и отступы */
@media (min-width: 320px) {
  .responsive-container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Секция медиа и геолокации: адаптивная сетка */
.device-features-section .grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .device-features-section .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
