/* okno.css — iOS Liquid Glass Modal (fixed & mobile-improved) */
:root {
  --ios-tint-new:     #5AC8FA;
  --ios-tint-old:     #A284FF;
  --ios-bg-dark:      rgba(0, 0, 0, 0.35);
  --ios-bg-content:   rgba(20, 20, 28, 0.92);
  --ios-border:       rgba(255, 255, 255, 0.1);
  --ios-text-light:   rgba(235, 235, 245, 0.98);
  --ios-text-muted:   rgba(235, 235, 245, 0.60);
  --ios-shadow-low:   0 4px 12px rgba(0, 0, 0, 0.24);
  --ios-shadow-high:  0 12px 40px rgba(0, 0, 0, 0.45);
}

/* =================== OVERLAY =================== */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: var(--ios-bg-dark);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  animation: fadeIn 0.3s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  /* Центрирование содержимого */
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(12px, 4vw, 40px) 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal.active,
.modal[style*="display: block"],
.modal[style*="display:block"] {
  display: flex;
}

/* =================== MODAL CONTENT =================== */
.modal-content {
  position: relative;              /* ИСПРАВЛЕНО: нужно для absolute-позиц. .close-btn */
  background: var(--ios-bg-content);
  margin: auto;
  padding: clamp(18px, 4vw, 28px);
  border-radius: 20px;
  width: min(90vw, 440px);
  max-width: 100%;
  box-shadow:
    var(--ios-shadow-high),
    inset 0 0 0 1px var(--ios-border);
  border: 1px solid var(--ios-border);
  backdrop-filter: blur(40px);
  -webkit-backdrop-filter: blur(40px);
  animation: slideIn 0.32s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  contain: layout style paint;
}

.modal-content h3 {
  font-family: 'Syne', -apple-system, sans-serif;
  font-size: clamp(15px, 3vw, 18px);
  font-weight: 700;
  color: var(--ios-text-light);
  margin: 0 0 4px;
  padding-right: 44px; /* чтобы заголовок не уходил под кнопку закрытия */
  letter-spacing: -0.02em;
}

/* =================== CLOSE BUTTON =================== */
.close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.22);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  padding: 0;
  z-index: 10;
  transition: background var(--transition, 0.2s ease);
  /* Touch target увеличен padding-ом без смены размера визуально */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.close-btn:hover  { background: rgba(120, 120, 128, 0.36); }
.close-btn:active { background: rgba(255, 107, 107, 0.25); }

.close-btn::before,
.close-btn::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 1.8px;
  background-color: var(--ios-text-light);
  border-radius: 1px;
  transition: background 0.2s ease;
}

.close-btn::before { transform: rotate(45deg); }
.close-btn::after  { transform: rotate(-45deg); }

/* =================== APK LIST =================== */
.apk-list {
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 6px;
  margin: 14px 0 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 120, 128, 0.4) transparent;
  -webkit-overflow-scrolling: touch;
}

.apk-list::-webkit-scrollbar       { width: 5px; }
.apk-list::-webkit-scrollbar-thumb { background: rgba(120, 120, 128, 0.4); border-radius: 3px; }

/* =================== APK ITEM =================== */
.apk-item {
  padding: clamp(12px, 2.5vw, 18px) clamp(14px, 3vw, 20px);
  margin: 8px 0;
  border-radius: 14px;
  background: rgba(120, 120, 128, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
  transition: transform 0.2s ease, background 0.2s ease;
}

.apk-item:hover {
  transform: translateY(-1px);
  background: rgba(120, 120, 128, 0.11);
}

.apk-item:active {
  transform: scale(0.98);
}

.apk-item.new-version {
  border-left: 3px solid var(--ios-tint-new);
  background: rgba(90, 200, 250, 0.07);
}

.apk-item.old-version {
  border-left: 3px solid var(--ios-tint-old);
  background: rgba(162, 132, 255, 0.07);
}

/* =================== APK NAME =================== */
.apk-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.apk-name a {
  font-weight: 500;
  letter-spacing: -0.1px;
  flex-grow: 1;
  font-size: clamp(14px, 2.5vw, 15.5px);
  line-height: 1.4;
  text-decoration: none;
  color: var(--ios-text-light);
  transition: opacity 0.2s ease;
  word-break: break-word;
}

.apk-name a:hover   { opacity: 0.82; }
.apk-name a:active  { opacity: 0.65; }

.apk-item.new-version .apk-name a { color: var(--ios-tint-new); font-weight: 600; }
.apk-item.old-version .apk-name a { color: var(--ios-tint-old); font-weight: 600; }

/* =================== LATEST BADGE =================== */
.latest-badge {
  background: linear-gradient(135deg, var(--ios-tint-new), #6EDCFF);
  color: #1C1C1E;
  padding: 3px 11px;
  border-radius: 12px;
  font-size: clamp(11px, 1.8vw, 12.5px);
  font-weight: 700;
  letter-spacing: 0.2px;
  box-shadow: 0 2px 6px rgba(90, 200, 250, 0.25);
  flex-shrink: 0;
  white-space: nowrap;
}

/* =================== APK DETAILS =================== */
.apk-details {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 10px;
  font-size: clamp(12px, 1.8vw, 13px);
  color: var(--ios-text-muted);
  line-height: 1.4;
}

/* =================== VERSION GROUP =================== */
.version-group {
  margin-bottom: 20px;
}

.version-group-title {
  font-size: clamp(14px, 2.5vw, 16.5px);
  font-weight: 700;
  margin: 20px 0 12px;
  color: var(--ios-text-light);
  letter-spacing: -0.1px;
  display: flex;
  align-items: center;
  line-height: 1.2;
}

.version-group-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, currentColor, transparent);
  margin-left: 12px;
  opacity: 0.18;
}

/* =================== PROGRESS BAR =================== */
.progress-container {
  height: 4px;
  background: rgba(120, 120, 128, 0.18);
  border-radius: 2px;
  margin: 20px 0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--ios-tint-new), #7AD4FF);
  width: 0%;
  border-radius: 2px;
  transition: width 0.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.progress-text {
  text-align: center;
  margin-top: 8px;
  font-size: clamp(12px, 1.8vw, 13.5px);
  color: var(--ios-text-muted);
  font-weight: 500;
}

/* =================== STATES =================== */
.error-message {
  color: #FF6B6B;
  text-align: center;
  font-size: clamp(14px, 2.5vw, 15.5px);
  margin: 24px 0 8px;
  font-weight: 600;
  line-height: 1.4;
}

.error-details {
  color: rgba(255, 107, 107, 0.8);
  text-align: center;
  font-size: clamp(12px, 1.8vw, 13px);
  margin-top: 4px;
  line-height: 1.45;
}

.no-files {
  color: var(--ios-text-muted);
  text-align: center;
  padding: 24px;
  font-size: clamp(13px, 2vw, 14.5px);
  line-height: 1.5;
}

/* =================== DOWNLOAD STATE =================== */
.apk-download-link.loading {
  opacity: 0.65;
  pointer-events: none;
}

.download-count {
  background: rgba(120, 120, 128, 0.18);
  padding: 3px 9px;
  border-radius: 10px;
  font-size: clamp(11px, 1.8vw, 12.5px);
  font-weight: 500;
  margin-left: 10px;
  color: var(--ios-text-muted);
  white-space: nowrap;
}

/* =================== АНИМАЦИИ =================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* =================== RESPONSIVE =================== */

/* Мобильные */
@media (max-width: 480px) {
  .modal {
    padding: 10px 8px;
    align-items: flex-start;
  }

  .modal-content {
    width: min(96vw, 440px);
    border-radius: 18px;
    padding: 18px 16px;
    /* На мобильных показываем ближе к верху */
    margin-top: 5vh;
  }

  .apk-item {
    padding: 12px 14px;
    margin: 6px 0;
  }

  .apk-details {
    flex-direction: column;
    gap: 3px;
  }

  .version-group-title { margin: 16px 0 10px; }
}

/* Магнитолы — маленькая высота */
@media (max-height: 600px) and (max-width: 800px) {
  .modal-content {
    margin: 4vh auto;
    padding: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .apk-list { max-height: 40vh; }

  .latest-badge { font-size: 11px; padding: 2px 9px; }
}