/* backend/modules/public/static/widget.css */
:root {
  --accent: #007aff;
  --header-bg: #0aaeeb;
  --header-text: #ffffff;
  --cell-bg-1: #ffffff;
  --cell-bg-2: #f2f7ff;
  --item-bg: #f8f9fa;
  --text-primary: #333;
  --text-secondary: #757474;
  --text-tertiary: #999;
  --divider: #e0e0e0;
  --danger: #ff1a1a;
  --success: #1cb841;
  --warning: #f0ad4e;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: #fff;
  min-height: 100vh;
}

/* V2-F98: Утилитарный класс */
.hidden {
  display: none !important;
}

/* ═══════════════ РЕЖИМЫ КОНТЕЙНЕРА ═══════════════ */
#widget-container.layout-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

#widget-container.layout-window {
  max-width: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

#widget-container.layout-auto {
  max-width: 100%;
  margin: 0 auto;
  padding: 0 12px;
}

@media (min-width: 1200px) {
  #widget-container.layout-auto {
    max-width: 1200px;
  }
}

/* ═══════════════ ШАПКА ═══════════════ */
#widget-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 20px 15px;
  text-align: center;
}

.layout-grid #widget-header {
  border-radius: 8px 8px 0 0;
}

.layout-window #widget-header {
  border-radius: 0;
}

#widget-container.square-corners :is(#widget-header, .lesson-card, .empty-slot, .mobile-day, .booking-cta) {
  border-radius: 0;
}

#widget-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
}

#widget-week-label {
  font-size: 15px;
  opacity: 0.9;
}

#widget-lessons-count {
  font-size: 13px;
  opacity: 0.75;
  margin-top: 4px;
}

/* ═══════════════ НАВИГАЦИЯ ═══════════════ */
#widget-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 10px;
  gap: 12px;
}

.btn-nav {
  padding: 8px 20px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: all 0.2s;
  min-width: 100px;
}

.btn-nav:hover {
  background: #f5f5f5;
}

/* ═══════════════ ФИЛЬТРЫ ═══════════════ */
#widget-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  max-width: 900px;
  margin: 0 auto;
}

.filter-group {
  flex: 1;
  min-width: 140px;
}

.filter-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

.filter-select:focus {
  border-color: var(--accent);
}

/* ═══════════════ SCHEDULE DESKTOP — GRID (V2-F98) ═══════════════ */
#schedule-desktop {
  margin-top: 10px;
  padding: 0 10px;
  overflow-x: auto;
}

.schedule-grid {
  display: grid;
  grid-template-columns: 56px repeat(7, minmax(140px, 1fr));
  min-width: 900px;
}

/* Шапка — sticky */
.schedule-grid--head {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
}

.schedule-grid--head .schedule-cell {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 5px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.schedule-grid--head .schedule-cell--time {
  background: var(--header-bg);
}

.schedule-grid--head .day-date {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
}

/* V2-F98: Тело — строки */
.schedule-row--wrapper {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 56px repeat(7, minmax(140px, 1fr));
  max-height: 500px;
  overflow: hidden;
  transition:
    max-height 0.35s ease,
    opacity 0.35s ease;
}

/* V2-F98: Компакт — пустые строки сворачиваются */
#schedule-desktop.compact .schedule-row--wrapper.empty-row {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Ячейки */
#schedule-desktop.compact .schedule-row--boundary .schedule-cell,
#schedule-desktop .schedule-row--boundary .schedule-cell {
  min-height: 0;
  padding-top: 6px;
  padding-bottom: 6px;
}

.schedule-cell {
  border: 1px solid var(--divider);
  padding: 4px;
  vertical-align: top;
  min-height: 60px;
  background: var(--cell-bg-1);
  transition: min-height 0.3s ease;
}

.schedule-cell--time {
  background: var(--header-bg);
  color: var(--header-text);
  text-align: center;
  font-weight: 600;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* V2-F98: Плотность в компакте */
#schedule-desktop.compact .schedule-cell {
  min-height: 48px;
}

/* Чередование фона */
.schedule-row--wrapper .schedule-cell:nth-child(even) {
  background: var(--cell-bg-2);
}

/* V2-F98: Полоски по типу занятия */
.lesson-card.group {
  border-left-color: var(--accent);
}

.lesson-card.individual {
  border-left-color: #9c27b0;
}

.lesson-card.rent {
  border-left-color: #ff9800;
}

/* ═══════════════ ПУСТОЙ СЛОТ (V2-F98) ═══════════════ */
.empty-slot {
  min-height: 50px;
  cursor: pointer;
  border-radius: 6px;
  transition:
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

.empty-slot.rentable {
  border: 1px dashed var(--divider);
  background: rgba(0, 122, 255, 0.02);
  cursor: pointer;
}

.empty-slot.rentable:hover {
  background: rgba(0, 122, 255, 0.08);
  border-color: var(--accent);
  color: var(--accent);
}

.empty-slot.rentable .slot-label {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.empty-slot.rentable:hover .slot-label {
  opacity: 1;
}

.empty-slot.occupied {
  cursor: not-allowed;
  opacity: 0.3;
}

/* V2-F98: mobile CTA */
.booking-cta {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

.booking-cta:hover {
  background: rgba(0, 122, 255, 0.06);
}

.booking-cta.booking-cta--individual {
  border-color: #9c27b0;
  color: #9c27b0;
}

.booking-cta.booking-cta--individual:hover {
  background: rgba(156, 39, 176, 0.06);
}

/* Старая .rent-cta — legacy */
.rent-cta {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
}

.rent-cta:hover {
  background: rgba(0, 122, 255, 0.06);
}

/* ═══════════════ КАРТОЧКА ЗАНЯТИЯ ═══════════════ */
.lesson-card {
  background: var(--item-bg);
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid var(--accent);
  margin-bottom: 4px;
}

.lesson-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.lesson-card.bookable-open {
  border: 2px solid #4caf50;
  animation: pulse-open 2s infinite;
}

@keyframes pulse-open {
  0%,
  100% {
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.4);
  }
  50% {
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.8);
  }
}

.lesson-card.bookable-active {
  border: 2px solid #2196f3;
  animation: pulse-active 3s infinite;
}

@keyframes pulse-active {
  0%,
  100% {
    box-shadow: 0 0 3px rgba(33, 150, 243, 0.3);
  }
  50% {
    box-shadow: 0 0 12px rgba(33, 150, 243, 0.6);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lesson-card.bookable-open,
  .lesson-card.bookable-active {
    animation: none;
  }
}

.lesson-card .lesson-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-card .lesson-info {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ═══════════════ СТИКЕРЫ ═══════════════ */
.lesson-stickers {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.sticker {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.sticker-enrollment {
  background: #4caf50;
  color: #fff;
}

.sticker-active {
  background: #2196f3;
  color: #fff;
}

.sticker-private {
  background: #9e9e9e;
  color: #fff;
}

.sticker-closed {
  background: #f44336;
  color: #fff;
}

.sticker-full {
  background: #f44336;
  color: #fff;
}

.sticker-waitlist {
  background: #ff9800;
  color: #fff;
}

.sticker-individual {
  background: #9c27b0;
  color: #fff;
}

.sticker-rent {
  background: #ff9800;
  color: #fff;
}

.sticker-pending {
  background: #ff9800;
  color: #fff;
  animation: pulse-pending 2s infinite;
}

@keyframes pulse-pending {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* ═══════════════ СВОБОДНЫЕ МЕСТА ═══════════════ */
.lesson-places {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ═══════════════ МОБИЛЬНАЯ ВЕРСИЯ ═══════════════ */
#schedule-mobile {
  display: none;
  margin-top: 10px;
  padding: 0 10px;
}

.mobile-day {
  margin-bottom: 10px;
}

.mobile-day-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mobile-day-header .lesson-count {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 11px;
}

.mobile-day-header .chevron {
  transition: transform 0.3s;
}

.mobile-day-header.open .chevron {
  transform: rotate(180deg);
}

.mobile-day-items {
  display: none;
  padding: 5px 0;
}

.mobile-day-items.open {
  display: block;
}

/* ═══════════════ МОДАЛКИ ═══════════════ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-small {
  max-width: 320px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--divider);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 0;
}

.btn-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  gap: 8px;
  padding: 15px 20px;
  border-top: 1px solid var(--divider);
}

/* ═══════════════ QUIZ-МОДАЛКА (V2-F98) ═══════════════ */
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.quiz-option:hover:not(.quiz-option--disabled) {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.1);
  transform: translateY(-1px);
}

.quiz-option--disabled {
  cursor: not-allowed;
  opacity: 0.6;
  background: #fafafa;
}

.quiz-option__icon {
  font-size: 28px;
  flex-shrink: 0;
  line-height: 1;
}

.quiz-option__content {
  flex: 1;
  min-width: 0;
}

.quiz-option__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.quiz-option__subtitle {
  font-size: 12px;
  color: var(--text-secondary);
}

.quiz-option__link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
  margin-top: 4px;
}

.quiz-option__link:hover {
  text-decoration: underline;
}

.quiz-option--rent .quiz-option__icon {
  color: #ff9800;
}

.quiz-option--individual .quiz-option__icon {
  color: #9c27b0;
}

/* ═══════════════ КНОПКИ ═══════════════ */
.btn-primary {
  flex: 1;
  padding: 10px;
  background: var(--success);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.btn-primary.btn-waitlist {
  background: var(--warning);
  color: #333;
}

.btn-secondary {
  flex: 1;
  padding: 10px;
  background: #f5f5f5;
  color: var(--text-primary);
  border: 1px solid var(--divider);
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
}

.btn-secondary:hover {
  background: #e8e8e8;
}

/* ═══════════════ ФОРМА ═══════════════ */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  background: #fff;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.form-checkbox input[type='checkbox'] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ═══════════════ ПРЕЛОАДЕР ═══════════════ */
#preloader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--divider);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  100% {
    transform: rotate(360deg);
  }
}

/* ═══════════════ V2-F98: STAGGER-FADE ПРИ TOGGLE ═══════════════ */
#schedule-desktop.animating .schedule-row--wrapper {
  animation: stagger-fade 0.35s ease-out both;
  animation-delay: calc(var(--i, 0) * 25ms);
}

@keyframes stagger-fade {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ═══════════════ КНОПКА РАЗВЕРНУТЬ / СВЕРНУТЬ (V2-F90) ═══════════════ */
#schedule-toggle-wrap {
  display: flex;
  justify-content: center;
  padding: 16px 10px 24px;
}

.btn-toggle-view {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  min-width: 220px;
  justify-content: center;
}

.btn-toggle-view:hover {
  background: rgba(0, 122, 255, 0.06);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
}

.btn-toggle-view:active {
  transform: translateY(0);
}

.btn-toggle-view .toggle-icon {
  font-size: 12px;
  transition: transform 0.3s;
}

.btn-toggle-view.expanded .toggle-icon {
  transform: rotate(180deg);
}

/* ═══════════════ V2-F104: ФОРМА АРЕНДЫ (одна строка) ═══════════════ */
.rent-datetime {
  margin-bottom: 12px;
  font-size: 14px;
  color: #555;
}

/* Общая строка: [часы:минуты] [− длительность +] */
.rent-controls-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
}

.rent-time-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

/* ⚠️ Важно: перебиваем .form-input { width: 100% } — иначе селект уезжает
   на мобильных. Двойная страховка: уточнённый селектор + !important.
   RULES.md: CSS-переменные MAX UI не применимы (виджет без React). */
.rent-time-row .form-input.rent-time-select,
.rent-time-select {
  flex: 0 0 64px !important;
  width: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
  text-align: center;
  padding: 10px 4px;
}

.rent-time-sep {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  flex: 0 0 auto;
}

.duration-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--divider);
  border-radius: 8px;
  background: #fff;
  flex: 1 1 auto;
  min-width: 0;
  justify-content: space-between;
}

.duration-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: #f8f9fa;
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.duration-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.duration-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.duration-value {
  flex: 1 1 auto;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.rent-summary {
  margin: 10px 0 14px;
  padding: 10px 12px;
  background: rgba(0, 122, 255, 0.06);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
}

/* ═══════════════ АДАПТИВНОСТЬ ═══════════════ */
@media (max-width: 768px) {
  #schedule-desktop {
    display: none !important;
  }
  #schedule-mobile {
    display: block !important;
  }
  #schedule-toggle-wrap {
    display: none !important;
  }
}

@media (min-width: 769px) {
  #schedule-mobile {
    display: none;
  }
}

/* V2-F104: На мобильных — уменьшить контролы */
@media (max-width: 480px) {
  .rent-controls-row {
    gap: 8px;
  }

  .rent-time-row .form-input.rent-time-select,
  .rent-time-select {
    flex: 0 0 56px !important;
    width: 56px !important;
    min-width: 56px !important;
    max-width: 56px !important;
    padding: 10px 2px;
    font-size: 15px;
  }

  .duration-stepper {
    gap: 4px;
    padding: 3px;
  }

  .duration-value {
    font-size: 13px;
  }

  .duration-btn {
    width: 32px;
    height: 32px;
    font-size: 18px;
  }
}

/* Individual booking shares the rental form controls. */
.individual-booking-form { display: grid; gap: 14px; }
.individual-booking-form .form-group { display: grid; gap: 6px; margin: 0; }
.individual-booking-form .form-input { width: 100%; box-sizing: border-box; min-height: 44px; }
.individual-booking-form .form-checkbox { display: flex; align-items: flex-start; gap: 10px; }
.individual-booking-form input[type=checkbox] { width: 20px; height: 20px; flex-shrink: 0; }
.individual-booking-form .btn-primary { min-height: 44px; width: 100%; }
.btn-close { min-width: 40px; min-height: 40px; display: grid; place-items: center; }

.lesson-card { position: relative; }
.lesson-card.group .lesson-name { padding-right: 28px; }
.group-status-icon { position: absolute; top: 6px; right: 7px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; font-weight: 700; background: #eef2f6; color: #536170; }
.group-status-icon--Open { background: #f4e8fc; color: #8d24ad; }
.group-status-icon--Active { background: #e4f5ea; color: #16743b; }
