/* ========================================
   🎨 GLOBAL VARIABLES & THEME
   ======================================== */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec-bg: var(--tg-theme-secondary-bg-color, #f0f2f5);
  --border: rgba(0,0,0,0.08);
  --success: #34c759;
  --warning: #ff9500;
  --focus-ring: 0 0 0 3px rgba(51,144,236,0.4);
}

/* 🔹 Тёмная тема */
@media (prefers-color-scheme: dark) {
  :root {
    --sec-bg: #2a2a2a;
    --border: rgba(255,255,255,0.12);
  }
}

/* ========================================
   ♿ ACCESSIBILITY & MOTION
   ======================================== */
/* Focus-visible для клавиатурной навигации */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 8px;
}

/* Reduced motion для пользователей с предпочтением */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Скрытые элементы для скринридеров */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========================================
   🌐 BASE RESET & LAYOUT
   ======================================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 240px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Skip link для доступности */
#skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--btn);
  color: var(--btn-text);
  padding: 8px 16px;
  z-index: 100;
  transition: top 0.2s;
  text-decoration: none;
  font-weight: 600;
}
#skip-link:focus {
  top: 0;
}

/* ========================================
   📐 GRID LAYOUT
   ======================================== */
.app-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

/* 🔹 Десктоп: 3 колонки */
@media (min-width: 1200px) {
  .app-grid {
    grid-template-columns: 260px minmax(600px, 1fr) 260px;
    gap: 28px;
    padding: 28px;
  }
  body {
    padding-bottom: 24px;
  }
  .footer {
    position: sticky;
    bottom: 28px;
    margin-top: 20px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  }
}

/* ========================================
   📦 PANELS (BASE + SCROLLABLE)
   ======================================== */
.panel {
  background: var(--sec-bg);
  border-radius: 16px;
  padding: 16px;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* 🔹 SCROLLABLE PANELS — РАБОТАЮТ НА ВСЕХ УСТРОЙСТВАХ */
.panel-left,
.panel-right {
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding: 16px;
  max-height: 40vh; /* Мобильные: не больше 40% высоты */
}

/* 🔹 Десктоп: sticky + полная высота */
@media (min-width: 1200px) {
  .panel-left,
  .panel-right {
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 80px);
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
  }
}

/* 🔹 Кастомный скроллбар */
.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar {
  width: 6px;
}
.panel-left::-webkit-scrollbar-track,
.panel-right::-webkit-scrollbar-track {
  background: transparent;
}
.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  transition: background 0.2s ease;
}
.panel-left::-webkit-scrollbar-thumb:hover,
.panel-right::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
}

/* 🔹 Тёмная тема: скроллбар */
@media (prefers-color-scheme: dark) {
  .panel-left::-webkit-scrollbar-thumb,
  .panel-right::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
  }
  .panel-left::-webkit-scrollbar-thumb:hover,
  .panel-right::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
  }
}

/* 🔹 Индикатор прокрутки (градиент внизу) */
.panel-left::after,
.panel-right::after {
  content: "";
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 24px;
  background: linear-gradient(to bottom, transparent, var(--sec-bg));
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 1;
}
.panel-left.scrolling::after,
.panel-right.scrolling::after,
.panel-left:hover::after,
.panel-right:hover::after {
  opacity: 1;
}

/* ========================================
   📋 INFO LIST (левая панель)
   ======================================== */
.info-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.info-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.5;
  transition: opacity 0.2s ease, transform 0.2s ease;
  will-change: transform, opacity;
}
.info-item:last-child {
  border-bottom: none;
}
.info-item.base::before {
  content: "✓ ";
  color: var(--success);
  font-weight: bold;
  margin-right: 6px;
}
.info-item.cleaning::before {
  content: "⚙️ ";
  color: var(--warning);
  font-weight: bold;
  margin-right: 6px;
}
.info-empty {
  color: var(--hint);
  font-style: italic;
  font-size: 13px;
}

/* ========================================
   ✨ SELECTED EXTRAS (правая панель)
   ======================================== */
.extra-card {
  background: rgba(51,144,236,0.06);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid rgba(51,144,236,0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.extra-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(51,144,236,0.1);
}
.extra-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
}
.extra-cost {
  font-weight: 700;
  color: var(--btn);
}
.extra-process {
  font-size: 12px;
  color: var(--hint);
  line-height: 1.4;
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

/* ========================================
   🧮 CALCULATOR (центр)
   ======================================== */
.calculator {
  background: var(--sec-bg);
  border-radius: 16px;
  padding: clamp(12px, 3vw, 20px);
}

h2 {
  margin: 0 0 16px;
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 700;
}

.section {
  margin-bottom: 16px;
}

.label {
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: block;
  font-weight: 600;
}

/* ========================================
   🔘 BUTTON GROUPS
   ======================================== */
.btn-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.opt-btn {
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  opacity: 0.65;
}
.opt-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}
.opt-btn:active {
  transform: translateY(0);
}
.opt-btn.active {
  border-color: var(--btn);
  background: rgba(51,144,236,0.1);
  color: var(--btn);
  opacity: 1;
  box-shadow: 0 2px 8px rgba(51,144,236,0.15);
}
.opt-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ========================================
   🔢 NUMBER INPUTS
   ======================================== */
.num-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: clamp(16px, 3.5vw, 18px);
  font-weight: 600;
  text-align: center;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.num-input:focus {
  outline: none;
  border-color: var(--btn);
  box-shadow: var(--focus-ring);
}
.num-input.small {
  width: 70px;
  padding: 8px;
  font-size: 15px;
  text-align: right;
}

/* ========================================
   🎛️ EXTRA SERVICES LIST
   ======================================== */
.extra-row {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s ease;
}
.extra-row:last-child {
  border-bottom: none;
}
.extra-row:hover {
  background: rgba(0,0,0,0.02);
  border-radius: 8px;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggle-track {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 26px;
  transition: background 0.3s ease;
}
.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .toggle-track {
  background: var(--btn);
}
input:checked + .toggle-track .toggle-knob {
  transform: translateX(22px);
}
.toggle:focus-within .toggle-track {
  box-shadow: var(--focus-ring);
}

/* Extra info text */
.extra-info {
  margin-left: 14px;
  flex: 1;
  min-width: 0; /* Для обрезки длинного текста */
}
.extra-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}
.extra-price {
  font-size: 12px;
  color: var(--hint);
}

/* Expandable detail section */
.extra-detail {
  margin-top: 10px;
  display: none;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  animation: slideDown 0.2s ease;
}
.extra-detail.visible {
  display: block;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .extra-detail { animation: none !important; }
}

.detail-input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}
.detail-input-row span,
.detail-input-row label {
  font-size: 14px;
}

/* ========================================
   🪑 FURNITURE & ROTOR PANELS
   ======================================== */
.furniture-panel,
.rotor-panel {
  background: rgba(0,0,0,0.03);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}

.rotor-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  gap: 8px;
}
.rotor-item:last-child {
  border-bottom: none;
}
.rotor-item label {
  font-size: 14px;
  flex: 1;
}
.rotor-item span:last-child {
  color: var(--hint);
  font-size: 13px;
}

/* ========================================
   📊 CALCULATION BREAKDOWN
   ======================================== */
.calc-breakdown {
  margin-top: 10px;
  padding: 12px;
  background: rgba(51,144,236,0.05);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid rgba(51,144,236,0.2);
}
.calc-line {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
}
.calc-line.highlight {
  color: var(--btn);
  font-weight: 700;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(0,0,0,0.1);
}
.calc-line span:last-child {
  font-weight: 600;
  text-align: right;
  min-width: 80px;
}

/* Status text */
.status-text {
  text-align: center;
  margin-top: 8px;
  font-size: 13px;
  color: var(--hint);
  font-weight: 600;
  transition: color 0.2s ease;
}
.status-text.active {
  color: var(--btn);
}

/* ========================================
   🦶 FOOTER (FIXED BOTTOM)
   ======================================== */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  padding: 12px 16px env(safe-area-inset-bottom, 12px);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
  z-index: 10;
  transition: transform 0.3s ease;
}
.footer.hidden {
  transform: translateY(100%);
}

.total-label {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 2px;
  text-align: center;
}
.total-value {
  font-size: clamp(24px, 5vw, 28px);
  font-weight: 800;
  color: var(--btn);
  margin: 2px 0 10px;
  text-align: center;
  transition: color 0.2s ease;
}

/* Site link in footer */
.footer-site-link {
  margin-bottom: 12px;
  text-align: center;
}
.site-logo-link {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, opacity 0.2s ease;
  cursor: pointer;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
}
.site-logo {
  height: 36px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
  margin-bottom: 4px;
  transition: transform 0.2s ease;
}
.site-logo-link:hover .site-logo {
  transform: scale(1.05);
}
.site-caption {
  font-size: 14px;
  font-weight: 600;
  color: var(--btn);
  text-decoration: none;
  transition: color 0.2s ease;
}
.site-logo-link:hover .site-caption {
  text-decoration: underline;
  opacity: 0.8;
}
.site-logo-link:active {
  transform: scale(0.98);
}

/* Footer buttons */
.footer-btns {
  display: flex;
  gap: 10px;
}
.submit-btn {
  flex: 2;
  padding: 14px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.submit-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(51,144,236,0.3);
}
.submit-btn:active {
  transform: scale(0.98);
  opacity: 0.85;
}
.submit-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

.reset-btn {
  flex: 1;
  padding: 14px;
  background: transparent;
  color: var(--btn);
  border: 2px solid var(--btn);
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.reset-btn:hover {
  background: rgba(51,144,236,0.08);
  transform: translateY(-1px);
}
.reset-btn:active {
  transform: scale(0.98);
  opacity: 0.85;
}
.reset-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ========================================
   📱 RESPONSIVE ADJUSTMENTS
   ======================================== */
@media (max-width: 380px) {
  .footer-btns {
    flex-direction: column;
  }
  .submit-btn,
  .reset-btn {
    flex: none;
    width: 100%;
  }
  .btn-group {
    grid-template-columns: 1fr;
  }
}

/* 🔹 Отступ 5 см между калькулятором и футером на мобильных */
@media (max-width: 1199px) {
  .calculator {
    padding-bottom: 200px;
  }
  body {
    padding-bottom: 220px;
  }
}
@media (min-width: 1200px) {
  .calculator {
    padding-bottom: 160px;
  }
}

/* ========================================
   🎨 PRINT STYLES (опционально)
   ======================================== */
@media print {
  .footer,
  .panel-left,
  .panel-right {
    display: none;
  }
  .calculator {
    padding: 0;
    background: transparent;
  }
  body {
    padding: 0;
    background: #fff;
    color: #000;
  }
  .opt-btn,
  .toggle,
  .num-input {
    border: 1px solid #000;
  }
}
