/* おあずかり — 白基調・警告しない・事実だけを置く */

:root {
  --bg: #faf9f7;
  --card: #ffffff;
  --ink: #3b3a36;
  --sub: #8f8d86;
  --line: #e9e7e2;
  --chip: #f1efe9;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app-header {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 20px 0;
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#screen-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--sub);
  min-height: 1.2em;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 16px calc(76px + env(safe-area-inset-bottom));
}

/* 作家フィルタ */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 0;
  min-height: 36px;
  background: var(--chip);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.chip .count {
  opacity: 0.55;
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
}

/* 棚の一覧 */
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.item-row:active { background: #f6f4ef; }

.row-sell {
  flex: 0 0 auto;
  border: 0;
  background: var(--chip);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 13px;
  min-height: 36px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.row-sell:disabled { opacity: 0.5; }

/* 今日の記録(売れた/返した の事実行) */
.item-row.done .item-name,
.item-row.done .item-days { color: var(--sub); font-weight: 500; }

/* 狭い画面では 日数・価格 を作品名の下に落とし、行の識別子である作品名を最優先で確保する */
@media (max-width: 480px) {
  .item-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) auto;
    grid-template-areas:
      'thumb main sell'
      'thumb meta sell';
    row-gap: 3px;
  }
  .thumb { grid-area: thumb; align-self: center; }
  .item-main { grid-area: main; }
  .item-right {
    grid-area: meta;
    display: flex;
    gap: 10px;
    align-items: baseline;
    text-align: left;
  }
  .item-right .item-price { margin-top: 0; }
  .row-sell { grid-area: sell; align-self: center; }
}

.item-row + .item-row { border-top: 1px solid var(--line); }

.thumb {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--chip);
  color: var(--sub);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-main { flex: 1; min-width: 0; }

.item-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-artist {
  font-size: 12.5px;
  color: var(--sub);
  margin-top: 2px;
}

.item-right {
  flex: 0 0 auto;
  text-align: right;
}

/* 滞留日数はこのアプリが置く唯一の「事実」。強調も警告色も使わない */
.item-days { font-size: 13px; }

.item-price {
  font-size: 12.5px;
  color: var(--sub);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.backup-fact {
  display: block;
  text-align: center;
  color: var(--sub);
  font-size: 12.5px;
  padding: 18px 0 4px;
  text-decoration: none;
}

.empty {
  text-align: center;
  color: var(--sub);
  padding: 56px 16px;
  font-size: 14px;
  line-height: 1.9;
  white-space: pre-line; /* textContent の改行を生かす */
}

.placeholder {
  text-align: center;
  color: var(--sub);
  padding: 48px 8px;
  font-size: 14px;
}

/* フォーム(あずかる) */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 8px;
}

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--sub);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="date"],
.field input[type="month"],
.field select {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* 16px 未満だと iOS がフォーカス時にズームする */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--ink);
}

.new-artist {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.photo-preview {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--line);
}

.btn-ghost {
  border: 0;
  background: var(--chip);
  color: var(--ink);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary:disabled { opacity: 0.5; }

/* フォームの案内。滞留の「事実表示」とは別物なので、落ち着いた色に留める */
.form-error {
  color: #9c5c4c;
  font-size: 13.5px;
  min-height: 1.2em;
  margin: 0;
}

/* 作品詳細 */
.back-link {
  display: inline-block;
  color: var(--sub);
  text-decoration: none;
  font-size: 13.5px;
  padding: 10px 0 4px;
}

.detail-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-top: 6px;
}

.detail-photo {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 10px;
  background: var(--chip);
  margin-bottom: 12px;
}

.detail-name { font-size: 18px; font-weight: 700; margin: 0; }
.detail-artist { color: var(--sub); font-size: 13px; margin: 3px 0 0; }
.detail-price { font-size: 22px; font-weight: 700; margin: 10px 0 0; font-variant-numeric: tabular-nums; }
.detail-fact { font-size: 13.5px; margin: 8px 0 0; }

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.actions-row { display: flex; gap: 10px; }
.actions-row .btn-ghost { flex: 1; padding: 13px 14px; }

.editbox {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
}

.editbox summary {
  padding: 13px 0;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
}

.editbox summary::-webkit-details-marker { display: none; }
.editbox summary::after { content: '+'; float: right; color: var(--sub); }
.editbox[open] summary::after { content: '−'; }

.editbox .inner {
  padding: 2px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.editbox input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.editbox input:focus { outline: none; border-color: var(--ink); }

.btn-danger-ghost {
  border: 0;
  background: none;
  color: var(--sub);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.section-title { font-size: 13px; color: var(--sub); margin: 18px 0 8px; }

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.history li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 14px;
  font-size: 13.5px;
}

.history li + li { border-top: 1px solid var(--line); }
.history .h-date { color: var(--sub); flex: 0 0 6em; font-variant-numeric: tabular-nums; }
.history .h-memo { color: var(--sub); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-amount { margin-left: auto; font-variant-numeric: tabular-nums; }
.history li.voided .h-label,
.history li.voided .h-amount { text-decoration: line-through; color: var(--sub); }

/* 作家一覧 */
.artist-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.artist-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
}

.artist-item summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  cursor: pointer;
  list-style: none;
}

.artist-item summary::-webkit-details-marker { display: none; }
.artist-name { font-weight: 600; font-size: 15px; }
.artist-meta { color: var(--sub); font-size: 12.5px; text-align: right; white-space: pre-line; }

.artist-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 0 14px;
}

.artist-form input {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}

.artist-form input:focus { outline: none; border-color: var(--ink); }

.hint { font-size: 12px; color: var(--sub); }

/* 精算 */
.settle-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settle-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.settle-amount {
  font-weight: 700;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.settle-card .history { border-radius: 10px; }

.settle-card input[type="text"],
.settle-card input[type="number"] {
  width: 100%;
  padding: 11px;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}

.settle-card input:focus { outline: none; border-color: var(--ink); }

.adj-row { display: flex; gap: 8px; }
.adj-row input:first-child { flex: 1.4; min-width: 0; }
.adj-row input { flex: 1; min-width: 0; }
.adj-row .btn-ghost { flex: 0 0 auto; }

.adj-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13.5px;
  padding: 0 2px;
}

.history li.linkable { cursor: pointer; }
.history li.linkable:active { background: #f6f4ef; }

/* 精算書プレビュー(全画面シート) */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(59, 58, 54, 0.5);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-inner {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  max-height: 92vh;
  overflow-y: auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.sheet-btns { display: flex; flex-direction: column; gap: 10px; }

/* iOS Safariタブでの試用バナー(事実の提示。警告色は使わない) */
#install-banner {
  display: block;
  width: 100%;
  border: 0;
  background: var(--chip);
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  cursor: pointer;
  text-align: center;
}

.install-help {
  white-space: pre-line;
  font-size: 14px;
  line-height: 1.9;
  margin: 4px 2px 8px;
}

/* トースト */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(64px + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  max-width: 86%;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 30; /* 精算書シート(20)より上。シート表示中の通知が隠れないように */
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.has-action { pointer-events: auto; }

#toast button {
  background: none;
  border: 0;
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  font-family: inherit;
  margin-left: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 下部タブ */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  text-align: center;
  padding: 13px 0 11px;
  font-size: 12.5px;
  color: var(--sub);
  text-decoration: none;
}

.tab.active {
  color: var(--ink);
  font-weight: 700;
}
