:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a1f2e;
  --muted: #6b7280;
  --primary: #e8521a;
  --primary-dark: #c74415;
  --border: #e5e7eb;
  --success: #059669;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden {
  display: none !important;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}

.app-header .subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  padding: 8px;
  cursor: pointer;
  color: var(--primary);
}

main {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.stats {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-tappable {
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.stat-tappable:active {
  transform: scale(0.98);
}

.stat-tappable.is-active {
  box-shadow: 0 0 0 2px var(--primary);
}

.stat-tappable .label::after {
  content: ' ›';
  color: var(--primary);
}

.archive-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.archive-list-header h2 {
  margin: 0;
  font-size: 1rem;
}

.archive-close-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

.item-row-archived .item-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.item-row-archived .price {
  margin-top: 2px;
}

.archive-search-card {
  margin-top: 16px;
}

.archive-search-card label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.archive-results {
  margin-top: 8px;
}

.item-row-archived .meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.item-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  vertical-align: middle;
}

.stat .num {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
}

.stat .label {
  font-size: 0.75rem;
  color: var(--muted);
}

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

.home-bulk-bar {
  display: flex;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.btn-compact {
  flex: 1;
  padding: 10px 8px;
  font-size: 0.85rem;
}

.home-item-row {
  cursor: default;
  align-items: stretch;
  gap: 8px;
}

.home-item-row .item-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.home-item-row .name {
  max-width: none;
}

.csv-pick-btn {
  flex-shrink: 0;
  align-self: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.1;
  min-width: 44px;
  cursor: pointer;
}

.csv-pick-btn.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.csv-pick-btn.is-exported {
  color: var(--muted);
  background: var(--bg);
  cursor: default;
}

.archive-pick {
  flex-shrink: 0;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.62rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  min-width: 52px;
}

.archive-pick input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.item-row:last-child {
  border-bottom: none;
}

.item-row .name {
  flex: 1;
  font-size: 0.92rem;
  font-weight: 600;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  max-width: 65vw;
}

.item-row .price {
  font-size: 0.85rem;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 10px;
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  margin-top: 10px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 6px;
}

label:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

.preview-box {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.85rem;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
}

.candidate {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  background: #fff;
}

.candidate:active,
.candidate.selected {
  border-color: var(--primary);
  background: #fff7f3;
}

.candidate .title {
  font-weight: 700;
  margin-bottom: 4px;
}

.candidate .meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.divider {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 16px 0;
}

.photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 8px;
  background: #f3f4f6;
  margin-bottom: 12px;
}

.loading {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  max-width: 608px;
  margin: 0 auto;
  background: #1a1f2e;
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 100;
  animation: fadein 0.2s ease;
}

.toast.error {
  background: var(--danger);
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 8px;
}

.section-title:first-child {
  margin-top: 0;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
}

.inventory-matches {
  margin-top: 10px;
}

.inventory-match {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fffbeb;
  cursor: pointer;
}

.inventory-match:active {
  border-color: var(--primary);
}

.inventory-match .match-title {
  font-weight: 600;
  font-size: 0.88rem;
}

.inventory-match .match-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.inventory-match .match-badge {
  display: inline-block;
  font-size: 0.7rem;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 4px;
}

.category-field,
.brand-field {
  margin-bottom: 8px;
}

.category-field .suggest-list,
.brand-field .suggest-list {
  margin-top: 8px;
}

.category-field .suggest-list:not(.hidden),
.brand-field .suggest-list:not(.hidden) {
  display: block;
}

.suggest-list .suggest-empty {
  padding: 12px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.suggest-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.suggest-list li {
  padding: 10px 12px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.suggest-list li:last-child {
  border-bottom: none;
}

.suggest-list li:active,
.suggest-list li.selected {
  background: #fff7f3;
}

.suggest-list .suggest-main {
  font-weight: 600;
}

.suggest-list .suggest-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.input-hscroll {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  max-height: 2.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  resize: none;
  line-height: 1.45;
  -webkit-overflow-scrolling: touch;
  field-sizing: fixed;
}

.size-dims {
  margin-bottom: 12px;
}

.size-dims-label {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.size-dims-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.size-dims-row input {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.size-dims-sep {
  color: var(--muted);
  flex-shrink: 0;
}

.size-dims-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  margin-bottom: 10px;
  cursor: pointer;
}

.size-dims-check input {
  width: auto;
  margin: 0;
}

#size-store-fields {
  margin-top: 4px;
}

.fixed-bottom {
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--bg) 20%);
  padding: 16px 0 8px;
  margin-top: 8px;
}

.item-row .item-date {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
}

