/* =========================================================
   在庫管理 — style.css
   - カラートークン（ライト／ダーク）
   - アプリシェル（100dvh・リストだけスクロール）
   - <dialog> / popover のトップレイヤーアニメーション
   - View Transitions（タブ切り替え・カレンダー月移動）
   ========================================================= */

/* ---------- color tokens ---------- */
:root {
  color-scheme: light dark;

  --bg: #f2f6f5;
  --surface: #ffffff;
  --surface-2: #eaf2f0;
  --text: #1f2937;
  --muted: #5b6573;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --on-primary: #ffffff;
  --primary-ink: #0f766e;      /* 文字色として使うティール */
  --primary-soft: #ccfbf1;
  --accent: #2563eb;
  --danger: #dc2626;
  --danger-ink: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-line: #fca5a5;
  --warn: #f59e0b;
  --warn-ink: #92400e;
  --warn-bg: #fffbeb;
  --warn-line: #fcd34d;
  --todo-border: #f59e0b;
  --todo-bg: #fef3c7;
  --secondary-bg: #e3f3f0;
  --secondary-line: #9fd4cb;
  --secondary-ink: #134e4a;
  --border: #dfe7e5;
  --border-strong: #87918f;    /* 入力欄の枠：背景と 3:1 以上 */
  --chip-active-bg: #1f2937;
  --chip-active-ink: #ffffff;
  --badge-opened-bg: #e0e7ff;
  --badge-opened-ink: #3730a3;
  --ev-past-bg: #fee2e2;  --ev-past-ink: #991b1b;
  --ev-soon-bg: #fef3c7;  --ev-soon-ink: #92400e;
  --ev-ok-bg: #ccfbf1;    --ev-ok-ink: #115e59;
  --ev-frozen-bg: #e0f2fe; --ev-frozen-ink: #075985;
  --cal-selected: #ecfdf5;
  --header-bg: color-mix(in oklab, var(--bg) 88%, transparent);
  --backdrop: rgb(15 23 42 / 0.5);
  --shadow-1: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.07);
  --shadow-2: 0 10px 30px rgb(16 24 40 / 0.14), 0 2px 6px rgb(16 24 40 / 0.08);
  --focus: #2563eb;

  --radius: 14px;
  --radius-sm: 10px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);

  accent-color: var(--primary);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1615;
    --surface: #17211f;
    --surface-2: #1e2b29;
    --text: #e8eeed;
    --muted: #a3b2af;
    --primary: #0f766e;
    --primary-strong: #0d9488;
    --primary-ink: #5eead4;
    --primary-soft: #134e4a;
    --danger: #dc2626;
    --danger-ink: #fca5a5;
    --danger-soft: #3b1414;
    --danger-line: #7f1d1d;
    --warn-ink: #fcd34d;
    --warn-bg: #33270a;
    --warn-line: #78590f;
    --todo-bg: #3b2a06;
    --secondary-bg: #16302d;
    --secondary-line: #2b5b55;
    --secondary-ink: #99f6e4;
    --border: #2a3836;
    --border-strong: #667774;
    --chip-active-bg: #e8eeed;
    --chip-active-ink: #0e1615;
    --badge-opened-bg: #312e81;
    --badge-opened-ink: #e0e7ff;
    --ev-past-bg: #4c1414;  --ev-past-ink: #fecaca;
    --ev-soon-bg: #45330a;  --ev-soon-ink: #fde68a;
    --ev-ok-bg: #134e4a;    --ev-ok-ink: #99f6e4;
    --ev-frozen-bg: #0c3b52; --ev-frozen-ink: #bae6fd;
    --cal-selected: #134e4a;
    --backdrop: rgb(0 0 0 / 0.62);
    --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-2: 0 10px 30px rgb(0 0 0 / 0.5);
    --focus: #60a5fa;
    accent-color: #14b8a6;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3 { line-height: 1.3; text-wrap: balance; }
p { text-wrap: pretty; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; max-width: 100%; min-width: 0; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
a { color: var(--primary-ink); }
img { max-width: 100%; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-block-size: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  transition: background-color .15s, border-color .15s, transform .1s, box-shadow .15s;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 1px 0 rgb(255 255 255 / .12) inset, var(--shadow-1); }
.btn-primary:active:not(:disabled) { background: var(--primary-strong); }
@media (hover: hover) { .btn-primary:hover:not(:disabled) { background: var(--primary-strong); } }
.btn-secondary { background: var(--secondary-bg); border-color: var(--secondary-line); color: var(--secondary-ink); }
.btn-ghost { background: transparent; }
.btn-ghost-light { background: rgb(255 255 255 / .15); color: #fff; border-color: rgb(255 255 255 / .4); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { min-block-size: 36px; padding: 6px 11px; font-size: 13px; }
.btn-block { display: flex; width: 100%; margin-top: 10px; }
.btn-large { min-block-size: 52px; font-size: 16px; }
.btn-google { background: #fff; color: #1f2937; border: 1px solid var(--border-strong); }
.google-icon { width: 18px; height: 18px; flex: none; }

/* ---------- auth ---------- */
.auth-view {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in oklab, var(--primary) 16%, transparent), transparent 70%),
    var(--bg);
}
.auth-card {
  background: var(--surface); border-radius: 22px; padding: 28px 22px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow-2); text-align: center; border: 1px solid var(--border);
}
.auth-logo { font-size: 52px; line-height: 1; }
.auth-card h1 { font-size: 22px; margin: 10px 0 4px; }
.auth-sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.auth-form, .auth-subform { text-align: left; display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 4px; }
.auth-field label { font-size: 13px; color: var(--muted); }
.auth-divider { display: flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.code-input { text-transform: uppercase; letter-spacing: .08em; }
.warn-box { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: var(--radius-sm); padding: 10px; font-size: 13px; margin-bottom: 14px; text-align: left; }
.error-text { color: var(--danger-ink); font-size: 13px; margin: 4px 0; }
.error-text::before { content: "⚠️ "; content: "⚠️ " / ""; }
.info-text { color: var(--primary-ink); font-size: 13px; margin: 4px 0; }

/* ---------- text inputs ---------- */
.auth-field input,
.field input:not([type="checkbox"], [type="radio"], [type="file"]),
.field select,
.expiry-inputs input,
.todo-manual input,
.scan-manual input,
.search-row input,
.picker-qty {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: max(16px, 1em); /* iOS のズーム防止 */
  min-block-size: 44px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.field select, .sort-row select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
input::placeholder { color: color-mix(in oklab, var(--muted) 80%, transparent); }
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

/* 入力後・送信後だけエラー表示（:user-invalid） */
:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger);
  background-color: var(--danger-soft);
}
.field-error { display: none; color: var(--danger-ink); font-size: 13px; margin: 2px 0 0; }
:is(input, select, textarea):is(:user-invalid, .user-invalid-fallback) + .field-error { display: block; }
input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- app shell ---------- */
.app-shell { display: flex; flex-direction: column; height: 100dvh; }
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px 4px; max-width: 640px; margin: 0 auto; width: 100%; flex: none;
}
.app-header h1 { font-size: 19px; margin: 0; letter-spacing: .01em; }
.header-actions { display: flex; gap: 2px; }
.icon-btn {
  inline-size: 44px; block-size: 44px; border-radius: 12px; border: 0;
  background: transparent; font-size: 18px; display: grid; place-items: center; padding: 0;
  transition: background-color .15s;
}
.icon-btn:active { background: var(--surface-2); }
@media (hover: hover) { .icon-btn:hover { background: var(--surface-2); } }

.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 6px auto 4px;
  max-width: calc(640px - 32px); width: calc(100% - 32px); flex: none;
  background: var(--surface-2); border-radius: 999px; border: 1px solid var(--border);
}
.tab {
  flex: 1; min-block-size: 38px; padding: 8px 2px; border-radius: 999px; border: 0;
  background: transparent; font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--muted);
  transition: background-color .2s, color .2s, box-shadow .2s;
}
.tab.active, .tab[aria-current="page"] { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }

.view {
  max-width: 640px; margin: 0 auto; padding: 4px 16px 0; width: 100%;
  flex: 1; min-height: 0; display: flex; flex-direction: column;
}
/* リスト部分だけがスクロールする（画面全体はスクロールしない） */
.scroll-area {
  flex: 1; min-height: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  scrollbar-width: thin;
}
#inventoryList { padding-bottom: 12px; }
#calDayList { padding-bottom: 16px; }
#todoList, #pickerList { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
#locationFilters, .attention-row, .sort-row, .search-row, .category-tabs, .todo-actions, .todo-manual,
.cal-head, .cal-week, .cal-grid, .cal-day-title, .cal-legend, .recipe-head, .fab-row { flex: none; }

.fab-row {
  display: flex; gap: 8px;
  margin: 0 -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--bg) 92%, transparent);
  border-top: 1px solid var(--border);
}
.fab-main { flex: 1.4; }
.fab-row .btn { flex: 1; min-block-size: 50px; padding: 12px 8px; font-size: 15px; border-radius: 14px; }

/* ---------- filters ---------- */
.search-row { display: flex; align-items: center; gap: 6px; padding: 2px 0 8px; }
.search-row input { border-radius: 999px; padding: 9px 16px; min-block-size: 42px; }
.chip-row {
  display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 -2px;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.attention-row { padding-bottom: 4px; }
.chip {
  white-space: nowrap; min-block-size: 34px; padding: 6px 13px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text);
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip.active { background: var(--chip-active-bg); color: var(--chip-active-ink); border-color: var(--chip-active-bg); }
.chip.att-danger { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger-ink); font-weight: 700; }
.chip.att-warn { border-color: var(--todo-border); background: var(--warn-bg); color: var(--warn-ink); font-weight: 700; }
.chip.att-danger.active { background: var(--danger); border-color: var(--danger); color: #fff; }
.chip.att-warn.active { background: var(--todo-border); border-color: var(--todo-border); color: #1f2937; }
.chip.active::before, .chip[aria-pressed="true"]::before { content: "✓ "; content: "✓ " / ""; }

.sort-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 0 8px; font-size: 13px; color: var(--muted); }
.sort-row select {
  appearance: none; -webkit-appearance: none;
  min-block-size: 36px; padding: 6px 30px 6px 12px; border: 1px solid var(--border-strong); border-radius: 999px;
  background-color: var(--surface); color: var(--text); font-size: 13px;
}
.group-check { display: flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; min-block-size: 36px; }
.group-check input { width: 18px; height: 18px; }
.sort-select-wrap { display: flex; align-items: center; gap: 8px; }

/* ---------- segment ---------- */
.segment {
  display: flex; gap: 3px; padding: 3px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
}
.segment-btn {
  position: relative; flex: 1; display: flex; align-items: center; justify-content: center;
  min-block-size: 40px; padding: 8px 6px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background-color .15s, color .15s, box-shadow .15s;
}
.segment-btn input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segment-btn.active,
.segment-btn[aria-pressed="true"],
.segment-btn:has(input:checked) { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
.segment-btn:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 1px; }
.category-tabs { margin: 2px 0 8px; }
.category-tabs .segment-btn { min-block-size: 36px; padding: 6px 4px; font-size: 14px; }

/* ---------- cards ---------- */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow-1);
}
/* 画面外のカードは描画を後回しにする（最初の1画面分には付けない） */
.card-list > .card:nth-child(n + 8) {
  content-visibility: auto;
  contain-intrinsic-size: auto none auto 132px;
}
.card.todo-highlight { background: var(--todo-bg); border: 2px solid var(--todo-border); }
.card-main { display: flex; gap: 12px; align-items: flex-start; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-weight: 700; font-size: 16px; word-break: break-word; line-height: 1.35; }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.expiry { font-size: 14px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.expiry.expired { color: var(--danger-ink); font-weight: 700; }
.expiry.expired::before { content: "⚠️ "; content: "⚠️ " / ""; }
.expiry.soon { color: var(--warn-ink); font-weight: 700; }
.expiry.soon::before { content: "⏰ "; content: "⏰ " / ""; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 6px; padding: 2px 6px; vertical-align: middle; line-height: 1.4; }
.badge-todo { background: var(--todo-border); color: #1f2937; }
.badge-opened { background: var(--badge-opened-bg); color: var(--badge-opened-ink); }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.qty-ctrl {
  display: inline-flex; align-items: center; gap: 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); padding: 2px;
}
.qty-ctrl button {
  width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent;
  font-size: 18px; color: var(--text); display: grid; place-items: center;
}
.qty-ctrl button:active { background: var(--surface); }
.qty-ctrl span { min-width: 30px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.empty-text { color: var(--muted); text-align: center; padding: 28px 0; }
.empty-text::before { content: "🦓"; content: "🦓" / ""; display: block; font-size: 32px; margin-bottom: 4px; }
.group-head {
  position: sticky; top: 0; z-index: 2; margin: 0 0 -4px; padding: 8px 2px 4px;
  background: var(--bg); font-weight: 800; font-size: 14px;
}

.thumb {
  width: 48px; height: 48px; border-radius: 12px; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; padding: 0; overflow: hidden;
}
.thumb > img { width: 100%; height: 100%; object-fit: cover; border: 0; display: block; }
.thumb-large { width: 76px; height: 76px; font-size: 32px; border-radius: 14px; }
button.thumb { cursor: zoom-in; }
div.thumb { cursor: default; }

/* 残量バー */
.remain-wrap { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.remain-bar { flex: 0 0 90px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.remain-bar > div { height: 100%; background: #0d9488; border-radius: 3px; }

/* ---------- todo ---------- */
.todo-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.todo-manual { display: flex; gap: 6px; margin-bottom: 12px; }
.todo-manual input[type="text"] { flex: 1; }
.todo-manual input[type="number"] { width: 64px; flex: none; padding: 10px 6px; text-align: center; }
.todo-card { display: flex; gap: 10px; align-items: flex-start; }
.todo-check { width: 26px; height: 26px; margin-top: 11px; flex-shrink: 0; }
.todo-done .card-name { text-decoration: line-through; color: var(--muted); }
.todo-done { opacity: .85; }
.picker-qty { width: 64px; min-block-size: 36px; padding: 6px; text-align: center; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 6px 0 8px; }
.cal-title { font-weight: 800; font-size: 17px; margin: 0; font-variant-numeric: tabular-nums; }
.cal-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.cal-week span:first-child { color: var(--danger-ink); }
.cal-week span:last-child { color: var(--accent); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; touch-action: pan-y; }
.cal-cell {
  min-height: 64px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 3px 4px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  font-size: 12px; color: var(--text); min-width: 0;
}
.cal-cell.other { opacity: .38; }
.cal-cell.today { border: 2px solid var(--primary); }
.cal-cell.selected { background: var(--cal-selected); border-color: var(--primary); }
.cal-daynum { font-weight: 700; font-variant-numeric: tabular-nums; }
.cal-cell.sun .cal-daynum, .cal-cell.holiday .cal-daynum { color: var(--danger-ink); }
.cal-cell.sat .cal-daynum { color: var(--accent); }
.cal-hol { font-size: 9px; font-weight: 700; color: var(--danger-ink); line-height: 1.25; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-hol-legend { font-size: 11px; }
.cal-ev { font-size: 10px; font-weight: 700; border-radius: 6px; padding: 1px 5px; line-height: 1.5; }
.ev-past { background: var(--ev-past-bg); color: var(--ev-past-ink); }
.ev-soon { background: var(--ev-soon-bg); color: var(--ev-soon-ink); }
.ev-ok { background: var(--ev-ok-bg); color: var(--ev-ok-ink); }
.ev-frozen { background: var(--ev-frozen-bg); color: var(--ev-frozen-ink); }
.cal-day-title { margin: 14px 0 8px; font-size: 16px; }
.cal-legend { padding: 6px 0 calc(8px + env(safe-area-inset-bottom)); }
.cal-row {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; width: 100%; box-shadow: var(--shadow-1); color: var(--text);
}
.cal-row-name { font-weight: 700; font-size: 15px; }

/* ---------- recipe ---------- */
.recipe-head { display: flex; gap: 8px; align-items: center; margin: 6px 0 8px; }
.recipe-head .btn-primary { flex: 1; min-block-size: 48px; }
.recipe-scroll { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.recipe-status { color: var(--primary-ink); font-size: 14px; margin: 8px 0 0; font-weight: 600; }
#recipeList { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 12px; }
.recipe-section { margin: 10px 0 0; font-size: 16px; }
.recipe-card h3 { margin: 0; font-size: 16px; }
.recipe-steps { margin: 8px 0 4px 20px; padding: 0; font-size: 14px; }
.recipe-steps li { margin: 3px 0; }
.chip-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.ing-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--bg); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: 13px; }
.ing-chip .btn-small { min-block-size: 30px; border-radius: 999px; }
.hint-text { color: var(--muted); font-size: 12px; margin: 0; }

/* =========================================================
   <dialog>：モーダル／シート／全画面スクリーン
   ========================================================= */
dialog {
  color: var(--text);
  background: var(--surface);
  border: 0;
  padding: 0;
  /* exit / entry transition（overlay・display は離散アニメーション） */
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: .22s;
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgb(0 0 0 / 0);
  transition-property: background-color, display, overlay;
  transition-duration: .22s;
  transition-timing-function: var(--ease-out);
  transition-behavior: allow-discrete;
}
dialog[open]:not([data-closing]) { opacity: 1; }
dialog[open]:not([data-closing])::backdrop { background-color: var(--backdrop); }
@starting-style {
  dialog[open]:not([data-closing]) { opacity: 0; }
  dialog[open]:not([data-closing])::backdrop { background-color: rgb(0 0 0 / 0); }
}

/* 中央モーダル */
dialog.modal {
  width: min(100% - 40px, 400px);
  max-height: min(100dvh - 40px, 720px);
  border-radius: 20px;
  padding: 22px 20px 20px;
  box-shadow: var(--shadow-2);
  overflow-y: auto;
}
.modal-title { margin: 0 0 10px; font-size: 18px; }
dialog.modal p { margin: 0 0 12px; }
dialog.modal .card-meta { font-size: 14px; }
.modal-btns { display: flex; flex-direction: column; gap: 8px; }
dialog.modal .modal-gap { margin-top: 14px; }
dialog.modal .confirm-text { font-size: 16px; font-weight: 600; margin: 4px 0 16px; }
.invite-code {
  font-size: 28px; font-weight: 800; letter-spacing: .14em; text-align: center; margin: 10px 0 16px !important;
  padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px dashed var(--border-strong);
  font-variant-numeric: tabular-nums; user-select: all; -webkit-user-select: all;
}

/* 下から出るシート（狭い画面） */
@media (max-width: 599px) {
  dialog.sheet {
    width: 100%; max-width: 100%;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  dialog.sheet::before {
    content: ""; display: block; width: 40px; height: 5px; border-radius: 3px;
    background: var(--border-strong); margin: -10px auto 12px; opacity: .6;
  }
}

/* 全画面スクリーン（スキャン・フォーム・ピッカー） */
dialog.screen {
  width: 100%; height: 100%;
  max-width: none; max-height: none;
  margin: 0; inset: 0;
  border-radius: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
dialog.screen::backdrop { background-color: transparent !important; }

@media (prefers-reduced-motion: no-preference) {
  dialog.modal { transform: scale(.96); }
  dialog.modal[open]:not([data-closing]) { transform: none; }
  @starting-style { dialog.modal[open]:not([data-closing]) { transform: scale(.96); } }

  dialog.screen { transform: translateY(16px); }
  dialog.screen[open]:not([data-closing]) { transform: none; }
  @starting-style { dialog.screen[open]:not([data-closing]) { transform: translateY(16px); } }
}
@media (prefers-reduced-motion: no-preference) and (max-width: 599px) {
  dialog.sheet { transform: translateY(100%); }
  dialog.sheet[open]:not([data-closing]) { transform: none; }
  @starting-style { dialog.sheet[open]:not([data-closing]) { transform: translateY(100%); } }
}
@media (prefers-reduced-motion: reduce) {
  dialog, dialog::backdrop { transition-duration: .1s; }
}

/* ---------- form screen ---------- */
.form-view { background: var(--bg); padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.picker-view[open] { display: flex; flex-direction: column; }
.picker-view > * { width: 100%; max-width: 560px; margin-left: auto; margin-right: auto; }
.form-topbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 10px; max-width: 560px; margin: 0 auto 10px; padding: 12px 0 8px;
  background: var(--bg);
}
.form-topbar h2 { font-size: 18px; margin: 0; }
#itemForm { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.form-photo-row {
  display: flex; gap: 14px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-1);
}
.form-photo-btns { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.file-btn:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; min-width: 0; }
.field > label, .field-label { font-size: 14px; font-weight: 600; }
legend.field-label { margin-bottom: 6px; }
.req { color: var(--danger-ink); font-size: 12px; font-weight: 700; margin-left: 4px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-inline { display: inline-flex; align-items: center; gap: 8px; min-block-size: 44px; font-size: 15px; cursor: pointer; }
.check-inline input { width: 22px; height: 22px; margin: 0; }
.expiry-inputs { display: flex; align-items: center; gap: 6px; }
.expiry-inputs input { flex: 1; padding: 10px 4px; text-align: center; font-variant-numeric: tabular-nums; }
.expiry-inputs input:first-child { flex: 1.3; }
.expiry-inputs > span { color: var(--muted); }
.expiry-inputs .btn { flex: none; }
.jan-line { color: var(--muted); font-size: 13px; margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- scan screen ---------- */
dialog.scan-view {
  background: #0b1210; color: #fff;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  color-scheme: dark;
}
.scan-view > * { max-width: 560px; margin-left: auto; margin-right: auto; }
.scan-topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.scan-topbar h2 { font-size: 16px; margin: 0; }
.scan-banner { text-align: center; font-size: 19px; font-weight: 800; padding: 12px; border-radius: 14px; margin-bottom: 10px; background: #374151; transition: background-color .25s; }
.scan-banner.state-starting { background: #374151; }
.scan-banner.state-searching { background: #1d4ed8; }
.scan-banner.state-detected { background: #b45309; }
.scan-banner.state-success { background: #047857; }
.scan-banner.state-error { background: var(--danger); }
.scan-frame { position: relative; border: 4px solid #374151; border-radius: 18px; overflow: hidden; aspect-ratio: 4 / 3; background: #000; touch-action: none; transition: border-color .25s; }
.scan-frame.state-starting { border-color: #374151; }
.scan-frame.state-searching { border-color: #3b82f6; }
.scan-frame.state-detected { border-color: #f59e0b; }
.scan-frame.state-success { border-color: #10b981; }
.scan-frame.state-error { border-color: var(--danger); }
.scan-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-guide { position: absolute; inset: 22% 12%; border: 2px dashed rgb(255 255 255 / .75); border-radius: 10px; pointer-events: none; }
.scan-line { position: absolute; left: 12%; right: 12%; height: 3px; background: #f87171; top: 25%; animation: scanmove 1.6s ease-in-out infinite alternate; box-shadow: 0 0 10px #f87171; }
@keyframes scanmove { from { top: 25%; } to { top: 72%; } }
@media (prefers-reduced-motion: reduce) { .scan-line { animation-duration: 3.2s; } }
.scan-hint { text-align: center; color: #d1d5db; font-size: 14px; }
.scan-zoom { display: flex; align-items: center; gap: 10px; margin: 8px auto; }
.scan-zoom input { flex: 1; accent-color: #2dd4bf; }
.scan-manual { display: flex; gap: 6px; margin-top: 10px; }
.scan-manual input { flex: 1; border-color: #4b5563; background: #111827; color: #fff; }
#scanRetryBtn { display: flex; width: 100%; margin-top: 12px; }
#scanRetryBtn.hidden { display: none !important; }

/* ---------- lightbox ---------- */
dialog.lightbox {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; inset: 0;
  background: rgb(0 0 0 / .92);
  padding: 20px;
  color-scheme: dark;
}
dialog.lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
dialog.lightbox::backdrop { background-color: transparent !important; }
.lightbox img { max-width: 100%; max-height: 75dvh; border-radius: 14px; object-fit: contain; }
.lightbox p { color: #fff; font-size: 17px; font-weight: 700; margin: 0; text-align: center; }
.lightbox-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  width: 44px; height: 44px; border-radius: 50%; border: none; background: rgb(255 255 255 / .2); color: #fff; font-size: 18px;
}

/* =========================================================
   popover：トースト／ツールチップ
   ========================================================= */
/* Popover API 非対応ブラウザ用（head のスクリプトが .no-popover を付ける） */
.no-popover [popover]:not(.popover-open) { display: none; }
.no-popover [popover].popover-open { display: block; position: fixed; z-index: 1000; }

.toast {
  position: fixed; inset: auto; margin: 0;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  translate: -50% 0;
  background: #111827; color: #fff; border: 0;
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgb(0 0 0 / .3); max-width: 90vw; width: max-content; text-align: center;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: .2s;
  transition-behavior: allow-discrete;
}
.toast:is(:popover-open, .popover-open) { opacity: 1; }
@starting-style { .toast:is(:popover-open, .popover-open) { opacity: 0; } }
@media (prefers-reduced-motion: no-preference) {
  .toast { transform: translateY(8px); }
  .toast:is(:popover-open, .popover-open) { transform: none; }
  @starting-style { .toast:is(:popover-open, .popover-open) { transform: translateY(8px); } }
}
@media (prefers-color-scheme: dark) { .toast { background: #e8eeed; color: #0e1615; } }

.tip {
  position: fixed; inset: auto; margin: 0;
  background: #1f2937; color: #fff; border: 0;
  font-size: 12px; line-height: 1; font-weight: 600;
  padding: 6px 9px; border-radius: 7px; white-space: nowrap;
  pointer-events: auto;
  opacity: 0;
  transition-property: opacity, display, overlay;
  transition-duration: .15s;
  transition-behavior: allow-discrete;
}
.tip:is(:popover-open, .popover-open) { opacity: 1; }
@starting-style { .tip:is(:popover-open, .popover-open) { opacity: 0; } }
@media (prefers-color-scheme: dark) { .tip { background: #e8eeed; color: #0e1615; } }
/* アンカー位置指定に対応していればCSSで、未対応ならJSで位置を決める */
@supports (anchor-name: --a) and (position-area: block-end) {
  #refreshBtn { anchor-name: --tip-refresh; }
  #householdBtn { anchor-name: --tip-household; }
  #notifyBtn { anchor-name: --tip-notify; }
  #logoutBtn { anchor-name: --tip-logout; }
  #tipRefresh { position-anchor: --tip-refresh; }
  #tipHousehold { position-anchor: --tip-household; }
  #tipNotify { position-anchor: --tip-notify; }
  #tipLogout { position-anchor: --tip-logout; }
  .tip {
    position-area: block-end;
    position-try-fallbacks: block-end span-inline-start, block-end span-inline-end, flip-block;
    margin-top: 4px;
  }
}

/* =========================================================
   View Transitions（タブ切り替え・カレンダーの月移動）
   名前は遷移中だけ付ける（app.js が :root[data-vt] を切り替える）
   ========================================================= */
:root[data-vt="tab"] .app-shell > .view:not(.hidden) { view-transition-name: tab-panel; }
:root[data-vt="cal"] #calGrid { view-transition-name: cal-grid; }
:root[data-vt="cal"] #calTitle { view-transition-name: cal-title; }

::view-transition-group(tab-panel),
::view-transition-group(cal-grid),
::view-transition-group(cal-title) { animation-duration: .24s; animation-timing-function: var(--ease-out); }
::view-transition-group(tab-panel) { animation: none; }

:root[data-vt-dir="forward"]::view-transition-old(tab-panel),
:root[data-vt-dir="forward"]::view-transition-old(cal-grid),
:root[data-vt-dir="forward"]::view-transition-old(cal-title) { animation: .2s ease-in both vt-out-start; }
:root[data-vt-dir="forward"]::view-transition-new(tab-panel),
:root[data-vt-dir="forward"]::view-transition-new(cal-grid),
:root[data-vt-dir="forward"]::view-transition-new(cal-title) { animation: .24s var(--ease-out) both vt-in-end; }
:root[data-vt-dir="back"]::view-transition-old(tab-panel),
:root[data-vt-dir="back"]::view-transition-old(cal-grid),
:root[data-vt-dir="back"]::view-transition-old(cal-title) { animation: .2s ease-in both vt-out-end; }
:root[data-vt-dir="back"]::view-transition-new(tab-panel),
:root[data-vt-dir="back"]::view-transition-new(cal-grid),
:root[data-vt-dir="back"]::view-transition-new(cal-title) { animation: .24s var(--ease-out) both vt-in-start; }

@keyframes vt-out-start { to { opacity: 0; transform: translateX(-28px); } }
@keyframes vt-out-end   { to { opacity: 0; transform: translateX(28px); } }
@keyframes vt-in-end    { from { opacity: 0; transform: translateX(28px); } }
@keyframes vt-in-start  { from { opacity: 0; transform: translateX(-28px); } }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

/* ---------- loading ---------- */
.loading-overlay {
  position: fixed; inset: 0; background: #b9fdf2; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  color-scheme: light;
}
.loader-video { width: min(74vw, 300px); height: auto; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 22px; }
.loader-text { font-size: 17px; font-weight: 700; color: #0f766e; letter-spacing: .04em; }
.loader-dots span { animation: dotBlink 1.2s infinite; opacity: 0; }
.loader-dots span:nth-child(2) { animation-delay: .2s; }
.loader-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dotBlink { 0% { opacity: 0; } 40% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- pointer / contrast preferences ---------- */
@media (pointer: coarse) {
  .chip { min-block-size: 36px; }
}
@media (forced-colors: active) {
  .btn, .chip, .tab, .segment-btn, .card, .cal-cell, .qty-ctrl, .icon-btn { border: 1px solid ButtonText; }
  .tab.active, .tab[aria-current="page"], .chip.active,
  .segment-btn:has(input:checked), .segment-btn[aria-pressed="true"], .segment-btn.active {
    background: Highlight; color: HighlightText; forced-color-adjust: none;
  }
  .cal-cell.today, .cal-cell.selected { outline: 2px solid Highlight; }
  .remain-bar > div { background: Highlight; }
  dialog { border: 1px solid CanvasText; }
}

/* カレンダー画面：固定部分が多いと下部の明細リストが潰れるため、この画面だけ全体スクロールにする */
#calendarView { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#calendarView .cal-day-list { flex: none; overflow: visible; }
/* マスを少し低くして、下部の明細エリアに余裕を持たせる */
#calendarView .cal-cell { min-height: 50px; }
#calendarView .cal-day-title { margin-top: 10px; }
