:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #7a8088;
  --accent: #2f6fed;
  --accent-soft: #e8effd;
  --danger: #d64545;
  --ok: #1f9d55;
  --border: #e3e6ea;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Pretendard", "Noto Sans KR", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

header.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 16px 0;
}
.appbar h1 { font-size: 18px; margin: 0; padding: 14px 0 8px; }
nav.tabs { display: flex; gap: 4px; padding-bottom: 8px; }
nav.tabs a {
  flex: 1;
  text-align: center;
  padding: 9px 0;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
nav.tabs a.active { background: var(--accent-soft); color: var(--accent); }

main { padding: 16px; max-width: 720px; margin: 0 auto; padding-bottom: 48px; }

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

button {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.danger { background: #fdeaea; color: var(--danger); }
button.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
button.block { width: 100%; }

input, select {
  font: inherit;
  font-size: 16px; /* iOS 확대 방지 */
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  width: 100%;
}
label.fld { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.fld > span { display: block; margin-bottom: 4px; font-weight: 600; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }
.ok { color: var(--ok); }

/* 업로드 */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  background: var(--card);
  color: var(--muted);
  margin-bottom: 14px;
}
.dropzone strong { color: var(--accent); }

.filelist { list-style: none; margin: 0 0 14px; padding: 0; }
.filelist li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14px;
}
.filelist .status { font-size: 13px; font-weight: 700; white-space: nowrap; }
.status.wait { color: var(--muted); }
.status.busy { color: var(--accent); }
.status.done { color: var(--ok); }
.status.fail { color: var(--danger); }

/* 품목 편집 */
.item-row {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.item-row .row2 {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.item-row .row2 input, .item-row .row2 select { flex: 1 1 64px; min-width: 0; }
.item-row .row2 .f-cat { flex: 1.4 1 90px; }
.item-row .row2 button { flex: 0 0 auto; }
.item-row input.num { text-align: right; }

/* 검증 경고 */
.item-row.item-warn { background: #fff8e6; border-radius: 8px; padding: 10px 8px; }
.warn-msg {
  grid-column: 1 / -1;
  color: #9a6b00;
  font-size: 12.5px;
  line-height: 1.5;
  margin-bottom: 2px;
}
.warn-banner {
  background: #fff3cd;
  border: 1px solid #f5d989;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  color: #7a5c00;
  font-size: 13.5px;
  line-height: 1.55;
}

/* 검색 결과 */
.best-card {
  background: linear-gradient(135deg, #2f6fed, #5b8cff);
  color: #fff;
  border: none;
}
.best-card .muted { color: rgba(255, 255, 255, 0.8); }
.best-card .price { font-size: 28px; font-weight: 800; margin: 6px 0 2px; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  padding: 3px 10px;
}

table.compare { width: 100%; border-collapse: collapse; font-size: 14px; }
table.compare th, table.compare td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
table.compare th { color: var(--muted); font-size: 12px; font-weight: 600; }
table.compare td.num, table.compare th.num { text-align: right; white-space: nowrap; }

/* 리스트 */
a.rowlink { text-decoration: none; color: inherit; display: block; }
.receipt-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.receipt-row .total { font-weight: 800; white-space: nowrap; }

.searchbar { display: flex; gap: 8px; margin-bottom: 16px; }
.searchbar input { flex: 1; }
.searchbar button { white-space: nowrap; }

.empty { text-align: center; color: var(--muted); padding: 36px 0; }
