/* ==========================================================================
   Baby Food Stock - Minimalist & Warm Aesthetic Design System
   ========================================================================== */

:root {
  --bg-primary: #FAF8F5;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #FFFFFF;
  --bg-subtle: #F2EFE9;
  
  --text-primary: #2C2825;
  --text-secondary: #706B65;
  --text-muted: #A39D94;

  --accent-sage: #5A7E68;
  --accent-sage-bg: #EDF3EF;
  --accent-sage-border: #D5E3D9;

  --border-subtle: #EBE7DF;
  --border-focus: #4F735D;
  
  --shadow-sm: 0 2px 6px rgba(44, 40, 37, 0.04);
  --shadow-md: 0 4px 16px rgba(44, 40, 37, 0.06);
  --shadow-lg: 0 10px 30px rgba(44, 40, 37, 0.08);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;

  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #181715;
    --bg-surface: #22201D;
    --bg-surface-elevated: #2C2925;
    --bg-subtle: #2B2824;

    --text-primary: #EDE9E3;
    --text-secondary: #AAA49B;
    --text-muted: #6B655D;

    --accent-sage: #81A890;
    --accent-sage-bg: #223027;
    --accent-sage-border: #324739;

    --border-subtle: #332F2A;
    --border-focus: #81A890;

    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
  }
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  width: 100%;
  max-width: 580px;
  min-height: 100vh;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-emoji {
  font-size: 1.5rem;
  line-height: 1;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.item-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  transition: var(--transition);
}

.header-right {
  display: flex;
  align-items: center;
}

.sync-status-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.sync-status-btn:hover {
  background-color: var(--bg-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background-color: #A39D94; /* 로컬 모드 기본 회색 */
  transition: var(--transition);
}

.status-dot.synced {
  background-color: #2ECC71; /* 동기화 완료 초록 */
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.4);
}

.status-dot.syncing {
  background-color: #F39C12; /* 동기화 진행 중 주황 */
  animation: pulse 1.2s infinite;
}

.status-dot.error {
  background-color: #E74C3C;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

/* --------------------------------------------------------------------------
   Input Section
   -------------------------------------------------------------------------- */
.input-section {
  position: sticky;
  top: 16px;
  z-index: 10;
  margin-bottom: 24px;
}

.add-form {
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 6px 6px 6px 18px;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-lg), 0 0 0 3px rgba(90, 126, 104, 0.12);
}

.ingredient-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  width: 100%;
}

.ingredient-input::placeholder {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.submit-btn {
  background-color: var(--accent-sage);
  color: #FFFFFF;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.submit-btn:active {
  transform: scale(0.92);
}

/* --------------------------------------------------------------------------
   Inventory Section & Grid
   -------------------------------------------------------------------------- */
.inventory-section {
  flex: 1;
}

.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state.visible {
  display: flex;
}

.empty-text {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 칩 / 카드 그리드 */
.ingredient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

/* 재료 카드 아이템 */
.ingredient-card {
  position: relative;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s ease, opacity 0.2s ease, border-color 0.2s ease;
  user-select: none;
  overflow: hidden;
  animation: cardEnter 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ingredient-card.removing {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.ingredient-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent-sage-border);
  transform: translateY(-2px);
}

.ingredient-card:active {
  transform: scale(0.97);
}

.ingredient-name {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

/* 박스 없이 아주 심플하고 작은 연월일 텍스트 */
.ingredient-date {
  font-size: 0.76rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

/* 색상별 파스텔 틴트 클래스 (아이템별 자동 부여) */
.color-tint-0 { --card-accent: #5A7E68; }
.color-tint-1 { --card-accent: #C86D51; }
.color-tint-2 { --card-accent: #B8860B; }
.color-tint-3 { --card-accent: #6C5B7B; }
.color-tint-4 { --card-accent: #487A9A; }

.ingredient-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background-color: var(--card-accent, var(--accent-sage));
  border-radius: 4px 0 0 4px;
}

/* --------------------------------------------------------------------------
   Undo Toast
   -------------------------------------------------------------------------- */
.undo-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-full);
  padding: 10px 18px 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
}

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

.undo-message {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
}

.undo-action-btn {
  background: none;
  border: none;
  color: var(--accent-sage);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.undo-action-btn:hover {
  text-decoration: underline;
}



/* 모바일 화면 최적화 */
@media (max-width: 480px) {
  .app-container {
    padding: 16px 14px 50px;
  }
  .ingredient-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .ingredient-card {
    padding: 12px 14px;
    min-height: 76px;
  }
}
