/* 高齢の家族も使うため、文字は大きめ・ボタンは押しやすい大きさにする */

/* 色はアプリのアイコン（紺の背景にオレンジのリュック）に合わせる。
   紺＝ボタンや見出しなどの基本の色、オレンジ＝今いる画面の印などの差し色、赤＝消す・外す */
:root {
  --bg: #f6f2ea;
  --surface: #ffffff;
  --text: #1b2430;
  --text-sub: #545d6b;
  --border: #d8d0c1;
  --primary: #1f3a5f;
  --primary-text: #ffffff;
  --accent: #e07b2a;
  --header-bg: #1f3a5f;
  --header-text: #ffffff;
  --notice-bg: #fff1dc;
  --notice-border: #e0a052;
  --danger: #b3261e;
  --tab-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111821;
    --surface: #1b2531;
    --text: #eef1f5;
    --text-sub: #aab4c2;
    --border: #2f3c4d;
    --primary: #9cbfe8;
    --primary-text: #0f1a28;
    --accent: #f2a65a;
    --header-bg: #172c48;
    --header-text: #ffffff;
    --notice-bg: #3a2a16;
    --notice-border: #b37a35;
    --danger: #ff8a80;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 18px;
  line-height: 1.6;
  padding-bottom: calc(var(--tab-height) + env(safe-area-inset-bottom));
}

[hidden] {
  display: none !important;
}

/* ヘッダー */
.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 4px solid var(--accent);
  background: var(--header-bg);
  color: var(--header-text);
}

.app-title {
  margin: 0;
  font-size: 22px;
}

.house-name {
  margin: 0;
  padding: 4px 12px;
  border: 2px solid currentColor;
  border-radius: 8px;
  color: inherit;
  font-size: 18px;
  font-weight: bold;
  text-decoration: none;
}

.house-name::after {
  content: " ▾";
}

.app-header {
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-help {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  color: inherit;
  font-size: 17px;
  font-weight: bold;
  text-decoration: none;
}

.header-help .icon {
  color: var(--accent);
}

/* 更新のお知らせ */
.update-banner {
  margin: 12px 16px 0;
  padding: 14px 16px;
  background: var(--notice-bg);
  border: 2px solid var(--notice-border);
  border-radius: 12px;
}

.update-banner p {
  margin: 0 0 10px;
}

/* 本文 */
.main {
  padding: 16px;
}

.loading,
.empty {
  color: var(--text-sub);
}

h2 {
  margin: 0 0 12px;
  font-size: 22px;
}

.card {
  margin: 0 0 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 19px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
}

.row-label {
  color: var(--text-sub);
}

.note {
  margin: 8px 0 0;
  color: var(--text-sub);
  font-size: 16px;
}

.error {
  color: var(--danger);
}

/* ボタン */
.button {
  display: inline-block;
  min-height: 48px;
  padding: 10px 20px;
  border: 2px solid var(--primary);
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-text);
  font: inherit;
  font-weight: bold;
  cursor: pointer;
}

.button-secondary {
  background: transparent;
  color: var(--primary);
}

.button-small {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 16px;
}

.button-danger {
  border-color: var(--danger);
  background: transparent;
  color: var(--danger);
}

/* 絵の付いたボタン */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.icon {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button-small .icon {
  width: 20px;
  height: 20px;
}

a.button {
  text-decoration: none;
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 一覧 */
.item-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.item-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.item-thumb {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
}

.item-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  min-width: 0;
}

.item-name {
  font-size: 19px;
  font-weight: bold;
}

.item-quantity {
  font-size: 19px;
  font-weight: bold;
  white-space: nowrap;
}

.item-expiry {
  grid-column: 1 / -1;
  font-size: 16px;
}

.item-meta {
  grid-column: 1 / -1;
  color: var(--text-sub);
  font-size: 16px;
}

/* 入力画面 */
.item-form {
  margin: 0 0 24px;
}

.field {
  display: block;
  margin: 0 0 18px;
}

.field-label {
  display: block;
  margin: 0 0 4px;
  font-weight: bold;
}

.field-hint {
  display: block;
  margin: 4px 0 0;
  color: var(--text-sub);
  font-size: 16px;
}

.field input[type="text"],
.field input[type="date"],
.field select,
.field textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.field input[type="text"]:focus,
.field input[type="date"]:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  outline: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.section-fields {
  margin: 0 0 18px;
  padding: 12px 16px 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.section-fields legend {
  padding: 0 6px;
  font-weight: bold;
}

.section-fields .note {
  margin: 0 0 12px;
}

/* iPhone の日付欄は文字が中央に寄るので左にそろえる */
.field input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
}

.field input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

/* 年・月を選ぶ欄 */
.year-month {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field .year-month select {
  display: inline-block;
  width: auto;
  min-width: 96px;
}

/* 期限ごとの内訳 */
.lot {
  margin: 0 0 16px;
  padding: 14px 14px 2px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.lot .button-small {
  margin: 0 0 14px;
}

.lot-preview {
  color: var(--primary);
  font-weight: bold;
}

.lot-total {
  margin: 16px 0 12px;
  font-size: 20px;
  font-weight: bold;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin: 0 0 12px;
}

.check-field input {
  width: 28px;
  height: 28px;
  margin: 0;
  accent-color: var(--primary);
}

.form-error {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 2px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-weight: bold;
}

.form-actions {
  display: flex;
  gap: 12px;
}

.form-actions .button {
  flex: 1;
  text-align: center;
}

.danger-zone {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* 絞り込み */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px 12px;
  margin: 0 0 12px;
}

.filter {
  display: block;
}

.filter-label {
  display: block;
  color: var(--text-sub);
  font-size: 16px;
}

.filter select {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.filter-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  font-weight: bold;
}

/* タグ */
.item-tags {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.tag {
  padding: 2px 10px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  color: var(--primary);
  font-size: 15px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 16px 6px 12px;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.chip input {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--primary);
}

.chip:has(input:checked) {
  border-color: var(--primary);
  font-weight: bold;
}

.tag-add {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}

.tag-add input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.tag-add .button {
  margin: 0;
}

.tag-list {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.tag-row input[type="text"] {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.tag-row-actions {
  display: flex;
  gap: 10px;
}

.tag-row-actions + .tag-row-actions {
  margin-top: 10px;
}

.tag-row .check-field {
  min-height: 44px;
  margin: 0 0 8px;
}

.badges {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: bold;
}

.badge-ok {
  background: #dcefe3;
  color: #14532d;
}

.badge-warn {
  background: #ffe1c2;
  color: #7a3600;
}

.badge-notice {
  background: #dde9f7;
  color: #1d3f6e;
}

.badge-bad {
  background: #fbdcd9;
  color: #8a1c14;
}

.badge-muted {
  background: var(--bg);
  color: var(--text-sub);
}

.set-pick-group h3 {
  margin: 12px 0 4px;
  font-size: 18px;
}

.set-pick {
  border-top: 1px solid var(--border);
}

.set-pick .check-field {
  margin: 0;
}

.set-required {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px 40px;
}

.set-required input {
  width: 6em;
  min-height: 44px;
  padding: 6px 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* テンプレートを選ぶ画面 */
.search-input {
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.search-input:focus {
  border-color: var(--primary);
  outline: none;
}

.picker-group h3 {
  margin: 20px 0 8px;
  font-size: 19px;
}

.picker-list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.picker-row {
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--border);
}

.picker-row:first-child {
  border-top: none;
}

.picker-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 56px;
  padding: 8px 16px;
  color: inherit;
  text-decoration: none;
}

.picker-name {
  font-weight: bold;
}

.picker-sub {
  color: var(--text-sub);
  font-size: 16px;
}

.picker-remove {
  flex: none;
  width: 56px;
  border: none;
  border-left: 1px solid var(--border);
  background: transparent;
  color: var(--text-sub);
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

.preset-note {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 2px solid var(--primary);
  border-radius: 10px;
}

/* 写真 */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  margin: 0 0 12px;
}

.photo-grid:empty {
  display: none;
}

.photo-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.photo-thumb {
  position: relative;
  display: block;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-sub);
  font: inherit;
  overflow: hidden;
  cursor: pointer;
}

.photo-thumb img {
  /* Safari ではボタンの中で高さ100%が効かず、縦に長い写真で枠が伸びるため、枠に重ねて置く */
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-kind {
  width: 100%;
  min-height: 44px;
  padding: 4px 6px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.photo-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 12px;
}

.photo-buttons .button {
  flex: 1 1 auto;
  /* 「写真を撮る」が途中で折り返さないように。入りきらないときはボタンごと次の行へ */
  white-space: nowrap;
}

.photo-viewer {
  width: min(100vw - 24px, 820px);
  max-width: none;
  max-height: calc(100vh - 24px);
  /* iPhone では 100vh が見えている高さより大きいことがあるので、見えている高さ（dvh）を使う */
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.photo-viewer::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

.photo-viewer img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 160px);
  max-height: calc(100dvh - 160px);
  margin: 0 auto;
  object-fit: contain;
}

/* 閉じるボタンは写真の上に置き、縦に長い写真でも必ず見えるようにする */
.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 12px;
}

.viewer-actions .button {
  flex: 1 1 auto;
  white-space: nowrap;
}

/* 下のタブ */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(var(--tab-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-size: 18px;
  text-decoration: none;
}

.tab[aria-current="page"] {
  color: var(--primary);
  font-weight: bold;
  box-shadow: inset 0 4px 0 var(--accent);
}

/* ホームの「お知らせ」と、期限の区分の色（赤＝期限切れ、橙＝30日以内、青＝90日以内） */
.attention h3 {
  margin: 0 0 8px;
}

.attention p {
  margin: 0 0 12px;
}

.attention-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.attention-button {
  min-height: 48px;
  padding: 6px 14px;
  border: 2px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: bold;
}

.attention-button[aria-pressed="true"] {
  border-color: currentColor;
}

.item-card.level-bad {
  border-left: 8px solid #c62828;
}

.item-card.level-warn {
  border-left: 8px solid #e07b00;
}

.item-card.level-notice {
  border-left: 8px solid #3b72b8;
}

.item-expiry .badge {
  font-size: 14px;
}

/* カレンダーに入れる予定 */
.calendar-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.calendar-list li {
  display: grid;
  gap: 0 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.calendar-date {
  color: var(--text-sub);
  font-size: 16px;
}

.note-list {
  margin: 0;
  padding-left: 1.2em;
}

.note-list li {
  margin: 0 0 8px;
}

.filter-panel {
  margin: 0 0 16px;
}

.filter-panel summary {
  min-height: 48px;
  padding: 10px 0;
  color: var(--primary);
  font-weight: bold;
  cursor: pointer;
}

/* 説明つきの選択肢は、丸を1行目にそろえる */
.radio-field {
  align-items: flex-start;
}

.radio-field input {
  flex: none;
  margin-top: 1px;
}

/* あと何日もつか */
.bottleneck {
  margin: 0 0 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--notice-bg);
  border: 2px solid var(--notice-border);
  font-weight: bold;
}

.supply-card.level-bad {
  border-left: 8px solid #c62828;
}

.supply-card.level-warn {
  border-left: 8px solid #e07b00;
}

.supply-card.level-ok {
  border-left: 8px solid #2e7d4f;
}

.supply-card.is-bottleneck {
  border-width: 3px;
  border-left-width: 8px;
}

.supply-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.supply-head h3 {
  margin: 0;
}

.supply-days {
  margin: 4px 0;
  font-size: 30px;
  font-weight: bold;
}

.supply-card .note {
  margin: 0 0 4px;
}

.supply-missing {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--bg);
}

.supply-missing p {
  margin: 0 0 4px;
}

.supply-missing ul {
  margin: 0;
  padding-left: 1.2em;
}

.supply-missing a {
  display: inline-block;
  min-height: 40px;
  padding: 6px 0;
  color: var(--primary);
}

.stepper {
  display: grid;
  grid-template-columns: 1fr 52px 4.5em 52px;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.stepper-label {
  font-weight: bold;
}

.stepper-label .field-hint {
  margin: 0;
  font-weight: normal;
}

.stepper-count {
  text-align: center;
  font-size: 20px;
  font-weight: bold;
}

.stepper-button {
  width: 52px;
  height: 52px;
  border: 2px solid var(--primary);
  border-radius: 10px;
  background: var(--surface);
  color: var(--primary);
  font-size: 26px;
  font-weight: bold;
  line-height: 1;
}

.stepper-button:disabled {
  border-color: var(--border);
  color: var(--border);
}

/* 基準の値と出典 */
.unit-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field .unit-input input {
  max-width: 10em;
}

.source-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.source-list li {
  display: grid;
  gap: 2px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.source-label {
  font-weight: bold;
}

.source-url {
  color: var(--text-sub);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.supply-line {
  display: block;
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 6px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: inherit;
  font-weight: bold;
  text-decoration: none;
}

.supply-line.level-bad {
  border-left-color: #c62828;
}

.supply-line.level-warn {
  border-left-color: #e07b00;
}

.supply-line.level-ok {
  border-left-color: #2e7d4f;
}

/* 消費ペースの計画 */
.plan-conditions {
  margin: 16px 0 8px;
}

.allowance {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.allowance-name {
  font-weight: bold;
}

.allowance-value {
  font-size: 22px;
  font-weight: bold;
  text-align: right;
}

.allowance-note {
  grid-column: 1 / -1;
  color: var(--text-sub);
  font-size: 16px;
}

.allowance.is-short .allowance-note {
  color: var(--danger);
  font-weight: bold;
}

.plan-order {
  margin: 0;
  padding: 0;
  list-style: none;
}

.plan-order li {
  display: grid;
  grid-template-columns: 6.5em 1fr;
  gap: 2px 8px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.plan-order li.is-late {
  background: #fff3e8;
}

@media (prefers-color-scheme: dark) {
  .plan-order li.is-late {
    background: #3a2a18;
  }
}

.plan-when {
  grid-row: span 2;
  font-weight: bold;
}

.plan-what a {
  color: var(--primary);
  font-weight: bold;
}

.plan-amount {
  color: var(--text-sub);
  font-size: 16px;
}

.plan-detail {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  color: var(--text-sub);
  font-size: 16px;
}

.card > .stepper:first-child {
  border-top: 0;
}

/* バックアップから戻す */
.restore-confirm {
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 2px solid var(--danger);
  border-radius: 10px;
}

.restore-confirm h4 {
  margin: 0 0 8px;
  font-size: 18px;
}

.restore-warning {
  color: var(--danger);
  font-weight: bold;
}

/* 家の一覧 */
.house-card.is-current {
  border: 3px solid var(--primary);
}

.house-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.house-card .note {
  margin: 4px 0 12px;
}

.house-edit {
  margin: 12px 0 0;
}

.house-edit summary {
  min-height: 44px;
  padding: 8px 0;
  color: var(--primary);
  font-weight: bold;
  cursor: pointer;
}

.house-edit input[type="text"] {
  display: block;
  width: 100%;
  min-height: 48px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* 家族とのやり取り */
.report-text {
  margin: 0 0 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg);
  white-space: pre-wrap;
}

.import-confirm {
  border-color: var(--primary);
}

/* 使う人のかんたん画面（文字を大きく） */
.simple {
  font-size: 20px;
}

.simple-card.level-bad {
  border-left: 8px solid #c62828;
}

.simple-card.level-warn {
  border-left: 8px solid #e07b00;
}

.simple-card.level-notice {
  border-left: 8px solid #3b72b8;
}

.simple-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.simple-photo {
  flex: none;
  width: 104px;
  height: 104px;
}

.simple-photo img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
}

.simple-info {
  flex: 1;
  min-width: 0;
}

.simple-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 12px;
}

/* 名前が長いときは、数を次の行に回す */
.simple-name {
  flex: 1 1 7em;
  color: inherit;
  font-size: 22px;
  font-weight: bold;
}

.simple-quantity {
  font-size: 26px;
  font-weight: bold;
  white-space: nowrap;
}

.simple-expiry {
  margin: 4px 0;
  font-size: 18px;
}

.simple-card .note {
  margin: 4px 0;
}

.simple-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0 0;
}

.simple-actions .button {
  min-height: 56px;
  font-size: 20px;
}

.simple-panel {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg);
}

.simple-question {
  margin: 0 0 8px;
  font-weight: bold;
}

.simple-counter {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  gap: 8px;
}

.simple-counter .stepper-button {
  width: 64px;
  height: 64px;
}

.simple-counter .stepper-count {
  font-size: 26px;
}

.record-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.record-list li {
  display: grid;
  gap: 6px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 18px;
}

.record-list .button {
  justify-self: start;
}

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tab-height) + env(safe-area-inset-bottom) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #1c1c1c;
  color: #ffffff;
  font-size: 18px;
  z-index: 10;
}

.toast .button {
  flex: none;
  background: #ffffff;
  color: #1c1c1c;
}

/* 印刷用のリスト（画面での見た目） */
.print-sheet {
  margin: 16px 0 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: #000000;
  font-size: 14px;
  line-height: 1.4;
}

.print-title {
  margin: 0;
  font-size: 20px;
}

.print-date {
  margin: 0 0 8px;
}

.print-summary p {
  margin: 0 0 4px;
}

.print-group h3 {
  margin: 16px 0 4px;
  font-size: 16px;
  border-bottom: 2px solid #000000;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.print-table th,
.print-table td {
  padding: 4px 6px;
  border: 1px solid #555555;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.print-table th {
  background: #eeeeee;
  font-size: 12px;
}

.print-table tr.more td {
  border-top-style: dotted;
}

.print-table .col-name { width: 30%; }
.print-table .col-quantity { width: 12%; }
.print-table .col-expiry { width: 24%; }
.print-table .col-where { width: 14%; }
.print-table .col-memo { width: 20%; }

.print-sub {
  display: block;
  font-size: 11px;
}

.print-memos dt {
  margin-top: 6px;
  font-weight: 700;
}

.print-memos dd {
  margin: 0 0 0 1em;
}

/* 印刷するとき：画面の操作は出さず、表だけにする */
@media print {
  @page {
    margin: 12mm;
  }

  body {
    padding: 0;
    background: #ffffff;
  }

  .app-header,
  .tab-bar,
  .update-banner,
  .no-print,
  .toast {
    display: none !important;
  }

  .main {
    padding: 0;
  }

  .print-sheet {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 11pt;
  }

  .print-table tr {
    break-inside: avoid;
  }

  .print-group h3 {
    break-after: avoid;
  }
}

/* 白黒で印刷しても分かるよう、期限切れの行は太字にする */
.print-table tr.is-expired .col-expiry,
.print-table tr.is-expired .col-quantity {
  font-weight: bold;
}

.attention-list {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.attention-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}

.attention-name {
  font-size: 18px;
  font-weight: bold;
}

.attention-place {
  color: var(--text-sub);
  font-size: 16px;
}

.back-link {
  margin: 0 0 8px;
  font-size: 17px;
}

.back-link a {
  color: var(--primary);
  text-decoration: none;
}

.restore-confirm .field {
  margin: 0 0 12px;
}

.restore-all-title {
  margin-top: 28px !important;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* 場所の画面の「必要なもの」 */
.needs-list {
  margin: 8px 0 12px;
  padding: 0;
  list-style: none;
}

.needs-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}

.needs-name {
  font-size: 18px;
  font-weight: bold;
}

.needs-count {
  font-size: 18px;
  font-weight: bold;
  white-space: nowrap;
}

.needs-count.is-short {
  color: var(--danger);
}

.set-pick-here {
  color: var(--text-sub);
  font-size: 16px;
}

.place-thumb {
  grid-row: span 2;
  width: 84px;
  height: 84px;
  border-radius: 10px;
  object-fit: cover;
}

.place-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 34px;
  font-weight: bold;
}

.place-photo-image {
  display: block;
  width: 100%;
  max-height: 220px;
  margin: 0 0 8px;
  border-radius: 12px;
  object-fit: cover;
}

/* 絞り込みと、タイル／一覧の切り替え */
.list-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
}

.list-tools .filter-panel {
  flex: 1 1 auto;
  margin: 0;
}

.view-switch {
  display: flex;
  border: 2px solid var(--primary);
  border-radius: 10px;
  overflow: hidden;
}

.view-button {
  min-height: 44px;
  padding: 6px 14px;
  border: 0;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: bold;
}

.view-button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-text);
}

/* 品目のタイル（横に2つ） */
.item-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.item-tiles > li {
  display: flex;
}

.item-tile {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: inherit;
  text-decoration: none;
}

.item-tile.level-bad {
  border-top: 6px solid #c62828;
}

.item-tile.level-warn {
  border-top: 6px solid #e07b00;
}

.item-tile.level-notice {
  border-top: 6px solid #3b72b8;
}

.tile-photo {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
}

.tile-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 40px;
  font-weight: bold;
}

.category-food { background: #c77d3a; }
.category-water { background: #3b7fc4; }
.category-daily { background: #6f8f4e; }
.category-medicine { background: #b8505a; }
.category-power { background: #c9a227; }
.category-tools { background: #5e6b7a; }
.category-other { background: #8a7f72; }

.tile-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 8px 10px 10px;
}

.tile-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 17px;
  font-weight: bold;
  line-height: 1.3;
}

.tile-quantity {
  font-size: 17px;
  font-weight: bold;
}

.tile-expiry {
  color: var(--text-sub);
  font-size: 15px;
}

/* 使い方 */
.help-card p {
  margin: 0 0 8px;
}

.help-list {
  margin: 0;
  padding-left: 1.4em;
}

.help-list li {
  margin: 0 0 6px;
}

/* 「何日分」の計算用の欄（たたんでおき、押すと開く） */
.calc-fields {
  padding: 4px 16px;
}

.calc-fields summary {
  min-height: 48px;
  padding: 10px 0;
  color: var(--primary);
  font-weight: bold;
  cursor: pointer;
}

.calc-fields[open] {
  padding-bottom: 8px;
}

/* 下のタブ：絵の下に名前 */
.tab {
  flex-direction: column;
  gap: 2px;
  font-size: 15px;
}

.tab .icon {
  width: 26px;
  height: 26px;
}

.tab[aria-current="page"] .icon {
  stroke-width: 2.4;
}

.back-link a {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.back-link .icon {
  width: 20px;
  height: 20px;
}

/* ボタンの文字は途中で折り返さない（入らなければボタンごと次の行へ） */
.tag-row-actions {
  flex-wrap: wrap;
}

.tag-row-actions .button {
  white-space: nowrap;
}

.settings-toggle {
  margin: 16px 0 0;
}

/* 場所の画面の見出しと「編集」 */
.place-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
}

.place-head h2 {
  margin: 0;
}

/* 場所の編集画面の写真 */
.place-edit-photo img {
  display: block;
  width: 100%;
  max-height: 220px;
  margin: 0 0 10px;
  border-radius: 10px;
  object-fit: cover;
}

.place-edit-photo-empty {
  display: block;
  margin: 0 0 10px;
  color: var(--text-sub);
}

/* 設定の場所の一覧 */
.place-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.place-row-thumb {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  font-size: 24px;
}

.place-row-name {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 18px;
  font-weight: bold;
}

.place-row-note {
  color: var(--text-sub);
  font-size: 14px;
  font-weight: normal;
}

.place-row-actions {
  display: flex;
  gap: 6px;
}

.place-row-actions .button {
  padding: 6px 10px;
  white-space: nowrap;
}

/* ホームの場所のタイル（写真がないとき） */
.place-placeholder {
  background: #dfe5ee;
  color: var(--primary);
}

.place-placeholder.is-all {
  background: var(--primary);
  color: var(--primary-text);
  font-size: 28px;
}

@media (prefers-color-scheme: dark) {
  .place-placeholder {
    background: #2a3a50;
  }
}

/* 「場所を追加」のタイル */
.add-tile {
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 160px;
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--primary);
  font-weight: bold;
}

.add-tile .icon {
  width: 32px;
  height: 32px;
}

.tile-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tile-badges:empty {
  display: none;
}

/* 下に並ぶボタンは、文字を折り返さず、入らなければ次の行へ */
.form-actions {
  flex-wrap: wrap;
}

.form-actions .button {
  white-space: nowrap;
}

/* 幅が足りないときは、↑↓と編集を名前の下に回す */
.place-row {
  flex-wrap: wrap;
}

.place-row-name {
  flex: 1 1 140px;
}

.place-row-actions {
  margin-left: auto;
}

/* 「たりる？」の画面の説明 */
.days-intro {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-sub);
  font-size: 16px;
}

/* 使い方のメモ（改行をそのまま出す）と、説明書の写真 */
.memo-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.manual-photo {
  display: block;
  width: 100%;
  height: auto;
  margin: 8px 0 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* かんたん画面の表示の切り替えと、写真のタイル（文字を大きく） */
.simple-view-switch {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 12px;
}

.simple .view-button {
  min-height: 52px;
  padding: 6px 20px;
}

.simple .tile-photo {
  aspect-ratio: 1 / 1;
}

.simple .tile-name,
.simple .tile-quantity {
  font-size: 20px;
}

.simple .tile-expiry {
  font-size: 17px;
}
