:root {
  /* 타이포/여백 스케일 — 값이 늘어날수록 하나씩 정해진 비율로 커지게 해서, 새 요소를 추가할 때
     매번 임의의 rem 값을 새로 고르지 않고 이 중에서 고르면 된다. */
  --fs-2xs: 0.72rem;
  --fs-xs: 0.8rem;
  --fs-sm: 0.88rem;
  --fs-base: 1rem;
  --fs-md: 1.1rem;
  --fs-lg: 1.3rem;
  --fs-xl: 1.6rem;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --radius: 16px;
}

:root {
  --bg: #f6f7f2;
  --surface: #ffffff;
  --text: #1f2a24;
  --text-muted: #6b7568;
  --border: #e3e7dd;
  /* 허브그린 — 기본 SaaS 초록 대신 부엌/가정용 앱에 어울리게 살짝 올리브 톤으로 */
  --brand: #427e33;
  --brand-dark: #2f5c25;
  --brand-soft: #e8f2e3;
  --brand-contrast: #ffffff;
  /* 테라코타 포인트 — 재고 상태(초록/노랑/빨강)와 겹치지 않게, 초대코드·플로팅버튼 같은
     "사람이 직접 하는 행동" 포인트에만 쓴다 */
  --accent-warm: #c35222;
  --accent-warm-dark: #b6491a;
  --accent-warm-soft: #faeadf;
  --danger: #d64545;
  --danger-soft: #fdeaea;
  --warn: #e2a83a;
  --warn-soft: #fdf3df;
  --warn-text: #8a5a12;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 4px 16px rgba(20, 30, 25, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141815;
    --surface: #1d2320;
    --text: #eef1ec;
    --text-muted: #9aa79d;
    --border: #2b332e;
    --brand: #7fc766;
    --brand-dark: #98db80;
    --brand-soft: #223622;
    --brand-contrast: #141815;
    --accent-warm: #df5f1f;
    --accent-warm-dark: #e47943;
    --accent-warm-soft: #422719;
    --danger: #e57373;
    --danger-soft: #3a1f1f;
    --warn: #e9bf6b;
    --warn-soft: #3a2f14;
    --warn-text: #f0cf8a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

/* 시스템 설정과 무관하게 사용자가 직접 고른 모드 — data-theme이 위 media query보다 우선한다 */
:root[data-theme="light"] {
  --bg: #f6f7f2;
  --surface: #ffffff;
  --text: #1f2a24;
  --text-muted: #6b7568;
  --border: #e3e7dd;
  --brand: #427e33;
  --brand-dark: #2f5c25;
  --brand-soft: #e8f2e3;
  --brand-contrast: #ffffff;
  --accent-warm: #c35222;
  --accent-warm-dark: #b6491a;
  --accent-warm-soft: #faeadf;
  --danger: #d64545;
  --danger-soft: #fdeaea;
  --warn: #e2a83a;
  --warn-soft: #fdf3df;
  --warn-text: #8a5a12;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 4px 16px rgba(20, 30, 25, 0.06);
}
:root[data-theme="dark"] {
  --bg: #141815;
  --surface: #1d2320;
  --text: #eef1ec;
  --text-muted: #9aa79d;
  --border: #2b332e;
  --brand: #7fc766;
  --brand-dark: #98db80;
  --brand-soft: #223622;
  --brand-contrast: #141815;
  --accent-warm: #df5f1f;
  --accent-warm-dark: #e47943;
  --accent-warm-soft: #422719;
  --danger: #e57373;
  --danger-soft: #3a1f1f;
  --warn: #e9bf6b;
  --warn-soft: #3a2f14;
  --warn-text: #f0cf8a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
}

.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: var(--fs-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--brand-dark); }

/* 유틸리티 — 템플릿에 흩어져 있던 style="flex:1" 같은 인라인 스타일을 대신한다 */
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.text-center { text-align: center; }
.mt-sm { margin-top: var(--sp-2); }
.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-4); }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 var(--sp-4) 90px;
}

header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.brand {
  font-weight: 700;
  font-size: var(--fs-md);
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

nav.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: var(--sp-2) var(--sp-4) 0;
  max-width: 720px;
  margin: 0 auto;
}

nav.tabs a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 999px;
  white-space: nowrap;
}

nav.tabs a.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 600;
}

form.logout-form { margin: 0; }
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  cursor: pointer;
  padding: 6px var(--sp-2);
}

h1 { font-size: var(--fs-xl); margin: var(--sp-5) 0 var(--sp-1); }
h2 { font-size: var(--fs-md); margin: var(--sp-5) 0 var(--sp-2); }
p.subtitle { color: var(--text-muted); margin-top: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.flash {
  padding: var(--sp-3) 14px;
  border-radius: 12px;
  margin: 14px 0;
  font-size: var(--fs-sm);
}
.flash.success { background: var(--brand-soft); color: var(--brand-dark); }
.flash.warning { background: var(--warn-soft); color: var(--warn-text); }

label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin: 14px 0 6px;
}
label:first-child { margin-top: 0; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%;
  padding: 11px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-base);
}
input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: var(--fs-base);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
  margin-top: 18px;
}
.btn-primary { background: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { width: auto; padding: 8px var(--sp-3); font-size: var(--fs-xs); margin-top: 0; }

.btn-row { display: flex; gap: var(--sp-2); }
.btn-row .btn { margin-top: 0; }

.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent-warm);
  color: white;
  font-size: var(--fs-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(195, 82, 34, 0.4);
}

.fridge-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

/* 4도어(상단 냉장실 2칸 + 하단 냉동 서랍 2칸) 냉장고 실루엣 */
.fridge-illustration {
  flex-shrink: 0;
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.4fr 1fr;
  gap: 5px;
  width: 132px;
  height: 172px;
  background: linear-gradient(160deg, var(--surface), var(--border));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 6px;
  box-shadow: var(--shadow);
}
.fridge-door {
  position: relative;
  background: linear-gradient(155deg, var(--bg), var(--surface));
  border: 1px solid var(--border);
  border-radius: 9px;
}
/* 상단 2칸: 냉장실 도어 — 손잡이가 가운데서 서로 마주보게 세로로 */
.fridge-door:nth-child(1)::after,
.fridge-door:nth-child(2)::after {
  content: "";
  position: absolute;
  top: 18%;
  bottom: 18%;
  width: 4px;
  border-radius: 3px;
  background: var(--text-muted);
}
.fridge-door:nth-child(1)::after { right: 8px; }
.fridge-door:nth-child(2)::after { left: 8px; }
/* 하단 2칸: 냉동 서랍 — 손잡이가 위쪽에 가로로 */
.fridge-door:nth-child(3)::after,
.fridge-door:nth-child(4)::after {
  content: "";
  position: absolute;
  top: 14%;
  left: 18%;
  right: 18%;
  height: 4px;
  border-radius: 3px;
  background: var(--text-muted);
}

/* 냉장고 모서리에 만료됨/곧만료 상태를 작은 점으로 — 장식이 아니라 한눈에 보는 정보가 되도록 */
.fridge-status-dots {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
}
.fridge-status-dots .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--surface);
}
.fridge-status-dots .dot.expired { background: var(--danger); }
.fridge-status-dots .dot.soon { background: var(--warn); }

.fridge-icons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px 8px;
  font-size: var(--fs-xl);
  max-width: 320px;
}
.fridge-icons-more {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  background: var(--border);
  border-radius: 999px;
  padding: 3px var(--sp-2);
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--sp-3);
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.item-card .icon-row { display: flex; align-items: baseline; gap: 6px; }
.item-card .icon { font-size: var(--fs-xl); }
.item-card .qty { color: var(--text-muted); font-size: var(--fs-2xs); }
.item-card .name { font-weight: 600; font-size: var(--fs-base); }
.item-card .storage-hint { color: var(--text-muted); font-size: var(--fs-2xs); }
.item-card .usage-hint {
  color: var(--brand-dark);
  background: var(--brand-soft);
  font-size: var(--fs-2xs);
  padding: 4px 7px;
  border-radius: 8px;
  line-height: 1.35;
}
.item-card.removing { opacity: 0; transform: scale(0.96); transition: opacity 0.2s ease, transform 0.2s ease; }

.quick-add-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.quick-add-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
}
.quick-add-chip:active { background: var(--brand-soft); border-color: var(--brand); }

.stats-row { display: flex; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.stats-tile {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: var(--sp-4);
  text-align: center;
}
.stats-tile .stats-number { font-size: var(--fs-xl); font-weight: 700; }
.stats-tile .stats-label { color: var(--text-muted); font-size: var(--fs-2xs); margin-top: 2px; }

.wasted-bar-row { margin-bottom: var(--sp-3); }
.wasted-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  margin-bottom: 4px;
}
.wasted-bar-track { background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; }
.wasted-bar-fill { background: var(--danger); height: 100%; border-radius: 999px; }

.photo-preview-row { display: flex; align-items: center; gap: var(--sp-2); margin: 6px 0 4px; min-height: 1.4em; }
.photo-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); flex-shrink: 0; }
.photo-filename { font-size: var(--fs-xs); color: var(--brand-dark); }

.badge {
  display: inline-block;
  font-size: var(--fs-2xs);
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  align-self: flex-start;
}
.badge.fresh { background: var(--brand-soft); color: var(--brand-dark); }
.badge.soon { background: var(--warn-soft); color: var(--warn-text); }
.badge.expired { background: var(--danger-soft); color: var(--danger); }
.badge.unknown { background: var(--border); color: var(--text-muted); }

.badge-row { display: flex; align-items: center; gap: 4px; align-self: flex-start; }

.item-actions { display: flex; gap: 6px; margin-top: 4px; }
.item-actions > * { flex: 1; margin: 0; }
.item-actions .btn { padding: 10px 6px; font-size: var(--fs-2xs); margin-top: 0; min-height: 40px; }

.predicted-tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 4px;
  border: 1px dashed var(--text-muted);
  color: var(--text-muted);
  background: none;
  cursor: pointer;
  font-family: inherit;
}

.section-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  margin: var(--sp-6) 0 var(--sp-2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px var(--sp-4);
}
.empty-state .empty-icon { font-size: 2.6rem; display: block; margin-bottom: var(--sp-2); }

.candidate-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px var(--sp-3);
  margin-bottom: var(--sp-2);
  font-size: 0.95rem;
  color: var(--text);
}
.candidate-list input[type="checkbox"] { width: 18px; height: 18px; }
.candidate-list input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0;
}

.receipt-preview img, .expiry-preview img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 10px 0;
}

.invite-code {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: 0.08em;
  background: var(--accent-warm-soft);
  color: var(--accent-warm-dark);
  padding: var(--sp-3);
  border-radius: 12px;
  text-align: center;
  margin: 10px 0;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }

.toggle-row { display: flex; gap: 10px; margin-bottom: var(--sp-4); }
.toggle-row a {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}
.toggle-row a.active { background: var(--brand); color: var(--brand-contrast); border-color: var(--brand); }

.uploaded-photo { margin: 10px 0; }
.uploaded-photo img { display: block; border-radius: 12px; border: 1px solid var(--border); }
.rotate-form { margin-top: 6px; }

.zoomable { cursor: zoom-in; transition: transform 0.15s ease; }
@media (hover: hover) {
  .zoomable:hover { transform: scale(1.04); }
}

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 10, 0.88);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  cursor: zoom-out;
}
.lightbox-overlay.open { display: flex; }
.lightbox-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* details/summary (재촬영 접기, 제조일자 토글) */
.rescan-toggle summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  padding: var(--sp-2) 0;
  list-style: none;
}
.rescan-toggle summary::-webkit-details-marker { display: none; }
.rescan-toggle summary::before { content: "▸ "; color: var(--text-muted); }
.rescan-toggle[open] summary::before { content: "▾ "; }
.rescan-toggle .rescan-body { padding-top: var(--sp-2); }

.mfg-toggle-link {
  display: inline-block;
  font-size: var(--fs-xs);
  margin-top: var(--sp-1);
}
