:root {
  --paper: #eaeff1;
  --surface: #ffffff;
  --ink: #15222c;
  --muted: #55656f;
  --line: #b9c6cd;
  --line-soft: #d7e0e5;
  --brand: #1b5b8a;
  --brand-ink: #ffffff;
  --brand-soft: #dcebf5;
  --c-greenhouse: #2e7d5a;
  --c-start: #b86414;
  --c-reduce: #2f6ab8;
  --danger: #b23a2e;
  --ok: #2e7d5a;
  --stake: #ffc457;
  --radius: 6px;
  --nav-h: 60px;
  font-family: 'Pretendard Variable', Pretendard, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: var(--brand); }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--stake); outline-offset: 2px; }

.shell { max-width: 720px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
.shell.no-nav { padding-bottom: 32px; }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; letter-spacing: -0.01em; }
.topbar .who { font-size: 13px; opacity: .85; }
.back { background: none; border: 0; color: inherit; font-size: 15px; padding: 8px 10px 8px 0; cursor: pointer; }

/* 하단 탭 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-inner { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.tab {
  height: var(--nav-h); border: 0; background: none; cursor: pointer;
  font-size: 13px; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; position: relative;
}
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current='page'] { color: var(--brand); font-weight: 700; }
.tab[aria-current='page']::before { content: ''; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; background: var(--brand); }

.page { padding: 14px 16px 0; display: grid; gap: 14px; }

/* 날짜 막대 */
.datebar { display: grid; grid-template-columns: 44px 1fr 44px; gap: 8px; align-items: center; }
.datebar input[type=date] { text-align: center; font-weight: 700; font-size: 17px; }
.iconbtn { height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); cursor: pointer; font-size: 18px; }
.today-link { justify-self: center; font-size: 14px; background: none; border: 0; color: var(--brand); text-decoration: underline; cursor: pointer; padding: 4px; }

/* 칩 */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 14px; font-size: 15px; cursor: pointer; min-height: 40px;
}
.chip[aria-pressed='true'] { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

.summary { font-size: 14px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.summary b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* 버튼 */
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: var(--radius); border: 1.5px solid var(--brand);
  background: var(--surface); color: var(--brand); font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; text-align: center;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.quiet { border-color: var(--line); color: var(--ink); font-weight: 500; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .grow { flex: 1; }

/* 폼 */
.field { display: grid; gap: 6px; }
.field > label, .field > .lab { font-size: 14px; font-weight: 700; color: var(--muted); }
.field .hint { font-size: 13px; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=date], input[type=search], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1.5px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
textarea { min-height: 150px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { min-height: 46px; border: 0; background: none; cursor: pointer; font-weight: 500; border-right: 1px solid var(--line-soft); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed='true'] { background: var(--ink); color: #fff; font-weight: 700; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 14px; }
.panel h2 { font-size: 16px; }

/* 현장 목록: 줄 + 구분색 막대 */
.sites { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.site {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px;
  padding: 12px 12px 12px 0; border-bottom: 1px solid var(--line-soft); cursor: pointer; position: relative;
  text-decoration: none; color: inherit; background: var(--surface); width: 100%; text-align: left; border-left: 0; border-top: 0; border-right: 0;
}
.site:last-child { border-bottom: 0; }
.site::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--cat, var(--line)); }
.site .no { text-align: center; font-weight: 700; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; padding-left: 5px; }
.site .lot { font-size: 17px; font-weight: 700; line-height: 1.3; word-break: keep-all; }
.site .addr { font-size: 13px; color: var(--muted); word-break: keep-all; }
.site .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; font-size: 13px; }
.tag { font-weight: 700; color: var(--cat); }
.ref { background: var(--paper); padding: 0 6px; border-radius: 3px; font-variant-numeric: tabular-nums; }
.warn { color: var(--danger); font-weight: 700; }
.photos-n { font-variant-numeric: tabular-nums; text-align: right; font-size: 14px; color: var(--muted); }
.photos-n b { display: block; font-size: 18px; color: var(--ink); }
.site.done .lot { text-decoration: line-through; text-decoration-color: var(--ok); text-decoration-thickness: 2px; color: var(--muted); }
.donemark { color: var(--ok); font-weight: 700; }
.cat-온실 { --cat: var(--c-greenhouse); }
.cat-착공 { --cat: var(--c-start); }
.cat-감면 { --cat: var(--c-reduce); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); display: grid; gap: 12px; justify-items: center; }
.empty strong { color: var(--ink); font-size: 17px; }

/* 사진 칸: 보고서의 5칸과 같은 모양 (필지 경계 점선) */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.slot {
  aspect-ratio: 4 / 3; border: 2px dashed var(--line); border-radius: 4px; position: relative; overflow: hidden;
  display: grid; place-items: center; color: var(--line); font-weight: 700; font-size: 22px; background: var(--paper);
  font-variant-numeric: tabular-nums;
}
.slot.filled { border: 2px solid var(--ink); background: #000; padding: 0; cursor: zoom-in; }
.slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot .badge { position: absolute; left: 4px; top: 4px; background: rgba(21,34,44,.8); color: #fff; font-size: 12px; padding: 0 6px; border-radius: 3px; }
.slot.pending { border-color: var(--brand); color: var(--brand); font-size: 13px; text-align: center; padding: 4px; }
.slot.failed { border-color: var(--danger); color: var(--danger); font-size: 13px; cursor: pointer; text-align: center; padding: 4px; }
.slot .spin { width: 22px; height: 22px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.slot.more { border-style: dotted; }

.shoot { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.status { font-size: 13px; color: var(--muted); min-height: 20px; }
.status.err { color: var(--danger); font-weight: 700; }
.status.ok { color: var(--ok); }

.notice { background: #fff6dd; border: 1px solid #e8cf86; border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.notice.err { background: #fbe9e7; border-color: #e3a9a2; }

.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.list-plain li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.list-plain li:last-child { border-bottom: 0; }

/* 경로 */
.legs { display: grid; gap: 12px; }
.leg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.leg > header { padding: 10px 12px; background: var(--ink); color: #fff; font-weight: 700; border-radius: var(--radius) var(--radius) 0 0; display: flex; justify-content: space-between; gap: 8px; }
.leg ol { margin: 0; padding: 8px 12px 8px 36px; }
.leg li { padding: 4px 0; font-size: 15px; }
.leg li small { color: var(--muted); display: block; }
.leg .row { padding: 0 12px 12px; }

/* 사진 크게 보기 */
.viewer { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.92); display: grid; grid-template-rows: 1fr auto; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.viewer img { max-width: 100%; max-height: 100%; margin: auto; object-fit: contain; }
.viewer .bar { display: flex; gap: 10px; padding: 12px 16px; justify-content: space-between; }
.viewer .btn { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.4); }
.viewer .btn.danger { color: #ffb4ab; border-color: #ffb4ab; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 200;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 15px; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 로그인 */
.login { max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top)) 20px 40px; display: grid; gap: 18px; }
.login .brandmark { display: flex; align-items: center; gap: 12px; }
.login .brandmark img { width: 52px; height: 52px; border-radius: 12px; }
.login h1 { font-size: 24px; letter-spacing: -0.02em; }
.login .sub { color: var(--muted); font-size: 14px; }

.progress { height: 8px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .2s; }

@media (min-width: 760px) {
  .page { padding-top: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* v2: 기타 구분, 팀, 재방문, 메모, 엑셀 업로드 */
:root { --c-etc: #6b5b95; --revisit: #c0392b; }
.cat-기타 { --cat: var(--c-etc); }
.team { color: var(--ink); font-weight: 700; }
.team::before { content: '· '; color: var(--muted); font-weight: 400; }
.revisit { background: var(--revisit); color: #fff; font-weight: 700; padding: 0 6px; border-radius: 3px; }
.memo-line { font-size: 13px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.site > div { min-width: 0; }
.grid-gap { display: grid; gap: 14px; }
.steps { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.step { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; align-content: start; }
.step .btn { justify-self: start; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: 420px; overflow-y: auto; }
table.preview { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--surface); }
table.preview th { position: sticky; top: 0; background: var(--paper); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.preview td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.preview td:first-child { color: var(--muted); font-variant-numeric: tabular-nums; }
table.preview tr.bad td { background: #fbe9e7; }
.err-msg { color: var(--danger); font-weight: 700; font-size: 12px; }
.check-row, .revisit-row { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; min-height: 32px; }
.check-row input, .revisit-row input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.revisit-row { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.revisit-row:has(input:checked) { border-color: var(--revisit); background: #fbe9e7; }
.revisit-row input { accent-color: var(--revisit); }
.help ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.seg button { padding: 0 6px; }
table.preview td:nth-child(2), table.preview td:nth-child(3), table.preview td:nth-child(4) { white-space: nowrap; }
.datetag { font-weight: 700; color: var(--ink); background: var(--brand-soft); padding: 0 6px; border-radius: 3px; }

/* v3: 이월, 실적 집계 */
.sec-title { font-size: 15px; margin: 4px 0 8px; color: var(--ink); }
.sec-sub { font-size: 15px; margin: 6px 0 0; }
section.carry .sites { border-color: var(--stake); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 10px; display: grid; gap: 2px; }
.stat span { font-size: 13px; color: var(--muted); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
table.preview td:nth-child(n+2) { font-variant-numeric: tabular-nums; }
