/* CalorieGemin — Нативный Obsidian Dark стиль (оптимизировано под iPhone / iOS Safari PWA, 60fps GPU) */

:root {
  color-scheme: dark;
  --bg-main: #0D0F12;
  --bg-card: #16191E;
  --bg-card-elevated: #1D2128;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --text-primary: #F3F4F6;
  --text-secondary: #9CA3AF;
  --accent-emerald: #34D399;
  --accent-amber: #FBBF24;
  --accent-sky: #38BDF8;
  --accent-rose: #F87171;
  --ease-ios-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-ios-out: cubic-bezier(0.32, 0.72, 0, 1);
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", Roboto, sans-serif;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

/* Главный контейнер с учетом нижней панели и челки iPhone */
.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

/* Плавная смена главных вкладок */
.view-enter {
  animation: viewFadeSlideIn 0.22s var(--ease-ios-spring) forwards;
  will-change: transform, opacity;
}

@keyframes viewFadeSlideIn {
  from {
    opacity: 0;
    transform: translate3d(0, 6px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* Карточки в стиле Obsidian Dark */
.obsidian-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  transition: border-color 0.2s ease, transform 0.16s var(--ease-ios-spring);
}

.obsidian-card-sm {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  transition: border-color 0.18s ease, background-color 0.18s ease, transform 0.14s var(--ease-ios-spring);
}

/* Прогресс-кольцо калорий и полоски БЖУ (настоящая GPU/SVG интерполяция) */
.ring-circle {
  transition: stroke-dashoffset 0.55s var(--ease-ios-spring), stroke 0.3s ease;
  will-change: stroke-dashoffset;
}

.macro-bar-fill {
  transition: width 0.5s var(--ease-ios-spring);
  will-change: width;
}

/* Плавная анимация строк в дневнике */
.diary-entry-row {
  transition: opacity 0.18s ease, transform 0.18s var(--ease-ios-spring), max-height 0.2s ease;
  will-change: transform, opacity;
}

.diary-entry-row.is-removing {
  opacity: 0;
  transform: translate3d(-14px, 0, 0) scale(0.97);
  pointer-events: none;
}

/* Стеклянный нижний таб-бар */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(17, 20, 25, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-inner {
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 64px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #6B7280;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.18s ease, transform 0.14s var(--ease-ios-spring);
  user-select: none;
  cursor: pointer;
}

.nav-item:active {
  transform: scale(0.92);
}

.nav-item.active {
  color: var(--accent-emerald);
}

/* Модальные окна и нижние шторки (iOS Sheet) с плавным открытием и закрытием */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: modalBackdropIn 0.22s var(--ease-ios-out) forwards;
  will-change: opacity;
}

.modal-backdrop.is-closing {
  animation: modalBackdropOut 0.2s var(--ease-ios-out) forwards;
  pointer-events: none;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  background: #15181E;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 26px 26px 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  animation: modalSheetUp 0.28s var(--ease-ios-out) forwards;
  will-change: transform;
  touch-action: pan-y;
}

/* Когда модалка уже открыта и обновляется внутри — не перезапускаем анимацию выезда */
.modal-sheet.is-mounted {
  animation: none;
}

.modal-sheet.is-closing {
  animation: modalSheetDown 0.2s var(--ease-ios-out) forwards;
  pointer-events: none;
}

/* Зона захвата шторки пальцем для свайпа вниз на iPhone */
.modal-grabber-area {
  padding-top: 10px;
  padding-bottom: 8px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.modal-grabber-bar {
  width: 40px;
  height: 4px;
  background: #4B5563;
  border-radius: 9999px;
  margin: 0 auto;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.modal-grabber-area:active .modal-grabber-bar {
  background: #9CA3AF;
  transform: scaleX(1.1);
}

@keyframes modalBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalBackdropOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modalSheetUp {
  from { transform: translate3d(0, 100%, 0); }
  to { transform: translate3d(0, 0, 0); }
}

@keyframes modalSheetDown {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, 104%, 0); }
}

/* Всплывающий тост (iOS Dynamic Island стиль) */
.toast-pill {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translate3d(-50%, 0, 0);
  z-index: 95;
  padding: 9px 18px;
  border-radius: 9999px;
  background: #34D399;
  color: #0D0F12;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(16, 185, 129, 0.35), 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  white-space: nowrap;
  animation: toastEnter 0.24s var(--ease-ios-spring) forwards;
  will-change: transform, opacity;
}

.toast-pill.is-hiding {
  animation: toastExit 0.18s ease forwards;
}

@keyframes toastEnter {
  from {
    opacity: 0;
    transform: translate3d(-50%, -16px, 0) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translate3d(-50%, 0, 0) scale(1);
  }
}

@keyframes toastExit {
  from {
    opacity: 1;
    transform: translate3d(-50%, 0, 0) scale(1);
  }
  to {
    opacity: 0;
    transform: translate3d(-50%, -12px, 0) scale(0.94);
  }
}

/* Переключатели (Segmented Controls) для Сухой/Вареный и Курицы */
.seg-group {
  display: flex;
  background: #101216;
  padding: 3px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  gap: 3px;
}

.seg-btn {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 9px;
  color: #9CA3AF;
  transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.12s var(--ease-ios-spring);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.seg-btn:active {
  transform: scale(0.96);
}

.seg-btn.active {
  background: #232832;
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.seg-btn.active-emerald {
  background: rgba(52, 211, 153, 0.16);
  color: #34D399;
  border: 1px solid rgba(52, 211, 153, 0.35);
}

/* Кнопки выбора порции с гарантированно видимым весом справа (для экранов iPhone) */
.portion-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid #252A34;
  background: #12151B;
  color: #D1D5DB;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s var(--ease-ios-spring);
  cursor: pointer;
  user-select: none;
}

.portion-chip:active {
  transform: scale(0.96);
}

.portion-chip.active {
  background: rgba(52, 211, 153, 0.16);
  border-color: #34D399;
  color: #6EE7B7;
}

.portion-chip-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.portion-chip-weight {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 3.5px 6px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  color: #9CA3AF;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.portion-chip.active .portion-chip-weight {
  background: rgba(52, 211, 153, 0.24);
  color: #A7F3D0;
}

/* Микро-отклик кнопок */
button {
  transition: transform 0.12s var(--ease-ios-spring), opacity 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Скрытие скроллбаров при сохранении прокрутки */
::-webkit-scrollbar {
  width: 0px;
  height: 0px;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Предотвращение авто-зума iOS Safari при фокусе на полях ввода */
@media screen and (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important;
  }
}
