/*
 * styles.css — Мой График PWA
 *
 * Организация:
 *   1. CSS Variables (tokens)
 *   2. Reset & Base
 *   3. Layout
 *   4. Header
 *   5. Today Banner
 *   6. Cards & Shared
 *   7. Shift Selector
 *   8. Calendar
 *   9. Stats
 *  10. Modals
 *  11. Form Elements
 *  12. Toast System
 *  13. Animations
 *  14. Accessibility / Focus
 *  15. Media Queries
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1. CSS Variables — тёмная тема (по умолчанию)
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  /* Цвета */
  --bg:             #0a0b10;
  --surface:        #12141d;
  --card:           #1a1d2e;
  --border:         #2a2d45;
  --work:           #00d4aa;
  --work-dim:       rgba(0, 212, 170, 0.15);
  --work-border:    rgba(0, 212, 170, 0.3);
  --rest:           #7b6ff0;
  --rest-dim:       rgba(123, 111, 240, 0.15);
  --rest-border:    rgba(123, 111, 240, 0.3);
  --vacation:       #f0a500;
  --vacation-dim:   rgba(240, 165, 0, 0.15);
  --vacation-border:rgba(240, 165, 0, 0.3);
  --text:           #e8eaf6;
  --muted:          #8a8fba;
  --accent:         #ff4757;
  --accent-dim:     rgba(255, 71, 87, 0.15);
  --accent-border:  rgba(255, 71, 87, 0.3);
  --overlay-bg:     rgba(0, 0, 0, 0.65);

  /* Radii */
  --radius:    16px;
  --radius-sm: 12px;
  --radius-xs: 8px;

  /* Transitions — конкретные свойства, без transition:all */
  --trans-color:     background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  --trans-transform: transform 0.15s ease;
  --trans-opacity:   opacity 0.25s ease;
  --trans-modal:     transform 0.32s cubic-bezier(0.175, 0.885, 0.32, 1.05);

  /* Shadows — минимальные, без дорогих фильтров */
  --shadow-card: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* ─── Светлая тема ─────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:             #f2f4f8;
  --surface:        #ffffff;
  --card:           #ffffff;
  --border:         #dbe0ed;
  --work:           #00a884;
  --work-dim:       rgba(0, 168, 132, 0.1);
  --work-border:    rgba(0, 168, 132, 0.3);
  --rest:           #6255d6;
  --rest-dim:       rgba(98, 85, 214, 0.1);
  --rest-border:    rgba(98, 85, 214, 0.3);
  --vacation:       #e68a00;
  --vacation-dim:   rgba(230, 138, 0, 0.1);
  --vacation-border:rgba(230, 138, 0, 0.3);
  --text:           #1a1d2e;
  --muted:          #6b7099;
  --overlay-bg:     rgba(0, 0, 0, 0.45);
  --shadow-card:    0 2px 12px rgba(0, 0, 0, 0.08);
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. Reset & Base
   ═══════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  /* Предотвращаем горизонтальный скролл на мобильных */
  overflow-x: hidden;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height (iOS Safari) */
  overflow-x: hidden;
  /* Предотвращаем резиновый bounce на iOS */
  overscroll-behavior-y: none;
  /* Плавное переключение темы */
  transition: var(--trans-color);
  /* Рендеринг текста */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  outline: none;
  border: none;
  cursor: pointer;
  /* Убираем двойное нажатие для зума на мобильных */
  touch-action: manipulation;
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. Layout
   ═══════════════════════════════════════════════════════════════════════════ */
.app {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px 16px;
  /* Отступ снизу для safe area (iOS home indicator) */
  padding-bottom: calc(32px + env(safe-area-inset-bottom, 16px));
  /* Отступ сверху для status bar в standalone режиме */
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. Header
   ═══════════════════════════════════════════════════════════════════════════ */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.logo {
  font-family: 'Unbounded', sans-serif;
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--work) 0%, var(--rest) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  /* Защита от пустого текста при загрузке шрифта */
  letter-spacing: -0.5px;
}

.controls {
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  /* Конкретные свойства вместо transition:all */
  transition: var(--trans-color), var(--trans-transform);
  will-change: transform;
}

.icon-btn:active {
  transform: scale(0.88);
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. Today Banner
   ═══════════════════════════════════════════════════════════════════════════ */
.today-banner {
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 16px;
  display: none;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-size: 14px;
}

.today-banner.active {
  display: flex;
  animation: slideDown 0.3s ease;
}

.today-banner-label {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.today-banner-text {
  margin-top: 2px;
  font-size: 14px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. Cards & Shared
   ═══════════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
  transition: var(--trans-color);
}

.card-label {
  font-family: 'Unbounded', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ═══════════════════════════════════════════════════════════════════════════
   7. Shift Selector
   ═══════════════════════════════════════════════════════════════════════════ */
.shift-selector {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shift-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  /* Скрываем scrollbar */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.shift-row::-webkit-scrollbar { display: none; }

.shift-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: var(--trans-color), var(--trans-transform);
  touch-action: manipulation;
}

.shift-btn:active { transform: scale(0.94); }

.shift-btn.w.active {
  background: var(--work);
  color: #fff;
  border-color: var(--work);
}

.shift-btn.r.active {
  background: var(--rest);
  color: #fff;
  border-color: var(--rest);
}

/* ═══════════════════════════════════════════════════════════════════════════
   8. Calendar
   ═══════════════════════════════════════════════════════════════════════════ */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.month-title {
  font-family: 'Unbounded', sans-serif;
  font-size: 15px;
  font-weight: 600;
  text-transform: capitalize;
  text-align: center;
  /* Фиксированная ширина чтобы кнопки не прыгали */
  flex: 1;
  padding: 0 8px;
}

.cal-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.cal-header-day {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  padding: 2px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  /* Предотвращаем случайный swipe-scroll */
  touch-action: pan-y;
}

.day-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  transition: var(--trans-color), var(--trans-transform);
  will-change: transform;
  touch-action: manipulation;
  /* Предотвращаем выделение текста при быстрых тапах */
  user-select: none;
  -webkit-user-select: none;
}

.day-cell:active { transform: scale(0.88); }

.day-num {
  /* Span внутри ячейки — для правильного позиционирования */
  line-height: 1;
  pointer-events: none;
}

.day-cell.empty {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
  cursor: default;
}

/* Типы дней */
.day-cell.work {
  background: var(--work-dim);
  border-color: var(--work-border);
  color: var(--work);
}

.day-cell.rest {
  background: var(--rest-dim);
  border-color: var(--rest-border);
  color: var(--rest);
}

.day-cell.vacation {
  background: var(--vacation-dim);
  border-color: var(--vacation-border);
  color: var(--vacation);
}

/* Сегодня */
.day-cell.today {
  font-weight: 700;
  box-shadow: inset 0 0 0 2px currentColor;
}

.day-cell.today::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  pointer-events: none;
}

/* Иконки в ячейках */
.payday-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}

.note-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}

/* Сдвигаем note-dot если есть "today" точка */
.day-cell.today .note-dot {
  right: 11px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   9. Stats & Salary
   ═══════════════════════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.stat-item {
  background: var(--surface);
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  border: 1px solid var(--border);
  transition: var(--trans-color);
}

.stat-item.full {
  grid-column: span 2;
  background: linear-gradient(135deg, var(--work-dim), var(--rest-dim));
  border-color: transparent;
}

.stat-val {
  font-family: 'Unbounded', sans-serif;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-lbl {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   10. Modals
   ═══════════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0; /* top/right/bottom/left: 0 */
  background: var(--overlay-bg);
  /* НЕ используем backdrop-filter — дорого на мобильных */
  display: flex;
  justify-content: center;
  align-items: flex-end;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  /* Анимируем только opacity */
  transition: var(--trans-opacity);
  /* Учитываем safe-area снизу */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--card);
  width: 100%;
  max-width: 500px;
  border-radius: 24px 24px 0 0;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: var(--trans-modal);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  /* Плавный скролл внутри модалки */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  will-change: transform;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

/* Drag handle */
.modal::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: -10px auto 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-family: 'Unbounded', sans-serif;
  font-weight: 600;
  font-size: 17px;
}

.close-btn {
  background: var(--surface);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--muted);
  flex-shrink: 0;
  transition: var(--trans-color), var(--trans-transform);
  touch-action: manipulation;
}

.close-btn:active { transform: scale(0.88); }

/* ─── Раздел внутри модалки ─────────────────────────────────────────────── */
.modal-section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Action Buttons ────────────────────────────────────────────────────── */
.action-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.action-btn {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--trans-color), var(--trans-transform);
  touch-action: manipulation;
}

.action-btn:active { transform: scale(0.97); }

.action-btn.danger {
  color: var(--accent);
  border-color: var(--accent-border);
}

/* ─── Divider ────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
  position: relative;
}

.divider::after {
  content: 'ИЛИ';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  padding: 0 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   11. Form Elements
   ═══════════════════════════════════════════════════════════════════════════ */
.input-group {
  margin-bottom: 14px;
}

.input-group label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 500;
}

.input-group input,
.input-group select,
.input-group textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  /* Убираем системный outline на iOS */
  -webkit-appearance: none;
  appearance: none;
  transition: var(--trans-color);
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
  outline: none;
  border-color: var(--work);
}

.input-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8fba' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.input-row {
  display: flex;
  gap: 10px;
}

.input-row .input-group {
  flex: 1;
}

/* ─── Кнопки ─────────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--work), var(--rest));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--trans-transform), opacity 0.2s ease;
  touch-action: manipulation;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-outline {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid var(--border);
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--trans-color), var(--trans-transform);
  touch-action: manipulation;
}

.btn-outline:active { transform: scale(0.97); }

/* ═══════════════════════════════════════════════════════════════════════════
   12. Toast System
   ═══════════════════════════════════════════════════════════════════════════ */
#toastContainer {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(calc(100vw - 32px), 400px);
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  pointer-events: auto;
  cursor: pointer;
  /* Начальное состояние: скрыт снизу */
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.1);
  will-change: transform, opacity;
  box-shadow: var(--shadow-card);
}

.toast--show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast--success {
  border-color: var(--work-border);
  color: var(--work);
}

.toast--error {
  border-color: var(--accent-border);
  color: var(--accent);
}

.toast--info {
  border-color: var(--border);
  color: var(--muted);
}

/* ═══════════════════════════════════════════════════════════════════════════
   13. Animations
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   14. Accessibility / Focus
   ═══════════════════════════════════════════════════════════════════════════ */

/* Показываем focus только при keyboard navigation */
:focus-visible {
  outline: 2px solid var(--work);
  outline-offset: 2px;
}

/* Скрываем focus при mouse/touch */
:focus:not(:focus-visible) {
  outline: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   15. Media Queries
   ═══════════════════════════════════════════════════════════════════════════ */

/* Очень маленькие экраны (< 360px) */
@media (max-width: 360px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .card { padding: 16px; }
  .day-cell { font-size: 13px; }
  .cal-grid { gap: 4px; }
  .logo { font-size: 18px; }
  .stat-val { font-size: 16px; }
}

/* Предпочтение анимаций: убираем для людей с вестибулярными нарушениями */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
