/* 현장관리앱 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); }

/* ---------- 2단계: 현장 ---------- */
.inline-loading { display: grid; place-items: center; padding: 56px 0; }
.back-link { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: 14px; padding: 4px 4px 4px 0; margin-bottom: 4px; }
.item-title { font-weight: 500; }
.site-no {
  display: inline-flex; align-items: center; flex: none; font-weight: 700; font-size: 13px; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 6px; background: var(--brand-soft); color: var(--brand-deep);
  font-variant-numeric: tabular-nums; border: 0; font-family: inherit;
}
.site-no.lg { font-size: 15px; padding: 4px 10px; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: 15px; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.chip[disabled] { cursor: default; }
input[type=search] {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; -webkit-appearance: none; appearance: none;
}
input[type=search]:focus { outline: 2px solid var(--brand-line); border-color: var(--brand); }
.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; min-width: 0; }
.input-row .btn { flex: none; }
.check-row {
  display: flex; gap: 12px; align-items: flex-start; padding: 16px; cursor: pointer;
  border: 1px solid var(--brand-line); border-radius: var(--radius); background: var(--brand-soft);
}
.check-row input { width: 24px; height: 24px; accent-color: var(--brand); flex: none; margin: 2px 0 0; }

.info-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.info-row:first-child { border-top: 0; }
.info-row .k { width: 68px; flex: none; color: var(--muted); font-size: 14px; }
.info-row .v { word-break: break-all; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photo-grid .ph {
  aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg); border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center;
}
.photo-grid .ph img { width: 100%; height: 100%; object-fit: cover; }
.photo-grid .ph-empty { grid-column: 1 / -1; padding: 14px 0; text-align: center; }

.overlay { position: fixed; inset: 0; z-index: 50; background: var(--surface); display: flex; flex-direction: column; }
.overlay-bar {
  display: flex; align-items: center; gap: 8px; font-weight: 600;
  padding: calc(8px + var(--safe-t)) 8px 8px 16px; border-bottom: 1px solid var(--line);
}
.pc-box { flex: 1; min-height: 0; }
.viewer { background: #000; color: #fff; }
.viewer .overlay-bar { border-bottom-color: #222; }
.viewer .stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; touch-action: pan-y; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border: 0;
  background: rgba(0,0,0,.35); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.viewer .nav.prev { left: 0; border-radius: 0 8px 8px 0; }
.viewer .nav.next { right: 0; border-radius: 8px 0 0 8px; }
.viewer .actions { display: flex; gap: 8px; padding: 12px 16px calc(12px + var(--safe-b)); }
.viewer .actions .btn { flex: 1; background: #1c1c1c; border-color: #333; color: #fff; }
.viewer .actions .btn.danger { color: #ff8a80; }

/* ---------- 3단계: 일정 ---------- */
:root { --k1: #2F6FD6; --k2: #F07A1A; --k3: #1D9E75; --k4: #C0392B; --k5: #8A8780; }
.k1 { --k: var(--k1); } .k2 { --k: var(--k2); } .k3 { --k: var(--k3); } .k4 { --k: var(--k4); } .k5 { --k: var(--k5); }
.cal-head { display: flex; align-items: center; gap: 4px; margin: 0 0 8px; }
.cal-head h2 { margin: 0 4px; font-size: 19px; }
.cal-card { padding: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 6px; }
.cal-wd.sun, .cal-day.sun .num { color: #D0453A; }
.cal-wd.sat, .cal-day.sat .num { color: #2F6FD6; }
.cal-day {
  aspect-ratio: 1 / 1.05; border: 0; background: none; border-radius: 10px; cursor: pointer; padding: 4px 0 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 15px; color: var(--text);
}
.cal-day.out { opacity: .35; }
.cal-day .num { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { border: 1.5px solid var(--brand); font-weight: 600; }
.cal-day.sel { background: var(--brand-soft); }
.cal-day.sel .num { background: var(--brand); color: var(--brand-ink) !important; font-weight: 600; }
.cal-day .dots { display: flex; gap: 3px; align-items: center; min-height: 8px; }
.cal-day .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--k); }
.cal-day .dots b { font-size: 11px; color: var(--brand-deep); font-weight: 700; line-height: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; background: var(--k); display: inline-block; }
.kind-tag {
  font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap;
  color: var(--k); background: color-mix(in srgb, var(--k) 12%, white);
}
.appt .appt-time { width: 56px; flex: none; text-align: center; color: var(--muted); }
.appt .appt-time .t { font-size: 17px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.appt.past { opacity: .5; }
.one-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239A9893' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}
input[type=date], input[type=time] {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
input[type=date]:focus, input[type=time]:focus { outline: 2px solid var(--brand-line); border-color: var(--brand); }

/* ---------- 4단계: 장부, 직원 ---------- */
.big-number { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.big-number.neg, .neg { color: var(--danger); }
.sum-val { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.in { color: #1F63B5; }
.amount.out { color: #B4501A; }
.entry .entry-date { width: 40px; flex: none; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: auto; display: block; margin-top: 4px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: #CFCCC5; stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--muted); font-family: inherit; }
.chart .tick.cur { fill: var(--text); font-weight: 700; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit.on { fill: rgba(0,0,0,.045); }
.chart .hit:focus-visible { stroke: var(--brand); stroke-width: 1.5; }
.legend-row { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend-row span { display: inline-flex; align-items: center; gap: 6px; }
.chart-info { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; padding: 8px 2px 0; color: var(--text); }
.chart-info span { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.table-toggle { margin-top: 10px; font-size: 13px; }
.table-toggle summary { color: var(--muted); cursor: pointer; padding: 4px 0; }
.mini-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
.mini-table th, .mini-table td { text-align: right; padding: 6px 4px; border-top: 1px solid var(--line); }
.mini-table th:first-child, .mini-table td:first-child { text-align: left; }
.mini-table th { color: var(--muted); font-weight: 500; border-top: 0; }
.mini-table tr.cur td { font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn { min-height: 48px; border: 0; background: var(--surface); font-size: 16px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.in.on { background: #E8F1FC; color: #1F63B5; }
.seg-btn.out.on { background: #FDEEE6; color: #B4501A; }
.amount-input { font-size: 22px !important; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin: 6px 0 4px; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.perm-list { list-style: none; padding: 0; margin: 0 0 14px; }
.perm-list li { padding: 4px 0 4px 22px; position: relative; }
.perm-list li::before { position: absolute; left: 0; font-weight: 700; }
.perm-list li.ok::before { content: '✓'; color: var(--ok); }
.perm-list li.no::before { content: '✕'; color: var(--danger); }

/* 6단계: 고객 관리 */
.icon-btn.faint { opacity: .35; }
.icon-btn.faint:hover, .icon-btn.faint:focus-visible { opacity: .8; }
.same-cust { border-color: var(--warn); background: var(--warn-soft); }
.same-cust > .row { color: var(--warn); }
.same-cust.bad { border-color: var(--danger); background: var(--danger-soft); }
.same-cust.bad > .row { color: var(--danger); }
.same-cust .list { background: var(--surface); }
.sheet-bg { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); }

/* 7단계: 목록 편집 */
.chip.edit-chip { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px 0 12px; cursor: default; }
.chip.edit-chip .mini { border: 0; background: none; font-size: 18px; line-height: 1; min-width: 30px; min-height: 36px; color: var(--muted); cursor: pointer; border-radius: 999px; }
.chip.edit-chip .mini:active { background: var(--bg); }

@media (min-width: 720px) {
  .page { padding-top: 24px; }
}
