:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-soft: #ecfdf5;
  --bg: #f3f6f5;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e2e8e6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --safe: #047857;
  --safe-soft: #ecfdf5;
  --shadow: 0 6px 22px rgba(15, 23, 42, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  line-height: 1.5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(16, 185, 129, .35);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.app-shell {
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(16, 185, 129, .3);
}

.brand h1 { margin: 0; font-size: 17px; letter-spacing: .02em; }
.brand p { margin: 0; font-size: 11px; color: var(--muted); }

.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
}
.icon-btn:hover { color: var(--primary-dark); border-color: var(--primary); }

/* ---------- inventory ---------- */
.app-main { flex: 1; padding: 16px 16px 120px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: #e7edeb;
  border-radius: 14px;
}

.tab {
  border: 0;
  border-radius: 10px;
  padding: 9px 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.tab.is-active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 1px 4px rgba(15, 23, 42, .1);
}

.list-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 2px 10px;
}
.list-heading h2 { margin: 0; font-size: 15px; }
.count { font-size: 12px; color: var(--muted); }

.item-list { display: flex; flex-direction: column; gap: 10px; }

.item-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .04);
}
.item-card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
.item-name {
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 12px;
  color: var(--muted);
}
.item-quantity:not(:empty)::before { content: "・"; color: var(--border); }

.item-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.item-expiry { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-expired { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-safe { background: var(--safe-soft); color: var(--safe); }

.empty-state {
  margin-top: 48px;
  text-align: center;
  color: var(--muted);
}
.empty-icon { font-size: 46px; }
.empty-state p { margin: 8px 0; font-size: 14px; }
#empty-title { color: var(--text); font-weight: 600; font-size: 16px; }
#empty-detail { font-size: 12px; }

/* ---------- action bar ---------- */
.action-bar {
  position: fixed;
  z-index: 6;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, rgba(243, 246, 245, 0));
}

.fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(15, 23, 42, .16);
}
.fab-main {
  flex: 1;
  max-width: 320px;
  min-height: 54px;
  padding: 0 20px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
}
.fab-main:active { transform: translateY(1px); background: var(--primary-dark); }
.fab-sub {
  width: 52px;
  height: 52px;
  background: var(--surface);
  color: var(--primary-dark);
  border: 1px solid var(--border);
}

/* ---------- overlays & sheets ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(15, 23, 42, .52);
  padding: 0;
}
.sheet {
  width: min(100%, 560px);
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  animation: slide-up .18s ease-out;
}
.sheet-wide { max-height: 92dvh; }
.sheet h2 { margin: 0 0 6px; font-size: 18px; }
.sheet h3 { margin: 0 0 6px; font-size: 14px; }
.sheet-lead { margin: 0 0 16px; font-size: 13px; color: var(--muted); }
@keyframes slide-up { from { transform: translateY(16px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.menu-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.menu-btn.is-ghost { text-align: center; color: var(--muted); background: transparent; }

.loading-box {
  margin-bottom: 60px;
  padding: 26px 30px;
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
}
.loading-box p { margin: 14px 0 4px; font-weight: 600; font-size: 15px; }
.loading-box small { color: var(--muted); }
.spinner {
  width: 38px;
  height: 38px;
  margin: 0 auto;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.field {
  display: block;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.field input, .field select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  min-height: 44px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { margin: 0 0 10px; font-size: 13px; color: var(--danger); }

.btn {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.btn.is-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.is-danger { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.btn.is-ghost { background: transparent; color: var(--muted); }
.spacer { flex: 1; }
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.inline-actions { display: flex; gap: 8px; }

/* ---------- analysis results ---------- */
.result-list { display: flex; flex-direction: column; gap: 12px; }
.result-row {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8faf9;
}
.row-top { display: flex; align-items: flex-end; gap: 8px; }
.row-name { flex: 1; }
.row-remove {
  flex: 0 0 auto;
  width: 42px;
  height: 44px;
  margin-bottom: 12px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 22px;
  line-height: 1;
}

/* ---------- settings ---------- */
.settings-section {
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8faf9;
}
.guide { margin: 8px 0 12px; padding-left: 20px; font-size: 13px; }
.guide li { margin-bottom: 6px; }
.hint { margin: 6px 0 12px; font-size: 12px; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  z-index: 40;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(90vw, 460px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(17, 24, 39, .94);
  color: #fff;
  font-size: 13px;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (min-width: 600px) {
  .overlay { align-items: center; padding: 20px; }
  .sheet, .sheet-wide { border-radius: 20px; padding-bottom: 24px; }
  .loading-box { margin-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
