*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --primary: #e8734a;
  --primary-dark: #c95f38;
  --text: #1a1a1a;
  --text-muted: #777;
  --border: #e0e0e0;
  --danger: #e53935;
  --success: #43a047;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Views ───────────────────────────────────────────── */
.view { display: none; flex-direction: column; min-height: 100dvh; }
.view.active { display: flex; }

/* ── Header ──────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 1.1rem; font-weight: 700; flex: 1; }
.header-title { flex: 1; min-width: 0; }
.header-title h1 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-title span { font-size: 0.75rem; color: var(--text-muted); }

.btn-icon {
  width: 36px; height: 36px;
  border: none; background: none;
  font-size: 1.2rem; cursor: pointer;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); flex-shrink: 0;
}
.btn-icon:active { background: var(--bg); }

/* ── Tabs ────────────────────────────────────────────── */
.tab-bar { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 10px;
  border: none; background: none;
  font-size: 0.85rem; font-weight: 600;
  color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent; transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Action row ──────────────────────────────────────── */
.action-row {
  display: flex; gap: 10px;
  padding: 12px 16px 4px;
}
.action-btn {
  flex: 1; padding: 10px 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  font-size: 0.85rem; font-weight: 600;
  cursor: pointer; color: var(--text);
  transition: all 0.15s;
}
.action-btn.primary {
  background: var(--primary); color: white; border-color: var(--primary);
}
.action-btn:active { opacity: 0.8; }

/* ── Lists ───────────────────────────────────────────── */
.list { padding: 12px; display: flex; flex-direction: column; gap: 10px; }

/* ── Trip Card ───────────────────────────────────────── */
.trip-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.trip-card:active { transform: scale(0.98); }
.trip-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.trip-card h3 { font-size: 0.95rem; font-weight: 700; }
.trip-card .destination { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.trip-card .date-badge {
  font-size: 0.72rem; color: var(--primary);
  background: #fef0eb; padding: 2px 8px; border-radius: 20px;
  white-space: nowrap; flex-shrink: 0;
}
.trip-progress { margin-top: 10px; }
.progress-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.3s; }
.progress-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; display: flex; justify-content: space-between; }

/* ── Summary bar ─────────────────────────────────────── */
.summary-bar {
  background: var(--primary); color: white;
  padding: 10px 16px; display: flex; gap: 20px; font-size: 0.8rem;
}
.summary-bar span { display: flex; flex-direction: column; }
.summary-bar strong { font-size: 1rem; }

/* ── Section header ──────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 4px;
  font-size: 0.8rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.btn-text {
  border: none; background: none;
  color: var(--primary); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.btn-text:active { background: var(--bg); }

/* ── Item Card ───────────────────────────────────────── */
.item-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 10px;
  transition: opacity 0.2s;
}
.item-card.purchased { opacity: 0.5; }
.item-thumb {
  width: 52px; height: 52px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0;
  background: var(--bg);
}
.item-thumb-placeholder {
  width: 52px; height: 52px; border-radius: 8px;
  background: #fef0eb; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.item-check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; margin-top: 14px;
  transition: all 0.2s;
}
.item-check.checked { background: var(--success); border-color: var(--success); color: white; }
.item-body { flex: 1; min-width: 0; }
.item-recipient { font-size: 0.72rem; color: var(--primary); font-weight: 700; margin-bottom: 2px; }
.item-name { font-size: 0.88rem; font-weight: 600; line-height: 1.3; }
.item-card.purchased .item-name { text-decoration: line-through; }
.item-price { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.item-price .actual { color: var(--success); font-weight: 600; }
.item-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.btn-small {
  border: none; background: none;
  font-size: 0.85rem; cursor: pointer;
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.btn-small:active { background: var(--bg); }

/* ── Empty state ─────────────────────────────────────── */
.empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: 0.9rem; line-height: 1.8;
}

/* ── Popup menu ──────────────────────────────────────── */
.popup {
  position: fixed; top: 60px; right: 12px; z-index: 100;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  overflow: hidden; min-width: 160px;
}
.popup button {
  display: block; width: 100%; padding: 12px 16px; text-align: left;
  border: none; background: none; font-size: 0.9rem; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.popup button:last-child { border-bottom: none; }
.popup button:active { background: var(--bg); }
.popup button.danger { color: var(--danger); }

/* ── Souvenir Search ─────────────────────────────────── */
.search-bar {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.search-bar input {
  flex: 1; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 0.9rem; font-family: inherit; outline: none;
}
.search-bar input:focus { border-color: var(--primary); }
.search-btn {
  padding: 10px 16px; border: none;
  background: var(--primary); color: white;
  border-radius: 10px; font-size: 0.9rem; font-weight: 700;
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
}
.search-btn:active { background: var(--primary-dark); }

/* ── Filter chips ────────────────────────────────────── */
.filter-chips {
  display: flex; gap: 8px; padding: 8px 16px 4px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 6px 14px; border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; transition: all 0.15s;
}
.chip.active {
  background: var(--primary); color: white; border-color: var(--primary);
}
.chip:active { opacity: 0.8; }

.souvenir-status {
  text-align: center; padding: 24px 16px;
  color: var(--text-muted); font-size: 0.9rem;
}
.souvenir-status.loading::after {
  content: '';
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.7s linear infinite;
  margin-left: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.souvenir-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 12px;
}
.souvenir-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
  cursor: pointer; transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.souvenir-card:active { transform: scale(0.97); }
.souvenir-img {
  width: 100%; aspect-ratio: 1;
  object-fit: cover; background: var(--bg);
}
.souvenir-img-placeholder {
  width: 100%; aspect-ratio: 1;
  background: #fef0eb;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
}
.souvenir-info { padding: 8px 10px 10px; flex: 1; display: flex; flex-direction: column; }
.souvenir-name {
  font-size: 0.78rem; font-weight: 600; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.souvenir-shop { font-size: 0.68rem; color: var(--text-muted); margin-top: 4px; }
.souvenir-price {
  font-size: 0.88rem; font-weight: 700; color: var(--primary);
  margin-top: 6px;
}
.souvenir-add-btn {
  margin-top: 8px; width: 100%; padding: 7px;
  background: var(--primary); color: white;
  border: none; border-radius: 7px;
  font-size: 0.8rem; font-weight: 700; cursor: pointer;
}
.souvenir-add-btn:active { background: var(--primary-dark); }

/* ── Souvenir add preview ────────────────────────────── */
.souvenir-preview {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; background: var(--bg); border-radius: 10px;
  margin-bottom: 4px;
}
.souvenir-preview img {
  width: 56px; height: 56px; border-radius: 8px; object-fit: cover;
}
.souvenir-preview-info { flex: 1; min-width: 0; }
.souvenir-preview-name {
  font-size: 0.82rem; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.souvenir-preview-shop { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Modal ───────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px; width: 100%;
  display: flex; flex-direction: column; gap: 14px;
  max-height: 90dvh; overflow-y: auto;
}
.modal-box h2 { font-size: 1rem; font-weight: 700; }
label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
}
input[type="text"], input[type="number"], input[type="date"], input[type="search"] {
  padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.95rem; font-family: inherit; outline: none;
  transition: border-color 0.2s; -webkit-appearance: none;
}
input:focus { border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn-primary {
  flex: 1; padding: 12px;
  background: var(--primary); color: white;
  border: none; border-radius: 8px;
  font-size: 0.95rem; font-weight: 700; cursor: pointer;
}
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary {
  flex: 1; padding: 12px;
  background: var(--bg); color: var(--text);
  border: none; border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
}

/* ── Overlay ─────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.4);
}
.overlay.hidden { display: none; }

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: white;
  padding: 10px 20px; border-radius: 20px;
  font-size: 0.85rem; z-index: 300; white-space: nowrap;
}
.toast.hidden { display: none; }

/* ── Misc ────────────────────────────────────────────── */
.hidden { display: none !important; }
.archived-badge {
  font-size: 0.7rem; background: #eee; color: #888;
  padding: 2px 8px; border-radius: 20px; margin-left: 6px;
}
