:root {
  color-scheme: light;
  --bg: #f2f7f6;
  --surface: #ffffff;
  --ink: #16302c;
  --muted: #607570;
  --line: #d7e5e1;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --safe: #16794a;
  --warn: #9a5b00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(26, 63, 56, 0.09);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #e8f4f1 0, var(--bg) 220px);
  color: var(--ink);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: calc(18px + env(safe-area-inset-top)) 18px 16px;
  max-width: 760px;
  margin: 0 auto;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 5vw, 1.8rem); line-height: 1.2; }
h2 { margin-bottom: 12px; font-size: 1.15rem; }
.eyebrow, .step-label { margin-bottom: 4px; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .08em; }

.header-badges { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.badge, .state-label {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.85);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 750;
  white-space: nowrap;
}
.badge-safe { border-color: #b9dfca; color: var(--safe); background: #edfbf3; }
.badge.offline { color: var(--warn); border-color: #ecd5a9; background: #fff8e8; }

main { max-width: 760px; margin: 0 auto; padding: 0 14px calc(40px + env(safe-area-inset-bottom)); }

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 6px;
  margin-bottom: 12px;
  border: 1px solid rgba(215,229,225,.9);
  border-radius: 16px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 18px rgba(26,63,56,.06);
}
.tab { min-height: 43px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 750; }
.tab.active { background: var(--primary); color: white; }

.view { display: none; }
.view.active { display: block; }
.card {
  margin-bottom: 13px;
  padding: 17px;
  border: 1px solid rgba(215,229,225,.95);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.section-heading { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

.reader {
  min-height: 190px;
  overflow: hidden;
  margin: 8px 0 13px;
  border: 2px dashed #bdd5d0;
  border-radius: 16px;
  background: #eaf2f0;
}
.reader:empty::before {
  content: "カメラ開始後、バーコードを横長の枠へ合わせてください";
  display: grid;
  place-items: center;
  min-height: 190px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
  font-size: .9rem;
}
#reader video { border-radius: 14px; }

.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.button-stack { display: grid; gap: 9px; }
.button {
  min-height: 47px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 780;
  cursor: pointer;
}
.button:disabled { cursor: default; opacity: .45; }
.button.primary { background: var(--primary); color: white; }
.button.primary:active { background: var(--primary-dark); }
.button.secondary { border-color: var(--line); background: #f7faf9; color: var(--ink); }
.button.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.button.full { width: 100%; margin-top: 14px; }
.button.compact { min-height: 36px; padding: 6px 10px; font-size: .8rem; }
.file-button { position: relative; display: grid; place-items: center; text-align: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.manual-form { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.manual-form label, .provisional-form label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .85rem; font-weight: 700; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
input {
  width: 100%;
  min-height: 47px;
  padding: 10px 12px;
  border: 1px solid #bed1cd;
  border-radius: 11px;
  background: white;
  color: var(--ink);
}
input:focus { outline: 3px solid rgba(15,118,110,.16); border-color: var(--primary); }

.notice { margin-bottom: 12px; padding: 12px 14px; border: 1px solid #f0d49b; border-radius: 13px; background: #fff9ea; color: #714500; }
.notice.error { border-color: #efc0bb; background: #fff1ef; color: var(--danger); }
.notice.success { border-color: #b8e0c7; background: #eefaf3; color: var(--safe); }
.muted { color: var(--muted); line-height: 1.6; }

.product-title { margin-bottom: 6px; font-size: 1.22rem; }
.jan-line { color: var(--muted); font-size: .86rem; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 13px; }
.result-grid div, .stats div { padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #f8fbfa; }
.result-grid dt, .stats dt { margin-bottom: 4px; color: var(--muted); font-size: .72rem; }
.result-grid dd, .stats dd { margin: 0; font-weight: 760; overflow-wrap: anywhere; }

.unknown-card { border-color: #ead5aa; }
.provisional-form { display: grid; gap: 10px; margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.provisional-form label { margin-bottom: 0; }
.provisional-form input { margin-top: 5px; }

.pending-list { display: grid; gap: 10px; }
.pending-empty { padding: 28px 10px; color: var(--muted); text-align: center; }
.pending-item { padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: #f9fbfa; }
.pending-item h3 { margin: 0 0 5px; font-size: 1rem; }
.pending-item p { margin-bottom: 5px; color: var(--muted); font-size: .82rem; }
.pending-thumb { display: block; max-width: 110px; max-height: 90px; margin-top: 8px; border-radius: 8px; }
.pending-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 9px; }
.pending-actions a, .pending-actions button { min-height: 35px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 9px; background: white; color: var(--primary); font: inherit; font-size: .78rem; font-weight: 700; text-decoration: none; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 13px 0; }
.safety-card { border-color: #bde0ca; background: linear-gradient(145deg, #fff, #f1fbf5); }

.dialog-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; background: rgba(9,33,29,.62); }
.dialog-backdrop[hidden] { display: none; }
.dialog { width: min(100%, 430px); padding: 20px; border-radius: 18px; background: white; box-shadow: 0 25px 70px rgba(0,0,0,.24); }

@media (max-width: 460px) {
  .app-header { align-items: stretch; flex-direction: column; }
  .header-badges { flex-direction: row; align-items: center; }
  .button-grid { grid-template-columns: 1fr; }
  .result-grid, .stats { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
