/* 현장조사용 앱 — 모바일/태블릿 우선 스타일
 * 원칙(계획서 11장): 큰 버튼 · 최소 타이핑 · 장갑 낀 손으로도 눌리는 터치 영역(48px 이상)
 */
:root {
  --green: #2E7D32;
  --green-light: #63CA3E;
  --green-dark: #1B5E20;
  --blue: #1E88E5;
  --purple: #8E24AA;
  --red: #E53935;
  --amber: #F9A825;
  --gray-0: #ffffff;
  --gray-1: #F6F7F5;
  --gray-2: #ECEFEA;
  --gray-3: #D7DCD5;
  --gray-5: #8A918A;
  --gray-7: #4A504A;
  --gray-9: #1D211D;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .08);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .18);
  --tap: 52px;
  --header-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Malgun Gothic',
    '맑은 고딕', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  background: var(--gray-1);
  color: var(--gray-9);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------- 레이아웃 */
#app { min-height: 100%; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px;
  background: var(--green);
  color: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .18);
}

.appbar h1 {
  font-size: 17px; font-weight: 700; margin: 0;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.appbar .sub { font-size: 12px; font-weight: 400; opacity: .85; display: block; }

.iconbtn {
  min-width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; color: inherit;
  font-size: 20px; border-radius: 12px; cursor: pointer; padding: 0 10px;
}
.iconbtn:active { background: rgba(255, 255, 255, .18); }

main { flex: 1; padding: 12px 12px calc(96px + var(--safe-b)); max-width: 900px; width: 100%; margin: 0 auto; }

.offline-bar {
  display: none; background: var(--amber); color: #3b2c00;
  font-size: 13px; font-weight: 600; text-align: center; padding: 6px 10px;
}
body.is-offline .offline-bar { display: block; }

/* ------------------------------------------------------------- 카드 */
.card {
  background: var(--gray-0); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card.tight { padding: 10px 12px; }
.card h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; color: var(--gray-7); }
.card .hint { font-size: 13px; color: var(--gray-5); margin: 4px 0 0; }

.section-title {
  font-size: 13px; font-weight: 700; color: var(--gray-5);
  letter-spacing: .02em; margin: 18px 4px 8px; text-transform: none;
}

/* ------------------------------------------------------------- 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border: 0; border-radius: 12px;
  background: var(--gray-2); color: var(--gray-9);
  font-size: 16px; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--green); color: #fff; }
.btn.accent { background: var(--green-light); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--gray-3); }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 40px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 auto; }

.fab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: linear-gradient(to top, rgba(246, 247, 245, 1) 60%, rgba(246, 247, 245, 0));
  display: flex; gap: 8px; max-width: 900px; margin: 0 auto;
}
.fab-bar > .btn { flex: 1; box-shadow: var(--shadow-lg); }

/* ------------------------------------------------------------- 폼 */
label.field, div.field { display: block; margin-bottom: 12px; }
label.field > span, div.field > span {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--gray-7); margin-bottom: 5px;
}
label.field > span .req { color: var(--red); }

input[type=text], input[type=number], input[type=date], input[type=url],
input[type=password], textarea, select {
  width: 100%; min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-3); border-radius: 10px;
  background: #fff; color: var(--gray-9);
  font-size: 16px; font-family: inherit;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(46, 125, 50, .14);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

.inline-mic { display: flex; gap: 8px; align-items: flex-start; }
.inline-mic textarea, .inline-mic input { flex: 1; }
.micbtn {
  min-width: 48px; height: 48px; border-radius: 12px;
  border: 1.5px solid var(--gray-3); background: #fff;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.micbtn.rec { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* 선택칩 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 46px; padding: 0 14px; border-radius: 23px;
  border: 1.5px solid var(--gray-3); background: #fff;
  font-size: 15px; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
.chip.on.warn { background: var(--amber); border-color: var(--amber); color: #3b2c00; }

/* ------------------------------------------------------------- 판정 버튼 */
.burden-item {
  border: 1.5px solid var(--gray-2); border-radius: var(--radius);
  margin-bottom: 10px; overflow: hidden; background: #fff;
}
.burden-item.set-O { border-color: var(--red); }
.burden-item.set-T { border-color: var(--amber); }

.burden-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  cursor: pointer; user-select: none;
}
.burden-no {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px;
  background: var(--gray-2); color: var(--gray-7);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px;
}
.burden-item.set-O .burden-no { background: var(--red); color: #fff; }
.burden-item.set-T .burden-no { background: var(--amber); color: #3b2c00; }
.burden-title { flex: 1; min-width: 0; }
.burden-title b { display: block; font-size: 15px; }
.burden-title small { color: var(--gray-5); font-size: 12.5px; }
.burden-caret { color: var(--gray-5); font-size: 13px; }

.judge-row { display: flex; gap: 8px; padding: 0 12px 12px; }
.judge-btn {
  flex: 1; min-height: 54px; border-radius: 12px;
  border: 2px solid var(--gray-3); background: #fff;
  font-size: 20px; font-weight: 800; font-family: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.judge-btn small { font-size: 11px; font-weight: 600; opacity: .75; }
.judge-btn.j-o.on { background: var(--red); border-color: var(--red); color: #fff; }
.judge-btn.j-t.on { background: var(--amber); border-color: var(--amber); color: #3b2c00; }
.judge-btn.j-x.on { background: var(--gray-7); border-color: var(--gray-7); color: #fff; }

.burden-detail {
  display: none; padding: 0 12px 12px; border-top: 1px dashed var(--gray-2);
  margin-top: 2px; padding-top: 10px;
}
.burden-item.open .burden-detail { display: block; }
.criteria {
  background: var(--gray-1); border-left: 4px solid var(--green-light);
  border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px;
}
.criteria .keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.criteria .keys span {
  background: #fff; border: 1px solid var(--gray-3); border-radius: 20px;
  padding: 3px 10px; font-size: 12.5px; font-weight: 600; color: var(--green-dark);
}
.criteria .tip { display: block; margin-top: 8px; color: var(--gray-5); font-size: 12.5px; }

/* ------------------------------------------------------------- 단위작업 카드 */
.unit-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  border-left: 6px solid var(--gray-3); display: block; text-decoration: none; color: inherit;
}
.unit-card.done { border-left-color: var(--green); }
.unit-card.partial { border-left-color: var(--amber); }
.unit-card .t { display: flex; align-items: baseline; gap: 8px; }
.unit-card .t b { font-size: 16px; }
.unit-card .t em { font-style: normal; font-size: 12.5px; color: var(--gray-5); }
.unit-card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  font-size: 12px; font-weight: 700; border-radius: 20px; padding: 3px 9px;
  background: var(--gray-2); color: var(--gray-7);
}
.badge.o { background: #FDE7E7; color: #B71C1C; }
.badge.t { background: #FFF4D6; color: #7A5B00; }
.badge.p { background: #E3F0FD; color: #0D47A1; }
.badge.s { background: #E7F3E5; color: var(--green-dark); }
.badge.miss { background: #FFEBEE; color: #B71C1C; }

/* 진행률 */
.progress { height: 10px; border-radius: 6px; background: var(--gray-2); overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--green-light); transition: width .3s; }
.stat-row { display: flex; gap: 10px; text-align: center; }
.stat-row > div { flex: 1; background: var(--gray-1); border-radius: 10px; padding: 8px 4px; }
.stat-row b { display: block; font-size: 20px; color: var(--green-dark); }
.stat-row span { font-size: 12px; color: var(--gray-5); }

/* ------------------------------------------------------------- 미디어 */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.media-tile {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: var(--gray-2); cursor: pointer; border: 0; padding: 0;
}
.media-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile .k {
  position: absolute; left: 4px; bottom: 4px; font-size: 10px; font-weight: 700;
  background: rgba(0, 0, 0, .62); color: #fff; padding: 2px 6px; border-radius: 10px;
}
.media-tile .vid {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff; background: #263238;
}
.media-add {
  aspect-ratio: 1; border: 2px dashed var(--gray-3); border-radius: 10px;
  background: #fff; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; font-size: 12px; color: var(--gray-5);
  cursor: pointer; font-family: inherit;
}
.media-add span { font-size: 22px; }

/* ------------------------------------------------------------- 모달/시트 */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--gray-1); width: 100%; max-width: 900px;
  max-height: 92vh; border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(20px); opacity: .4; } }
.sheet-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--gray-2); background: #fff; border-radius: 18px 18px 0 0;
}
.sheet-head b { flex: 1; font-size: 16px; }
.sheet-body { overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  display: flex; gap: 8px; padding: 10px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--gray-2); background: #fff;
}
.sheet-foot .btn { flex: 1; }
.sheet.full { max-height: 100vh; height: 100%; border-radius: 0; }

.toast-wrap {
  position: fixed; left: 0; right: 0; bottom: calc(80px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: rgba(29, 33, 29, .94); color: #fff; padding: 10px 16px;
  border-radius: 22px; font-size: 14px; font-weight: 600; max-width: 88vw;
  box-shadow: var(--shadow-lg); animation: up .16s ease-out;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* ------------------------------------------------------------- 펜 패드 */
.pad-wrap {
  background: #fff; border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow); display: flex; justify-content: center;
}
.pad-canvas { width: 100%; height: auto; display: block; touch-action: none; }
.pad-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--gray-3); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--green); }
.tool-btn {
  min-width: 46px; height: 44px; border-radius: 10px; border: 1.5px solid var(--gray-3);
  background: #fff; font-size: 17px; cursor: pointer; font-family: inherit;
}
.tool-btn.on { background: var(--green); color: #fff; border-color: var(--green); }

/* ------------------------------------------------------------- 기타 */
.empty { text-align: center; padding: 40px 16px; color: var(--gray-5); }
.empty .ico { font-size: 44px; display: block; margin-bottom: 10px; opacity: .5; }
.list-link {
  display: flex; align-items: center; gap: 10px; padding: 14px 12px;
  background: #fff; border-radius: 12px; margin-bottom: 8px;
  text-decoration: none; color: inherit; box-shadow: var(--shadow); cursor: pointer;
}
.list-link .ico { font-size: 22px; width: 32px; text-align: center; }
.list-link .tx { flex: 1; min-width: 0; }
.list-link .tx b { display: block; font-size: 15px; }
.list-link .tx small { color: var(--gray-5); font-size: 12.5px; }
.list-link .go { color: var(--gray-3); font-size: 18px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--gray-2); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--gray-5); }
.kv b { font-weight: 600; text-align: right; word-break: break-all; }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 10px; }
.alert.warn { background: #FFF8E1; border-left: 4px solid var(--amber); }
.alert.err { background: #FFEBEE; border-left: 4px solid var(--red); }
.alert.ok { background: #E8F5E9; border-left: 4px solid var(--green); }
.alert.info { background: #E3F2FD; border-left: 4px solid var(--blue); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.score-box {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--green-dark); color: #fff; border-radius: 12px; padding: 12px; margin-top: 10px;
}
.score-box b { font-size: 30px; line-height: 1; }
.score-box span { font-size: 13px; opacity: .9; }

@media (min-width: 720px) {
  main { padding: 16px 16px calc(96px + var(--safe-b)); }
  .judge-btn { min-height: 60px; }
}
