:root {
  --accent: #0e7490;
  --accent-light: #e0f2fe;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --expired-bg: #fee2e2;
  --expired-text: #991b1b;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 90px;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  color: #fff;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { margin: 0 0 8px; font-size: 1.3rem; }
.icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}
#search {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
}
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-top: 8px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.82rem;
  cursor: pointer;
}
.chip.active {
  background: #fff;
  color: var(--accent);
  border-color: #fff;
  font-weight: 600;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 0;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }

/* ---------- items ---------- */
.item-list { padding: 12px 12px 0; display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
}
.thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 10px;
  object-fit: cover;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}
.card-body { flex: 1; min-width: 0; }
.card-title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-sub { color: var(--muted); font-size: 0.82rem; margin: 0; }
.card-badges { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-light);
  color: var(--accent);
}
.pill.warn { background: var(--warn-bg); color: var(--warn-text); }
.pill.expired { background: var(--expired-bg); color: var(--expired-text); }

.status-btn {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 56px;
  height: 52px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.status-btn small { font-size: 0.6rem; color: var(--muted); font-weight: 600; }

.pill.thaw { background: #dbeafe; color: #1d4ed8; }
.pill.ok { background: #dcfce7; color: #166534; }

.status-options { display: flex; flex-direction: column; gap: 8px; }
.status-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.status-option.current { border-color: var(--accent); background: var(--accent-light); }
.status-emoji { font-size: 1.2rem; }
.status-note { margin-left: auto; font-size: 0.72rem; font-weight: 400; color: var(--muted); }

.empty { text-align: center; color: var(--muted); margin-top: 48px; padding: 0 24px; }

/* ---------- fab ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(14, 116, 144, 0.4);
  z-index: 15;
}

/* ---------- sheets ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 20;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  z-index: 21;
}
.sheet h2 { margin: 0 0 14px; font-size: 1.15rem; }
.sheet form { display: flex; flex-direction: column; gap: 12px; }
.sheet label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; font-weight: 600; }
.hint { color: var(--muted); font-weight: 400; }
.sheet input:not([type="file"]), .sheet select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.photo-row { display: flex; align-items: center; gap: 12px; }
#f-photo-preview {
  width: 84px;
  height: 84px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.photo-btns { display: flex; gap: 8px; }

.btn {
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--expired-bg); color: var(--danger); }

.sheet-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }

/* ---------- barcode scanner ---------- */
#scan-overlay[hidden] { display: none; }
#scan-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}
#scan-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-hint {
  position: relative;
  color: #fff;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  margin: 0;
}
#scan-cancel { position: relative; }

/* ---------- freezer manager ---------- */
.loc-list { list-style: none; margin: 0 0 12px; padding: 0; }
.loc-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.loc-count { color: var(--muted); font-size: 0.8rem; margin-left: 8px; }
.loc-del {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
}
.loc-add { display: flex; gap: 8px; }
.loc-add input { flex: 1; }

/* ---------- reminder setting ---------- */
.settings-h2 { margin-top: 20px; }
.reminder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.reminder-row input.app-name-input {
  flex: 1;
  width: auto;
  text-align: left;
}
.reminder-row input {
  width: 64px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  text-align: center;
}
