:root {
  --bg: #faf6f1;
  --surface: #ffffff;
  --ink: #3d3229;
  --ink-soft: #8a7c6d;
  --accent: #5a473a;
  --accent-soft: #ead9c8;
  --border: #e6dcd0;
  --danger: #b3453b;
  --danger-soft: #f6e3e0;
  --radius: 12px;
  --tab-bar-height: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.app-header h1 { margin: 0; font-size: 17px; font-weight: 600; }

main { padding: 12px 14px 24px; max-width: 520px; margin: 0 auto; }

.screen { display: none; }
.screen.active { display: block; }

h2 { font-size: 16px; margin: 4px 0 14px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--accent); }

/* ---------- フィルタ・件数 ---------- */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.filter-bar select { flex: 1; min-width: 0; }

select, input[type="text"], input[type="date"], textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; }

.closet-count {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

/* ---------- 写真グリッド ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.photo-cell {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
}
.photo-cell .thumb-wrap {
  aspect-ratio: 1 / 1;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.photo-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-cell .no-photo {
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  padding: 8px;
}
.photo-cell .cell-label {
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.3;
}
.photo-cell .cell-label .cell-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.photo-cell .cell-label .cell-sub {
  display: block;
  color: var(--ink-soft);
  font-size: 11px;
}
.badge-second-rank {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(61, 50, 41, 0.75);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 2;
}
.photo-cell.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.select-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  z-index: 2;
}
.photo-cell.selected .select-check {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.grid-number {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.empty-hint {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 40px 10px;
}

/* ---------- フォーム ---------- */
.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--accent);
}
.field .required {
  color: var(--danger);
  font-weight: 400;
  font-size: 11px;
  margin-left: 4px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.photo-preview {
  aspect-ratio: 4 / 3;
  max-width: 260px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.photo-pick-buttons { display: flex; gap: 8px; }

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

.btn {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { opacity: 0.6; }
.btn-secondary { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.file-btn { text-align: center; }

/* ---------- 相談画面 ---------- */
.scene-condition {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--accent-soft);
  padding: 6px 10px;
  border-radius: 8px;
  display: inline-block;
}
.scene-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  margin-top: 8px;
  color: var(--ink-soft);
}
.checkbox-line input { width: auto; }

.consult-preview-details { margin-top: 16px; }
.consult-preview-details summary {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  margin-bottom: 8px;
}
#consult-preview {
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  font-family: ui-monospace, monospace;
}

.ai-links {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- バックアップ ---------- */
.backup-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.backup-hint {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.6;
}

/* ---------- 下部タブ ---------- */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: var(--ink-soft);
  padding: 4px 2px;
}
.tab-btn .tab-icon { font-size: 19px; }
.tab-btn.active { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--tab-bar-height) + env(safe-area-inset-bottom) + 16px);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 26px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 15;
}

/* ---------- モーダル ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--ink-soft);
  line-height: 1;
  padding: 6px;
}
.detail-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--accent-soft);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 14px;
}
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.detail-body dl {
  display: grid;
  grid-template-columns: 84px 1fr;
  row-gap: 8px;
  column-gap: 8px;
  font-size: 13px;
  margin: 0 0 10px;
}
.detail-body dt { color: var(--ink-soft); }
.detail-body dd { margin: 0; }
.detail-body h3 { margin-top: 4px; font-size: 20px; }

/* ---------- バナー ---------- */
.banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  font-size: 13px;
  transform: translateY(-100%);
  transition: transform 0.25s ease;
  text-align: center;
}
.banner.show { transform: translateY(0); }
.banner-error { background: var(--danger); color: #fff; }
.banner-info { background: var(--accent); color: #fff; }

@media (min-width: 600px) {
  main { padding: 20px; }
}
