/* HydroLoop — адаптивные стили и сенсорное управление (смартфоны, планшеты, сенсорные экраны) */

/* Сенсорные элементы управления масштабом (Pinch-to-zoom toolbar) */
.chart-zoom-controls {
  position: absolute;
  top: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(8, 24, 36, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  padding: 3px 6px;
  z-index: 15;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.zoom-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line-soft);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.1s ease;
}

.zoom-btn:active {
  transform: scale(0.92);
  background: var(--blue);
  color: #fff;
}

.zoom-level-badge {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--cyan);
  padding: 0 4px;
  min-width: 38px;
  text-align: center;
  user-select: none;
}

.chart, .well-schematic {
  position: relative;
  overflow: hidden;
  touch-action: pan-y;
}

.chart.zoomed, .well-schematic.zoomed {
  touch-action: none;
  cursor: grab;
}

.chart.zoomed:active, .well-schematic.zoomed:active {
  cursor: grabbing;
}

/* Мобильная нижняя навигация (Mobile Tab Bar) */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(4, 12, 18, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 100;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.2s ease, background 0.2s ease;
}

.mobile-nav-item .nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.mobile-nav-item.active {
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.08);
}

.mobile-nav-item.active .nav-icon {
  transform: scale(1.1);
}

/* Плавающая кнопка быстрого расчёта (FAB) на смартфонах */
.mobile-fab {
  display: none;
  position: fixed;
  bottom: 74px;
  right: 18px;
  height: 48px;
  padding: 0 18px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #03131e;
  border: 0;
  font-weight: 700;
  font-size: 0.86rem;
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.45);
  z-index: 99;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  touch-action: manipulation;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.mobile-fab:active {
  transform: scale(0.94);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.6);
}

/* Оптимизация сенсорных контролов для экранов с тачем */
@media (hover: none) and (pointer: coarse) {
  .preset, .ghost-button, .icon-button, .small-button {
    min-height: 44px;
    touch-action: manipulation;
  }
  .field input {
    min-height: 44px;
    font-size: 16px !important; /* Предотвращает нежелательный зум в iOS Safari */
  }
  input[type=range] {
    height: 36px;
  }
  input[type=range]::-webkit-slider-thumb {
    width: 28px;
    height: 28px;
  }
  input[type=range]::-moz-range-thumb {
    width: 28px;
    height: 28px;
  }
  .remove-section {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }
}

/* Адаптивные медиа-запросы */
@media (max-width: 1180px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .analysis-grid { grid-template-columns: 1fr; }
  .well-schematic { min-height: 260px; }
  .well-schematic svg { height: 260px; }
}

@media (max-width: 820px) {
  .topbar { height: 62px; padding: 0 14px; }
  .local-badge { display: none; }
  .mobile-nav { display: grid; }
  .mobile-fab { display: flex; }
  .workspace { display: block; padding-bottom: 70px; }
  
  /* Мобильное переключение панелей по вкладкам */
  body.view-inputs .controls-panel { display: block; }
  body.view-inputs .results-panel { display: none; }
  
  body.view-charts .controls-panel { display: none; }
  body.view-charts .results-panel { display: block; }
  body.view-charts .well-panel, 
  body.view-charts .pressure-stack-panel, 
  body.view-charts .table-panel { display: none; }
  
  body.view-schematic .controls-panel { display: none; }
  body.view-schematic .results-panel { display: block; }
  body.view-schematic .chart-panel, 
  body.view-schematic .table-panel { display: none; }
  
  body.view-table .controls-panel { display: none; }
  body.view-table .results-panel { display: block; }
  body.view-table .metrics-grid,
  body.view-table .analysis-grid, 
  body.view-table .pressure-stack-panel { display: none; }

  .controls-panel { padding: 18px 14px 28px; border-right: 0; border-bottom: 0; max-height: none; overflow-y: visible; }
  .results-panel { padding: 16px 12px 40px; }
  .calculate-dock { position: static; }
  .alert-rail { min-height: 0; }
  .chart { min-height: 310px; }
  .pressure-breakdown { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
  .brand small { display: none; }
  .brand strong { font-size: 0.95rem; }
  .top-actions { gap: 6px; }
  .ghost-button { padding: 0 10px; font-size: 0.74rem; }
  .preset-row { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .fields-grid { grid-template-columns: 1fr 1fr; }
  .geometry-mini-grid { grid-template-columns: repeat(2, 1fr); }
  .metrics-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 104px; padding: 12px; }
  .panel { padding: 14px; }
  .panel-heading { align-items: flex-start; gap: 8px; }
  .segmented-control { flex: 0 0 auto; }
  .table-scroll { margin-left: -14px; margin-right: -14px; }
  .method-grid { grid-template-columns: 1fr; }
  .chart-zoom-controls { top: 6px; right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* Логотип Вибрации и брендинг */
.brand-logo { width: 32px; height: 32px; object-fit: contain; filter: drop-shadow(0 2px 8px rgba(99, 102, 241, 0.4)); flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }

/* Авторизация и профиль в шапке */
.user-auth-nav { position: relative; display: flex; align-items: center; }
.login-nav-btn { display: inline-flex; align-items: center; gap: 6px; background: rgba(99, 102, 241, 0.12); border-color: rgba(99, 102, 241, 0.4); color: #c7d2fe; }
.login-nav-btn:hover { background: rgba(99, 102, 241, 0.22); border-color: rgba(99, 102, 241, 0.7); color: #fff; }
.user-profile-pill { position: relative; display: flex; align-items: center; }
.user-pill-btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(99, 102, 241, 0.35); background: rgba(19, 27, 43, 0.85); color: #e2e8f0; font-size: 0.82rem; font-weight: 500; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease; }
.user-pill-btn:hover { background: rgba(99, 102, 241, 0.18); border-color: rgba(99, 102, 241, 0.6); }
.user-pill-avatar { font-size: 0.9rem; }
.user-pill-caret { font-size: 0.7rem; opacity: 0.7; }
.user-dropdown-menu { position: absolute; top: calc(100% + 8px); right: 0; width: 220px; background: #101625; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 12px; padding: 8px; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); display: none; flex-direction: column; gap: 4px; z-index: 1000; }
.user-dropdown-menu.show { display: flex; }
.user-dropdown-header { padding: 8px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.dropdown-role-badge { display: inline-block; font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: #818cf8; background: rgba(99, 102, 241, 0.15); padding: 2px 6px; border-radius: 4px; width: fit-content; }
.dropdown-email { font-size: 0.76rem; color: #94a3b8; word-break: break-all; }
.dropdown-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; font-size: 0.82rem; color: #cbd5e1; background: transparent; border: none; border-radius: 6px; text-decoration: none; cursor: pointer; text-align: left; transition: background 0.12s ease, color 0.12s ease; }
.dropdown-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.logout-item:hover { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* Диалог авторизации */
.login-dialog { max-width: 440px; width: 90vw; background: #0d121f; border: 1px solid rgba(99, 102, 241, 0.3); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7); color: #f8fafc; padding: 0; overflow: hidden; }
.login-heading-brand { display: flex; align-items: center; gap: 12px; }
.login-heading-brand img { filter: drop-shadow(0 2px 6px rgba(99, 102, 241, 0.5)); }
.login-dialog-body { padding: 20px 24px 26px; }
.login-prompt-msg { background: rgba(99, 102, 241, 0.12); border-left: 3px solid #6366f1; padding: 10px 14px; border-radius: 6px; font-size: 0.82rem; color: #c7d2fe; margin-bottom: 16px; line-height: 1.4; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-submit-btn { margin-top: 6px; width: 100%; }
.login-error { background: rgba(239, 68, 68, 0.15); border: 1px solid rgba(239, 68, 68, 0.4); color: #fca5a5; padding: 10px 14px; border-radius: 8px; font-size: 0.82rem; line-height: 1.4; }
.login-not-found-block { background: rgba(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.4); color: #fef3c7; padding: 12px 14px; border-radius: 8px; font-size: 0.82rem; line-height: 1.45; }
.login-not-found-block strong { color: #fde68a; }
.login-not-found-block .redirect-hint { color: #fcd34d; font-size: 0.76rem; margin: 6px 0 10px; }
.register-direct-btn { display: inline-block; background: #f59e0b; color: #0f172a; font-weight: 600; font-size: 0.8rem; padding: 6px 14px; border-radius: 6px; text-decoration: none; transition: background 0.15s ease; }
.register-direct-btn:hover { background: #fbbf24; }
.login-footer-links { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.08); font-size: 0.78rem; }
.login-footer-links a { color: #818cf8; text-decoration: none; transition: color 0.15s ease; }
.login-footer-links a:hover { color: #a5b4fc; text-decoration: underline; }

