/* Сброс стилей */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #121212;
  color: #e8e8e8;
  padding: 16px;
  min-height: 100vh; /* Фоллбэк для старых браузеров */
  min-height: var(--app-height, 100vh); /* Высота от MAX */
  box-sizing: border-box;
}

h1 {
  font-size: 22px;
  margin: 0 0 16px;
}

h2 {
  font-size: 18px;
  margin: 24px 0 12px;
}

.hidden {
  display: none !important;
}

/* --- Заголовок с логотипом --- */
.header-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 24px;
}
.header-wrap h1 {
  margin: 0;
}
.logo {
  width: 80px;
  height: 80px;
  border-radius: 12px;
  margin-bottom: 12px;
  object-fit: cover;
  background: #fff;
}

/* --- Главный экран клиента --- */
#main-screen {
  display: flex;
  flex-direction: column;
  min-height: calc(var(--app-height, 100vh) - 32px); /* 32px = паддинги body */
}

/* --- Формы --- */
label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #b0b0b0;
  margin-top: 16px;
}

select, input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  font-size: 15px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  color: #fff;
}

select:disabled, input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Кнопки --- */
button.primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: #2ecc71;
  color: #121212;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 20px;
  transition: background 0.2s, opacity 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

button.primary:hover:not(:disabled) {
  background: #27ae60;
}

button.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  background: #1e1e1e;
  color: #2ecc71;
  border: 1px solid #2ecc71;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 16px;
  transition: background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

button.secondary:hover {
  background: rgba(46, 204, 113, 0.1);
}

/* --- Сообщения об ошибках / успехе --- */
.msg {
  margin-top: 10px;
  font-size: 14px;
  min-height: 18px;
  text-align: center;
}
.msg.error { color: #ff6b6b; }
.msg.ok { color: #2ecc71; }

/* --- Сетка дат --- */
.date-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  margin-top: 8px;
}

.date-btn {
  width: 100%;
  background: #1e1e1e;
  border: 1px solid #333;
  color: #e8e8e8;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  text-align: left;
  -webkit-appearance: none;
  appearance: none;
}

.date-btn:hover:not(.disabled) { background: #2c2c2c; }
.date-btn.disabled { opacity: 0.4; cursor: not-allowed; }

.date-btn .dow { font-size: 14px; color: #a0a0a0; width: 40px; text-transform: capitalize; }
.date-btn .day { font-size: 16px; font-weight: bold; flex-grow: 1; }
.date-btn .count { font-size: 13px; color: #2ecc71; background: rgba(46, 204, 113, 0.1); padding: 4px 10px; border-radius: 20px; }

/* Красная плашка для выходного дня */
.date-btn .count.day-off {
  background: #e74c3c;
  color: #ffffff;
  font-weight: 600;
}

button.date-btn.active,
.date-btn.active {
  background-color: #2ecc71 !important;
  border-color: #2ecc71 !important;
  color: #121212 !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}
.date-btn.active .dow,
.date-btn.active .day,
.date-btn.active .count {
  color: #121212 !important;
  background-color: transparent !important;
}
.date-btn.active .count {
  background-color: rgba(0, 0, 0, 0.1) !important;
}

.date-grid.is-collapsed .date-btn:not(.active) {
  display: none;
}

/* --- Сетка времени --- */
.time-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
  margin-top: 8px;
}

.time-grid .meta {
  grid-column: 1 / -1;
  text-align: center;
  width: 100%;
}

.time-btn {
  background: #1e1e1e;
  border: 1px solid #333;
  color: #e8e8e8;
  padding: 12px 5px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
}
.time-btn:hover { background: #2c2c2c; border-color: #555; }
.time-btn.active {
  background-color: #2ecc71 !important;
  color: #121212 !important;
  border-color: #2ecc71 !important;
  font-weight: bold;
}

/* =========================================
   ЕДИНЫЙ СТИЛЬ КАРТОЧЕК (Клиент, Мастер, Услуги)
   ========================================= */
.unified-card {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.2s;
}
.unified-card.past { opacity: 0.5; }

.card-header {
  display: flex;
  gap: 16px;
  align-items: center;
}

.card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: #333;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: #e8e8e8;
  margin: 0 0 4px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.card-subtitle {
  font-size: 14px;
  color: #a0a0a0;
}

.card-details {
  display: flex;
  gap: 12px;
  background: #121212;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #e8e8e8;
}
.card-detail-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Бейджи статусов */
.status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}
.status-pending { background: #f39c12; color: #121212; }
.status-confirmed { background: #2ecc71; color: #121212; }
.status-completed { background: #3498db; color: #fff; }

/* Кнопки действий в карточках */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.btn-action {
  flex: 1;
  padding: 10px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  border: 1px solid transparent;
  transition: all 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.btn-action.confirm { background: #2ecc71; color: #121212; }
.btn-action.cancel { background: transparent; color: #ff6b6b; border-color: #ff6b6b; }

.btn-action.icon-only {
  flex: 0 0 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.btn-action.icon-only.edit { background: rgba(46, 204, 113, 0.1); color: #2ecc71; }
.btn-action.icon-only.delete { background: rgba(255, 107, 107, 0.1); color: #ff6b6b; }

/* --- Сворачиваемая панель мастера --- */
.master-panel-heading {
  margin: 0 0 16px;
}

.master-panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.master-panel-toggle:active { opacity: 0.75; }
.master-panel-toggle:focus-visible { outline: 2px solid #2ecc71; outline-offset: 4px; }

.master-panel-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}

.master-panel-icon .icon-plus { display: none; color: #2ecc71; }
.master-panel-icon .icon-minus { color: #e74c3c; }

.master-panel.collapsed .master-panel-icon .icon-plus { display: inline; }
.master-panel.collapsed .master-panel-icon .icon-minus { display: none; }

.master-panel-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.25s ease;
}

.master-panel-body > .master-panel-inner {
  overflow: hidden;
  min-height: 0;
}

.master-panel.collapsed .master-panel-body { grid-template-rows: 0fr; }

@media (prefers-reduced-motion: reduce) {
  .master-panel-body { transition: none; }
}

/* Навигация страниц мастера */
.master-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.master-nav a {
  padding: 14px 12px;
  text-align: center;
  color: #a0a0a0;
  text-decoration: none;
  font-size: 14px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 10px;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.master-nav a:hover { background: #2c2c2c; color: #e8e8e8; }
.master-nav a.active { background: #27ae60; border-color: #27ae60; color: #ffffff; font-weight: 600; }
.master-nav a:last-child:nth-child(odd) { grid-column: 1 / -1; }

.tab-content { display: none; }
.tab-content.active { display: block; }

.badge {
  display: inline-block;
  background: #f39c12;
  color: #121212;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
}

/* --- Спиннер --- */
.spinner-wrap { display: flex; justify-content: center; padding: 40px 0; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid #333;
  border-top-color: #2ecc71;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Общие тексты */
.meta {
  color: #a0a0a0;
  text-align: center;
  padding: 10px 0;
  font-size: 14px;
}

/* Фильтры записей */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1e1e1e;
  border: 1px solid #333;
  color: #e8e8e8;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.filter-btn:hover { background: #2c2c2c; }
.filter-btn.active {
  background: #2ecc71;
  border-color: #2ecc71;
  color: #121212;
  font-weight: 600;
}
.filter-count {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  background: #FF0000;
  color: #121212;
  text-align: center;
}
.filter-btn.active .filter-count {
  background: #ffffff;
  color: #2ecc71;
}

/* --- Карточка салона --- */
.salon-logo { max-width: 80px; border-radius: 20px; }
.salon-greeting { font-size: 18px; color: #aaa; font-weight: normal; margin-bottom: 16px; }
.salon-card { padding: 16px; margin-bottom: 24px; }
.salon-name { width: max-content; margin: 0 auto 12px auto; color: #f5f5f5; font-weight: 700; }

.salon-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 14px;
  color: #ccc;
}

.salon-info-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.salon-info-row.center { align-items: center; }

.salon-phone-link {
  color: #86cf7c;
  text-decoration: none;
  transition: color 0.2s ease;
}

/* --- Специфичные кнопки --- */
.btn-back { margin-bottom: 16px; font-size: 13px; }
.btn-new-booking { font-size: 16px; padding: 14px; }
.btn-change-date { width: 100%; padding: 18px; font-size: 18px; background: transparent; color: #2ecc71; border: 1px solid #2ecc71; border-radius: 12px; cursor: pointer; margin-top: 16px; margin-bottom: 24px; display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 500; }

/* --- Карточка записи клиента --- */
.booking-card { display: flex; flex-direction: column; }
.booking-service-name { font-weight: bold; font-size: 16px; color: #2ecc71; margin-bottom: 8px; }
.booking-info-row { margin-top: 4px; font-size: 14px; }
.btn-cancel-booking { margin-top: 14px; width: 100%; color: #e74c3c; border: 1px solid #e74c3c; background: transparent; padding: 8px; font-size: 14px; border-radius: 8px; box-sizing: border-box; }

/* --- Модальные окна (общие) --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 1000; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box; }
.modal-content { background: #1e1e1e; border-radius: 12px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto; position: relative; padding: 20px; box-sizing: border-box; }
.modal-close-btn { position: absolute; top: 10px; right: 10px; background: transparent; border: none; color: #aaa; font-size: 22px; cursor: pointer; padding: 4px 8px; line-height: 1; }

/* --- Специфичные элементы страниц мастера --- */
.search-input { width: 100%; padding: 10px; background: #1e1e1e; color: #fff; border: 1px solid #333; border-radius: 8px; font-family: inherit; box-sizing: border-box; }
.pager-container { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 8px; }
.pager-btn { font-size: 13px; }
.pager-info { text-align: center; font-size: 13px; }
.card-right-chevron { color: #666; font-size: 20px; padding-left: 8px; }
.service-form-wrap { margin-top: 20px; padding: 16px; background: #1e1e1e; border-radius: 10px; }
.settings-textarea { width: 100%; background: #121212; color: #fff; border: 1px solid #333; border-radius: 8px; padding: 8px; font-family: inherit; resize: vertical; }
.settings-hint { text-align: left; font-size: 12px; padding: 0; margin-top: 4px; }
.phone-warning { margin-top: 8px; font-size: 12px; color: #aaa; background: #1e1e1e; padding: 10px; border-radius: 8px; border: 1px solid #333; }

/* --- Подвал страницы --- */
.footer-text {
  margin-top: auto;
  padding-top: 40px;
  padding-bottom: 8px;
  text-align: center;
  color: #666;
  font-size: 13px;
  font-weight: 500;
}

/* --- Переключатель (Switch) --- */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #444;
  transition: .4s;
  border-radius: 34px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}
input:checked + .slider { background-color: #2ecc71; }
input:checked + .slider:before { transform: translateX(22px); }

/* =========================================
   УТИЛИТЫ
   ========================================= */
.w-100 { width: 100%; }
.text-center { text-align: center; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-0 { margin-top: 0; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Заголовок дня в списке записей */
.date-group-header {
  position: sticky;
  top: 0;
  background: #121212;
  padding: 12px 0 8px 0;
  margin-top: 16px;
  font-size: 15px;
  font-weight: bold;
  color: #2ecc71;
  z-index: 10;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.date-group-header:first-child {
  margin-top: 0;
}
.date-group-count {
  font-size: 12px;
  color: #888;
  font-weight: normal;
  background: #1e1e1e;
  padding: 2px 8px;
  border-radius: 10px;
}

/* --- Сводка по дням мастера --- */
.day-group {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
.day-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: #1e1e1e;
  transition: background 0.2s;
}
.day-header:hover { background: #2c2c2c; }
.day-header.collapsed { border-bottom: none; }
.day-header:not(.collapsed) { border-bottom: 1px solid #333; }
.day-title { font-size: 16px; font-weight: 600; color: #e8e8e8; }
.day-stats { font-size: 13px; color: #a0a0a0; display: flex; gap: 12px; }
.day-stat-badge { background: #121212; padding: 4px 8px; border-radius: 6px; }

/* Сетка слотов внутри дня */
.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  padding: 16px;
  background: #121212;
}
.day-grid.hidden { display: none; }
.slot-item {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: 14px;
  transition: all 0.2s;
}
.slot-item.free {
  cursor: pointer;
  color: #2ecc71;
  border-color: #000000;
}
.slot-item.free:hover { background: rgba(46, 204, 113, 0.1); border-color: #2ecc71; }
.slot-item.booked {
  background: #000000;
  border-color: #000000;
  color: #ff4343;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slot-time { font-weight: bold; font-size: 12px; margin-bottom: 4px; opacity: 0.7; }
.slot-client { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-service { font-size: 11px; color: #aaa; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Контейнер содержимого дня */
.day-content {
  background: #121212;
}
.day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  padding: 16px;
}
.day-grid.hidden { display: none; }

/* Селектор услуги */
.day-service-select {
  width: 100%;
  padding: 10px;
  background: #1e1e1e;
  color: #fff;
  border: 1px solid #333;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  margin-top: 4px;
}

/* Фильтры записей */
.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.filter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #1e1e1e;
  border: 1px solid #333;
  color: #a0a0a0;
  padding: 12px 10px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  text-align: center;
}

.filter-btn:hover {
  background: #2c2c2c;
  color: #e8e8e8;
}

.filter-btn.active {
  background: #27ae60;
  border-color: #27ae60;
  color: #ffffff;
  font-weight: 600;
}

.filter-count {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  background: #FF0000;
  color: #121212;
  text-align: center;
}
.filter-btn.active .filter-count {
  background-color: #e74c3c !important;
  color: #ffffff !important;
}

/* Разделитель под панелью мастера */
.master-panel {
  border-bottom: 1px solid #333;
  padding-bottom: 16px;
  margin-bottom: 20px;
}

/* Когда панель свернута, оставляем только аккуратный отступ */
.master-panel.collapsed {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 16px;
}