/* 현장관리앱 v2 — 모바일 우선 스타일
   업장 색상은 --brand 계열 변수로 바뀜 (brand.js에서 설정) */

:root {
  --brand: #F07A1A;
  --brand-ink: #ffffff;
  --brand-soft: #FEF1E6;
  --brand-line: #F8C9A3;
  --brand-deep: #9C4F11;

  --bg: #F6F5F2;
  --surface: #ffffff;
  --text: #1E1E1C;
  --muted: #6B6A66;
  --faint: #9A9893;
  --line: #E6E4DF;
  --danger: #C0392B;
  --danger-soft: #FCEBEA;
  --ok: #2E7D4F;
  --ok-soft: #E6F4EC;
  --warn: #8A5A00;
  --warn-soft: #FDF3DC;

  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-size: 16px; line-height: 1.55; -webkit-tap-highlight-color: transparent; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0 0 .75rem; }
a { color: var(--brand-deep); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- 레이아웃 ---------- */
.page { padding: 16px 16px calc(24px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.page.with-nav { padding-bottom: calc(var(--nav-h) + 24px + var(--safe-b)); }
.narrow { max-width: 440px; }
.center-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; }

.splash { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: var(--brand-soft); border-bottom: 1px solid var(--brand-line);
}
.topbar .title { font-weight: 600; font-size: 17px; color: var(--brand-deep); line-height: 1.2; }
.topbar .sub { font-size: 13px; color: var(--brand-deep); opacity: .85; }
.topbar.plain { background: var(--surface); border-bottom-color: var(--line); }
.topbar.plain .title, .topbar.plain .sub { color: var(--text); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: inherit; flex: none;
}
.icon-btn:active { background: rgba(0,0,0,.06); }

.logo-mark {
  width: 36px; height: 36px; border-radius: 10px; flex: none; overflow: hidden;
  background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 16px;
}
.logo-mark img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.logo-mark.lg { width: 72px; height: 72px; border-radius: 20px; font-size: 30px; }

/* 하단 메뉴 */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.bottomnav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--faint); font-size: 12px;
}
.bottomnav a.on { color: var(--brand); font-weight: 600; }
.bottomnav svg { width: 24px; height: 24px; }

/* ---------- 카드, 목록 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.card h2, .card h3 { margin-bottom: 8px; }
.section-label { font-size: 13px; color: var(--muted); margin: 20px 4px 8px; font-weight: 500; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  text-decoration: none; color: inherit; border-top: 1px solid var(--line);
}
.list-item:first-child { border-top: 0; }
.list-item:active { background: var(--bg); }
.chev { color: var(--faint); flex: none; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .big { font-size: 15px; color: var(--text); font-weight: 500; margin-bottom: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 3px 8px; border-radius: 999px; font-weight: 500; white-space: nowrap;
  background: var(--bg); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand-deep); }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 16px; cursor: pointer; text-decoration: none; text-align: center;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; cursor: default; }
.btn.block { display: flex; width: 100%; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.soft { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-deep); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: var(--radius-sm); }
.btn.kakao { background: #FEE500; border-color: #FEE500; color: rgba(0,0,0,.85); }
.btn.kakao svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }

/* ---------- 입력 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field .hint { display: block; font-size: 13px; color: var(--faint); margin-top: 6px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], textarea, select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-line); border-color: var(--brand); }
.prefix-input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.prefix-input .pre { padding: 0 10px; display: flex; align-items: center; color: var(--faint); background: var(--bg); font-size: 14px; white-space: nowrap; }
.prefix-input input { border: 0; border-radius: 0; }
.prefix-input:focus-within { outline: 2px solid var(--brand-line); border-color: var(--brand); }
.prefix-input input:focus { outline: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line);
  cursor: pointer; padding: 0;
}
.swatch.on { box-shadow: 0 0 0 2px var(--text); }
.color-input {
  -webkit-appearance: none; appearance: none; width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; background: none; cursor: pointer; overflow: hidden;
}
.color-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-input::-webkit-color-swatch { border: 0; border-radius: 50%; }
.color-input::-moz-color-swatch { border: 0; border-radius: 50%; }
.swatch-custom { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

.error { color: var(--danger); font-size: 14px; margin: 6px 0 0; }

/* ---------- 로그인, 초대 화면 ---------- */
.hero { text-align: center; padding: 8px 0 24px; }
.hero .logo-mark { margin: 0 auto 16px; }
.hero h1 { font-size: 24px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 13px; margin: 20px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.guide { list-style: none; margin: 0; padding: 0; }
.guide-step { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.guide-step:first-child { border-top: 0; }
.guide-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-size: 14px; font-weight: 600; flex: none;
}
.guide-icon { color: var(--brand-deep); display: grid; place-items: center; flex: none; }

/* 관리자: 휴대폰 미리보기 */
.preview-phone { border: 1px solid var(--line); border-radius: 20px; overflow: hidden; background: var(--bg); max-width: 300px; margin: 0 auto; }
.preview-phone .topbar { position: static; }
.preview-phone .pv-body { padding: 14px; }
.preview-phone .pv-btn { background: var(--brand); color: var(--brand-ink); border-radius: 10px; padding: 10px; text-align: center; font-weight: 500; font-size: 14px; }

.color-dot { width: 12px; height: 40px; border-radius: 6px; flex: none; }

.link-box {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all;
  background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
}

/* 알림 */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + var(--safe-b)); transform: translate(-50%, 20px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .page { padding-top: 24px; }
}
