:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  /* Фирменный цвет — сознательно НЕ берём из tg-theme-button-color: у
     разных людей в Telegram он может быть синим, зелёным, чем угодно —
     а нам нужен свой узнаваемый розовый везде, чтобы приложение выглядело
     как единый свадебный продукт, а не как случайные цвета чужого клиента. */
  --link: #d4547a;
  --button: #d4547a;
  --button-text: #ffffff;
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f4f2f3);
  --header-bg: var(--tg-theme-header-bg-color, #ffffff);
  --accent: var(--button);
  --accent-rgb: 212, 84, 122;
  --accent-soft: rgba(var(--accent-rgb), 0.12);
  --border: rgba(0, 0, 0, 0.07);
  --success: #34c759;
  --danger: #ff3b30;
  --danger-soft: rgba(255, 59, 48, 0.1);
  --card-radius: 16px;
  --control-radius: 12px;
  --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.06);
  --shadow-strong: 0 8px 28px rgba(0, 0, 0, 0.16);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([style*="--tg-theme-bg-color"]) {
    --bg: #17181c;
    --text: #f2f2f4;
    --hint: #8e8e96;
    --secondary-bg: #232429;
    --border: rgba(255, 255, 255, 0.08);
    --danger-soft: rgba(255, 59, 48, 0.18);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  overscroll-behavior-y: contain;
}

#app {
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

/* ---------------------------------------------------------------------- */
/* Загрузочный экран                                                      */
/* ---------------------------------------------------------------------- */

.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  z-index: 100;
  transition: opacity 0.25s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

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

.loading-screen .loading-text {
  font-size: 13px;
  color: var(--hint);
  text-align: center;
  line-height: 1.5;
  max-width: 260px;
}

.hidden-block { display: none !important; }

#loading-state,
#error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.error-icon { font-size: 34px; }

.retry-btn {
  margin-top: 4px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--control-radius);
  background: var(--accent);
  color: var(--button-text);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.retry-btn:active { opacity: 0.85; }

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

/* ---------------------------------------------------------------------- */
/* Шапка                                                                   */
/* ---------------------------------------------------------------------- */

.header {
  padding: 22px 20px 16px;
  text-align: center;
  background: linear-gradient(180deg, var(--accent-soft) 0%, transparent 100%);
}

.header-emoji {
  font-size: 26px;
  margin-bottom: 2px;
}

.countdown {
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.countdown .num {
  color: var(--accent);
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--bg);
  box-shadow: var(--shadow-soft);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.stat-chip .stat-icon { font-size: 13px; }

/* ---------------------------------------------------------------------- */
/* Табы                                                                    */
/* ---------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 3px;
  margin: 4px 14px 10px;
  padding: 4px;
  border-radius: 14px;
  background: var(--secondary-bg);
  position: sticky;
  top: 8px;
  z-index: 5;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 4px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tab .tab-icon { font-size: 14px; }

.tab.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

main { padding: 0 14px; }

.tab-content { display: none; animation: fade-in 0.2s ease; }
.tab-content.active { display: block; }

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

/* ---------------------------------------------------------------------- */
/* Карточки прогресса                                                      */
/* ---------------------------------------------------------------------- */

.progress-card,
.budget-card,
.summary-card {
  background: var(--secondary-bg);
  border-radius: var(--card-radius);
  padding: 14px 16px;
  margin: 10px 0 14px;
}

.progress-bar {
  height: 9px;
  border-radius: 5px;
  background: var(--bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 0;
  background: var(--accent);
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 70%, white));
  width: 0%;
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 12.5px;
  color: var(--hint);
  margin-top: 8px;
  font-weight: 500;
}

.budget-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.budget-total {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 600;
}

.edit-total-btn {
  border: none;
  background: var(--bg);
  box-shadow: var(--shadow-soft);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-total-btn:active { transform: scale(0.9); }

.budget-total .muted { color: var(--hint); font-weight: 400; }

.budget-remaining {
  font-size: 12.5px;
  margin-top: 8px;
  font-weight: 600;
}

.budget-remaining.over { color: var(--danger); }
.budget-remaining.under { color: var(--success); }

.summary-card { font-size: 13.5px; color: var(--hint); display: flex; justify-content: space-between; }
.summary-card b { color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Списки                                                                   */
/* ---------------------------------------------------------------------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: var(--card-radius);
  background: var(--secondary-bg);
  transition: opacity 0.2s ease, transform 0.15s ease;
}

.list li:active { transform: scale(0.985); }

.list li.done { opacity: 0.6; }

.list li .title {
  flex: 1;
  min-width: 0;
}

.list li .title .name {
  font-weight: 600;
  font-size: 14.5px;
  overflow-wrap: anywhere;
}

.list li .title .meta {
  font-size: 12px;
  color: var(--hint);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}

.list li.done .name { text-decoration: line-through; color: var(--hint); }

.checkbox-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--accent);
  padding: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}

.checkbox-btn.done { background: var(--accent); color: #fff; transform: scale(1.05); }
.checkbox-btn:active { transform: scale(0.9); }

.icon-btn {
  border: none;
  background: none;
  color: var(--hint);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:active { background: var(--danger-soft); color: var(--danger); }

.mini-budget-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg);
  overflow: hidden;
  margin-top: 6px;
  width: 100%;
}

.mini-budget-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.mini-budget-fill.over { background: var(--danger); }

.mini-input {
  width: 88px;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12.5px;
}

.rsvp-pill {
  border: none;
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--hint);
  white-space: nowrap;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.rsvp-pill:active { transform: scale(0.94); }

.rsvp-pill.confirmed { background: var(--success); color: #fff; }
.rsvp-pill.declined { background: var(--danger); color: #fff; }
.rsvp-pill.invited { background: var(--bg); color: var(--hint); border: 1px solid var(--border); }

.empty-hint {
  color: var(--hint);
  font-size: 13px;
  padding: 40px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.empty-hint .empty-icon { font-size: 30px; opacity: 0.6; }

/* ---------------------------------------------------------------------- */
/* Плавающая кнопка добавления                                             */
/* ---------------------------------------------------------------------- */

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: transform 0.15s ease;
}

.fab:active { transform: scale(0.9); }

/* ---------------------------------------------------------------------- */
/* Нижний лист (bottom sheet) для форм добавления                          */
/* ---------------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 30;
}

.sheet-backdrop.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 31;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
}

.sheet.show { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 6px auto 14px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sheet h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
}

.sheet-close {
  border: none;
  background: var(--secondary-bg);
  color: var(--hint);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------------- */
/* Формы                                                                    */
/* ---------------------------------------------------------------------- */

.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-form input[type="text"],
.add-form input[type="number"] {
  flex: 1;
  min-width: 120px;
  padding: 12px 14px;
  border-radius: var(--control-radius);
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
}

.add-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.add-form button {
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-radius: var(--control-radius);
  background: var(--button);
  color: var(--button-text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  margin-top: 2px;
}

.add-form button:active { opacity: 0.85; }

.add-form button:disabled { opacity: 0.55; pointer-events: none; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--hint);
  width: 100%;
  padding: 2px 2px 4px;
}

.checkbox-label input { width: 16px; height: 16px; }

/* ---------------------------------------------------------------------- */
/* Тост                                                                     */
/* ---------------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  box-shadow: var(--shadow-strong);
  z-index: 40;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
