/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:      #0f172a;
  --navy2:     #1e293b;
  --blue:      #2563eb;
  --blue-bg:   #eff6ff;
  --green:     #059669;
  --green-bg:  #ecfdf5;
  --amber:     #d97706;
  --amber-bg:  #fffbeb;
  --red:       #dc2626;
  --red-bg:    #fef2f2;
  --bg:        #f1f5f9;
  --border:    #e2e8f0;
  --muted:     #64748b;
  --text:      #0f172a;
  --radius:    16px;
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 2px 8px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Screen system ─────────────────────────────── */
.screen       { display: none; min-height: 100vh; }
.screen.active{ display: block; }

/* ── App Header ────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 100%);
  padding: 24px 20px 28px;
  color: #fff;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 480px;
  margin: 0 auto;
}
.header-icon { font-size: 2.2rem; line-height: 1; flex-shrink: 0; }
.app-header h1 { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; }
.app-header p  { font-size: .75rem; color: rgba(255,255,255,.55); margin-top: 3px; }

/* ── Result Header ─────────────────────────────── */
.result-header {
  background: var(--navy);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn {
  width: 38px; height: 38px;
  background: rgba(255,255,255,.12);
  border: none; color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.back-btn:active { background: rgba(255,255,255,.25); }

/* ── Content ───────────────────────────────────── */
.content {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Card ──────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.badge-auto { font-size: .68rem; font-weight: 500; color: var(--green); text-transform: none; letter-spacing: 0; background: var(--green-bg); padding: 2px 7px; border-radius: 20px; }
.badge-opt  { font-size: .68rem; font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; background: var(--bg); padding: 2px 7px; border-radius: 20px; }

/* ── Step badge ────────────────────────────────── */
.step-badge {
  width: 22px; height: 22px;
  background: var(--blue); color: #fff;
  border-radius: 50%;
  font-size: .72rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step-gray { background: var(--muted); }

/* ── Text field ────────────────────────────────── */
.field {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, background .15s;
  -webkit-appearance: none;
}
.field:focus { outline: none; border-color: var(--blue); background: #fff; }

/* ── JAN row ───────────────────────────────────── */
.jan-row { display: flex; gap: 8px; }
.jan-row .field {
  flex: 1;
  font-size: 1.05rem;
  letter-spacing: .06em;
}
.camera-btn {
  flex-shrink: 0;
  width: 54px; height: 54px;
  background: var(--navy);
  color: #fff;
  border: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: opacity .15s;
}
.camera-btn:active { opacity: .75; }

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: flex;
  align-items: center; justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  border: none;
  font-size: .95rem; font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:active { opacity: .82; transform: scale(.98); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-outline  { background: #fff; color: var(--navy2); border: 1.5px solid var(--border); padding: 12px; font-size: .88rem; }

/* ── Photo preview ─────────────────────────────── */
.photo-row { display: flex; align-items: center; gap: 12px; }
#photo-preview {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.retake-btn {
  font-size: .8rem; color: var(--blue);
  background: var(--blue-bg); border: none;
  padding: 8px 14px; border-radius: 20px;
  cursor: pointer; font-weight: 600;
}

/* ── Divider ───────────────────────────────────── */
.or-divider {
  text-align: center;
  position: relative;
}
.or-divider::before, .or-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}
.or-divider::before { left: 0; }
.or-divider::after  { right: 0; }
.or-divider span {
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  padding: 0 8px;
  position: relative;
}

/* ── Scanner overlay ───────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: var(--navy);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.overlay-top {
  padding: 16px 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.overlay-close {
  align-self: flex-end;
  background: rgba(255,255,255,.14); color: #fff;
  border: none; border-radius: 20px;
  padding: 8px 18px; font-size: .88rem; font-weight: 600;
  cursor: pointer;
}
.overlay-hint { font-size: .8rem; color: rgba(255,255,255,.55); }
#reader { flex: 1; }

/* ── Loading ───────────────────────────────────── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.loading-box {
  background: #fff; border-radius: var(--radius);
  padding: 30px 44px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  font-size: .88rem; color: var(--muted);
}
.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Product card ──────────────────────────────── */
.product-row { display: flex; gap: 14px; align-items: flex-start; }
.thumb {
  width: 84px; height: 84px;
  object-fit: cover; border-radius: 12px;
  border: 1px solid var(--border); flex-shrink: 0;
}
.pinfo { flex: 1; min-width: 0; }
.pname {
  font-size: .88rem; font-weight: 500; line-height: 1.45;
  color: #334155; margin-bottom: 10px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.price-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.price { font-size: 1.75rem; font-weight: 800; color: var(--red); letter-spacing: -.03em; }
.sbadge {
  font-size: .7rem; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
}
.sbadge.free { background: var(--green-bg); color: var(--green); }
.sbadge.paid { background: var(--amber-bg); color: var(--amber); }
.ylink {
  font-size: .78rem; color: var(--blue);
  display: inline-flex; align-items: center; gap: 3px;
}
.alert-note {
  font-size: .75rem; color: var(--amber);
  background: var(--amber-bg); padding: 9px 12px;
  border-radius: 10px; margin-top: 4px;
}

/* ── Size tabs ─────────────────────────────────── */
.size-tabs {
  display: flex; gap: 8px;
  flex-wrap: wrap;
  padding: 3px 2px 5px;
}
.size-tab {
  flex-shrink: 0; min-width: 58px;
  padding: 13px 6px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 1rem; font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  color: var(--navy2);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.size-tab.active {
  background: var(--blue); border-color: var(--blue); color: #fff;
  box-shadow: 0 3px 10px rgba(37,99,235,.3);
}
.size-hint { font-size: .72rem; color: var(--muted); line-height: 1.5; }

/* ── Discount ──────────────────────────────────── */
.discount-block { display: flex; flex-direction: column; gap: 8px; }
.discount-head  { font-size: .78rem; font-weight: 700; color: var(--muted); }
.radio-group    { display: flex; gap: 6px; flex-wrap: wrap; }

.radio-pill, .check-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 13px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 10px; cursor: pointer;
  font-size: .82rem; font-weight: 500;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.radio-pill:has(input:checked),
.check-pill:has(input:checked) {
  background: var(--blue-bg); border-color: var(--blue); color: var(--blue);
}
.radio-pill input, .check-pill input { accent-color: var(--blue); }
.check-pill { width: 100%; }
.radio-pill b, .check-pill b { font-weight: 800; }

/* ── Zone row (発送元 → 発送先) ──────────────────── */
.zone-row {
  display: flex; align-items: flex-end; gap: 8px;
}
.zone-col { flex: 1; }
.zone-sublabel {
  font-size: .75rem; color: var(--muted);
  margin-bottom: 4px; padding-left: 2px;
}
.zone-arrow {
  font-size: 1.2rem; color: var(--muted);
  padding-bottom: 14px; flex-shrink: 0;
}
@media (max-width: 400px) {
  .zone-row { flex-direction: column; gap: 10px; }
  .zone-arrow { display: none; }
}

/* ── Select ────────────────────────────────────── */
.select {
  width: 100%; padding: 13px 14px;
  font-size: .95rem;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
  cursor: pointer; -webkit-appearance: none;
}

/* ── Calculation ───────────────────────────────── */
.calc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; font-size: .9rem;
}
.calc-row > span:first-child { color: var(--muted); }
.calc-row.minus > span:last-child { color: var(--red); }
.calc-row.green > span:last-child { color: var(--green); font-weight: 700; }
.calc-divider { border-top: 2px solid var(--border); margin: 6px 0; }
.calc-row.total > span:first-child { font-weight: 700; color: var(--navy2); font-size: .95rem; }
.breakeven { font-size: 1.6rem; font-weight: 900; color: var(--blue); letter-spacing: -.03em; }

/* ── Purchase price ────────────────────────────── */
.yen-wrap {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 4px 16px 4px 14px;
  transition: border-color .15s;
}
.yen-wrap:focus-within { border-color: var(--blue); background: #fff; }
.yen-sign { font-size: 1.15rem; font-weight: 700; color: var(--muted); }
.yen-input {
  flex: 1; border: none; background: transparent; padding: 10px 0;
  font-size: 1.4rem; font-weight: 800; color: var(--text); letter-spacing: -.02em;
}
.yen-input:focus { outline: none; }

/* ── Verdict ───────────────────────────────────── */
.verdict-card {
  border-radius: var(--radius); padding: 22px 20px;
  text-align: center; box-shadow: var(--shadow);
}
.verdict-card.ok   { background: var(--green-bg); }
.verdict-card.warn { background: var(--amber-bg); }
.verdict-card.ng   { background: var(--red-bg); }
.verdict-label  { font-size: 1.15rem; font-weight: 800; margin-bottom: 8px; }
.verdict-amount {
  font-size: 2rem; font-weight: 900; letter-spacing: -.03em; margin-bottom: 4px;
}
.verdict-amount.pos { color: var(--green); }
.verdict-amount.neg { color: var(--red); }
.verdict-margin { font-size: .82rem; color: var(--muted); }

/* ── History button (input header) ─────────────── */
.header-text { flex: 1; }
.history-btn {
  background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 42px; height: 42px; border-radius: 12px;
  font-size: 1.2rem; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.history-btn:active { background: rgba(255,255,255,.28); }

/* ── Clear button (history header) ─────────────── */
.clear-btn {
  background: rgba(220,38,38,.15); color: #fca5a5;
  border: none; border-radius: 20px;
  padding: 6px 14px; font-size: .78rem; font-weight: 600;
  cursor: pointer;
}
.clear-btn:active { background: rgba(220,38,38,.3); }

/* ── Memo field ─────────────────────────────────── */
.memo-field {
  width: 100%; padding: 12px 14px;
  font-size: .9rem; line-height: 1.5;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text);
  resize: none; font-family: inherit;
  transition: border-color .15s, background .15s;
}
.memo-field:focus { outline: none; border-color: var(--blue); background: #fff; }

/* ── Save message ───────────────────────────────── */
.save-msg {
  text-align: center; font-size: .88rem; font-weight: 600;
  color: var(--green); padding: 2px 0;
}

/* ── History list ───────────────────────────────── */
.empty-msg {
  text-align: center; color: var(--muted);
  font-size: .88rem; padding: 48px 0;
}
.hist-card {
  background: #fff; border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.hist-head { display: flex; justify-content: space-between; align-items: center; }
.hist-date { font-size: .72rem; color: var(--muted); font-weight: 600; }
.hist-head-actions { display: flex; align-items: center; gap: 8px; }
.hist-open {
  background: var(--blue-bg); color: var(--blue);
  border: none; border-radius: 20px;
  padding: 5px 12px; font-size: .75rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.hist-open:active { opacity: .75; }
.hist-del {
  background: var(--bg); border: none; color: var(--muted);
  font-size: .75rem; width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.hist-del:active { background: var(--red-bg); color: var(--red); }
.hist-name {
  font-size: .85rem; font-weight: 600; line-height: 1.4; color: var(--navy2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.hist-jan { font-size: .7rem; color: var(--muted); letter-spacing: .04em; }
.hist-row {
  display: flex; justify-content: space-between; font-size: .82rem; padding: 2px 0;
}
.hist-row > span:first-child { color: var(--muted); }
.hist-row.accent > span:last-child { color: var(--blue); font-weight: 700; }
.hist-row.breakeven-row > span:first-child { font-weight: 700; color: var(--navy2); }
.hist-row.breakeven-row > span:last-child { font-size: 1.05rem; font-weight: 900; color: var(--blue); }
.hist-meta { font-size: .7rem; color: var(--muted); }
.hist-memo-wrap { margin-top: 2px; }
.hist-memo-display {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  background: var(--bg); border-radius: 8px; padding: 8px 10px;
}
.hist-memo-text { font-size: .8rem; color: var(--navy2); line-height: 1.5; flex: 1; white-space: pre-wrap; }
.hist-memo-empty { font-style: normal; color: var(--muted); }
.hist-memo-edit {
  background: none; border: none; cursor: pointer;
  font-size: .9rem; padding: 0 2px; flex-shrink: 0; opacity: .6;
}
.hist-memo-edit:active { opacity: 1; }
.hist-memo-textarea {
  width: 100%; padding: 10px 12px;
  font-size: .85rem; line-height: 1.5;
  border: 1.5px solid var(--blue); border-radius: 10px;
  background: #fff; color: var(--text);
  resize: none; font-family: inherit;
}
.hist-memo-textarea:focus { outline: none; }
.hist-memo-actions { display: flex; gap: 8px; margin-top: 6px; }
.hist-memo-save {
  flex: 1; padding: 9px; border: none; border-radius: 10px;
  background: var(--blue); color: #fff;
  font-size: .85rem; font-weight: 700; cursor: pointer;
}
.hist-memo-cancel {
  flex: 1; padding: 9px; border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--muted);
  font-size: .85rem; font-weight: 600; cursor: pointer;
}

/* ── Utility ───────────────────────────────────── */
.hidden { display: none !important; }

/* ── アカウント設定パネル ────────────────────────── */
.account-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
}
.account-drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(360px, 100vw);
  background: var(--navy2);
  border-left: 1px solid rgba(255,255,255,.1);
  box-shadow: -6px 0 32px rgba(0,0,0,.4);
  z-index: 201;
  overflow-y: auto;
  padding: 0 0 40px;
  color: #fff;
}
.account-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-size: .95rem;
  font-weight: 700;
  position: sticky; top: 0;
  background: var(--navy2);
}
.account-close-btn {
  background: rgba(255,255,255,.1); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: .9rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.account-close-btn:active { background: rgba(255,255,255,.2); }
.account-section {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.account-section:last-child { border-bottom: none; }
.account-section-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.4);
  margin-bottom: 14px;
}
.account-info-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: .85rem;
}
.account-info-key { color: rgba(255,255,255,.5); }
.account-info-val { font-family: monospace; color: #e2e8f0; font-weight: 600; word-break: break-all; }
.account-field { margin-bottom: 12px; }
.account-field label {
  display: block;
  font-size: .72rem;
  color: rgba(255,255,255,.5);
  margin-bottom: 5px;
  font-weight: 600;
}
.account-field input {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
.account-field input:focus { border-color: var(--blue); }
.account-btn {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 11px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.account-btn:hover { opacity: .88; }
.account-error {
  font-size: .78rem;
  color: #fca5a5;
  margin-top: 6px;
}
.account-ok {
  font-size: .78rem;
  color: #6ee7b7;
  margin-top: 6px;
}
