/* ─────────────────────────────────────────────────────────────
   금형 MES 웹 - 현장용 (휴대폰·태블릿 먼저, 큰 글씨·큰 버튼)
   색은 VB 프로그램과 맞춤 : 머리 #2c3e50(52,73,94), 완료 연두, 작업중 하늘, 주의 노랑, 지연 주황
   ───────────────────────────────────────────────────────────── */
:root {
  --head: #34495e;
  --head-dark: #2c3e50;
  --bg: #f3f5f8;
  --card: #ffffff;
  --line: #d5dbe3;
  --text: #1f2933;
  --muted: #5f6b7a;
  --primary: #2962af;
  --start: #2e8b57;
  --done: #2962af;
  --pause: #d6781e;
  --c-done: #e2efda;
  --c-run: #ddebf7;
  --c-warn: #fff2cc;
  --c-danger: #f8cbad;
  --red: #c0392b;
  --tap: 56px;            /* 손가락으로 누르는 최소 높이 */
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "맑은 고딕", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 17px; line-height: 1.45;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, select { font: inherit; color: inherit; }

/* ── 버튼 ── */
.btn {
  min-height: 44px; padding: 8px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: bold; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.6); color: #fff; }
.btn.big { min-height: var(--tap); font-size: 19px; padding: 10px 22px; }
.btn:focus-visible, .act:focus-visible, .tab:focus-visible, .rout:focus-visible, .card:focus-visible { outline: 3px solid #f1c40f; outline-offset: 2px; }

input, select {
  min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}

/* ── 로그인 ── */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--head-dark); }
.login-box { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 26px 22px; display: flex; flex-direction: column; gap: 6px; }
.login-box h1 { margin: 0; font-size: 26px; text-align: center; color: var(--head-dark); }
.login-box h1 span:not(:empty)::after { content: " "; }
.login-box .sub { margin: 0 0 12px; text-align: center; color: var(--muted); }
.login-box label { font-weight: bold; margin-top: 8px; }
.login-box input { min-height: var(--tap); font-size: 20px; }
.login-box .btn { margin-top: 14px; }
.msg { color: var(--red); min-height: 1.4em; margin: 6px 0 0; }
.recent .label { margin: 0 0 6px; color: var(--muted); font-size: 15px; }
.recent-list { display: flex; flex-wrap: wrap; gap: 8px; }
.recent-list .btn { min-height: 52px; font-size: 18px; flex: 1 1 30%; }

/* ── 앱 틀 ── */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  background: var(--head); color: #fff; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
}
.brand { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand #company:not(:empty)::after { content: " "; }
.spacer { flex: 1; }
.user { font-weight: bold; font-size: 18px; white-space: nowrap; }
.content { flex: 1; padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }

/* 탭 : 휴대폰 = 아래 고정, 넓은 화면 = 위 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; min-height: 64px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 14px; color: var(--muted); cursor: pointer; touch-action: manipulation;
}
.tab .ico { font-size: 20px; }
.tab[aria-current="page"] { color: var(--primary); font-weight: bold; box-shadow: inset 0 3px 0 var(--primary); }
@media (min-width: 900px) {
  .tabs { position: sticky; top: 52px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); padding: 0 12px; justify-content: center; }
  .tab { flex: 0 0 200px; flex-direction: row; gap: 8px; font-size: 18px; min-height: 56px; }
  .tab[aria-current="page"] { box-shadow: inset 0 -4px 0 var(--primary); }
  .content { padding-bottom: 24px; }
}

.sec { font-size: 18px; margin: 22px 0 8px; }
.sec small { font-weight: normal; color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 15px; margin: 6px 0; }
.row-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 8px 0; }
.row-opts label { font-weight: bold; }
.row-opts select { min-width: 160px; flex: 1 1 160px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-weight: normal !important; min-height: 44px; }
.chk input { width: 24px; height: 24px; min-height: 0; }

/* ── 작업 입력 ── */
.scanbar { display: flex; gap: 8px; }
.scan { flex: 1; min-width: 0; min-height: 60px; font-size: 24px; font-weight: bold; background: #fffbe0; letter-spacing: 1px; }
.icon-btn { min-height: 60px; min-width: 64px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 12px; font-size: 14px; }
.icon-btn span[aria-hidden] { font-size: 24px; line-height: 1; }
@media (min-width: 600px) { .icon-btn { flex-direction: row; gap: 6px; font-size: 17px; min-width: 120px; } }

.part-card {
  margin: 12px 0 8px; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--head);
  border-radius: var(--radius); font-size: 18px;
}
.part-card.empty { color: var(--muted); border-left-color: var(--line); }
.part-card .mold { font-weight: bold; color: var(--head-dark); }
.part-card .part { font-size: 22px; font-weight: bold; margin: 2px 0; }
.part-card .meta { color: var(--muted); font-size: 15px; }
.part-card .warn { color: var(--red); font-weight: bold; }

.rout-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rout {
  width: 100%; text-align: left; display: grid; grid-template-columns: 56px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px; min-height: 72px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer;
  touch-action: manipulation;
}
.rout .seq { font-size: 22px; font-weight: bold; text-align: center; color: var(--muted); }
.rout .nm { font-size: 20px; font-weight: bold; }
.rout .sub { grid-column: 2 / 4; color: var(--muted); font-size: 15px; }
.rout .who { grid-column: 2 / 4; color: var(--primary); font-weight: bold; font-size: 15px; }
.rout.s-DONE { background: var(--c-done); color: #4b5a4b; }
.rout.s-RUN { background: var(--c-run); }
.rout.s-PAUSE { background: var(--c-warn); }
.rout.sel { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(41, 98, 175, .25); }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 15px; font-weight: bold; background: #e6e9ee; white-space: nowrap; }
.badge.b-DONE { background: #b9dca4; }
.badge.b-RUN { background: #9cc3ea; }
.badge.b-PAUSE { background: #f5d77a; }
.badge.b-out { background: #ddd; color: #555; }
.tag { display: inline-block; font-size: 13px; padding: 1px 6px; border-radius: 6px; background: #eee; margin-left: 6px; vertical-align: middle; font-weight: normal; }
.tag.rw { background: #fde3cf; color: #9a4d0f; }

/* 버튼 3개 : 화면 아래(탭 위)에 붙어 있음 */
.actions {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 10px 0; background: linear-gradient(to top, var(--bg) 80%, rgba(243,245,248,0));
}
@media (min-width: 900px) { .actions { bottom: 0; } }
.act {
  min-height: 76px; border: 0; border-radius: 12px; color: #fff; font-size: 21px; font-weight: bold; cursor: pointer; touch-action: manipulation;
}
.act.start { background: var(--start); }
.act.done { background: var(--done); }
.act.pause { background: var(--pause); }
.act:disabled { background: #b8c0ca; color: #eef1f4; cursor: not-allowed; }
.act:not(:disabled):active { filter: brightness(.9); }
@media (max-width: 380px) { .act { font-size: 17px; } }

.toast { min-height: 0; margin: 8px 0 0; font-size: 19px; font-weight: bold; }
.toast:not(:empty) { padding: 10px 14px; border-radius: var(--radius); }
.toast.ok { background: #e3f4e8; color: #1e6b3a; }
.toast.err { background: #fde8e6; color: var(--red); }

.run-list, .card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card {
  width: 100%; text-align: left; display: block; padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; touch-action: manipulation;
}
.card.mine { background: var(--c-run); border-color: #9cc3ea; }
.card .l1 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card .l1 b { font-size: 19px; }
.card .l2 { color: var(--muted); font-size: 15px; margin-top: 2px; }
.card .right { margin-left: auto; font-weight: bold; white-space: nowrap; }
.card.ready-N { color: #7b8794; }
.card.run { background: var(--c-run); }
.due-over { color: var(--red); font-weight: bold; }

/* ── 작업일보 ── */
.sum-bar { margin: 8px 0; padding: 12px 14px; background: var(--head); color: #fff; border-radius: var(--radius); font-size: 19px; font-weight: bold; }
.daily-card { cursor: default; }
.daily-card .time { font-size: 20px; font-weight: bold; }
.daily-card .remark { display: flex; gap: 8px; margin-top: 8px; }
.daily-card .remark input { flex: 1; min-width: 0; }

/* ── 진척 현황 ── */
.sum-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.sum-box { padding: 10px; border-radius: var(--radius); background: #e8eef7; text-align: center; font-weight: bold; }
.sum-box .n { display: block; font-size: 28px; }
.sum-box.late { background: var(--c-danger); }
.sum-box.risk { background: var(--c-warn); }
.mold-card .risk { padding: 3px 10px; border-radius: 999px; font-size: 15px; background: #e2efda; }
.mold-card .risk.r-지연 { background: var(--c-danger); color: #8a2b0c; }
.mold-card .risk.r-위험 { background: var(--c-warn); color: #7a5b00; }
.mold-card .risk.r-완료, .mold-card .risk.r-보류 { background: #e6e6e6; }
.bar { position: relative; height: 26px; margin: 8px 0 4px; background: #fff; border: 1px solid #b8c0ca; border-radius: 6px; overflow: hidden; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: #4c91d6; }
.bar .fill.f-지연 { background: #cd5c5c; }
.bar .fill.f-위험 { background: #f0a030; }
.bar .time { position: absolute; top: -2px; bottom: -2px; width: 3px; background: #000; }
.bar .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 15px; }
.detail-body { max-height: 65vh; overflow: auto; }
.detail-part { margin: 10px 0 4px; font-weight: bold; color: var(--head-dark); }
.detail-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 6px; padding: 8px; border-radius: 8px; margin-bottom: 4px; background: #f6f7f9; font-size: 16px; }
.detail-row.s-DONE { background: var(--c-done); }
.detail-row.s-RUN { background: var(--c-run); }
.detail-row.s-PAUSE { background: var(--c-warn); }
.detail-row.late { color: var(--red); }
.detail-row small { grid-column: 2 / 4; color: var(--muted); }

/* ── 대화상자 ── */
.dlg { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px)); }
.dlg.wide { width: min(820px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.dlg-body h2 { margin: 0 0 6px; font-size: 21px; }
.dlg-body select { min-height: var(--tap); font-size: 19px; }
.dlg-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.dlg-btns .btn { flex: 1; }
.confirm-text p { margin: 0 0 8px; font-size: 19px; }

/* 카메라 : 화면 가득 */
.dlg.cam { width: 100vw; height: 100dvh; max-width: none; max-height: none; border-radius: 0; background: #000; }
.cam-body { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.cam-body video { width: 100%; height: 100%; object-fit: cover; }
.cam-guide { position: absolute; left: 8%; right: 8%; top: 38%; height: 24%; border: 3px solid #2ecc71; border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .35); }
.cam-msg { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 0; right: 0; margin: 0; text-align: center; color: #fff; font-size: 19px; font-weight: bold; text-shadow: 0 1px 3px #000; padding: 0 12px; }
.cam-close { position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); min-width: 200px; }

.loading { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 50; background: rgba(0,0,0,.75); color: #fff; padding: 8px 18px; border-radius: 999px; font-size: 15px; }

/* ── 좁은 휴대폰 : 머리줄·요약칸 줄이기 ── */
@media (max-width: 520px) {
  .wide-only { display: none; }
  .brand #company { display: none; }
  .top .btn { min-height: 40px; padding: 6px 12px; }
  .sum-boxes { grid-template-columns: repeat(5, 1fr); gap: 4px; }
  .sum-box { padding: 6px 2px; font-size: 12px; }
  .sum-box .n { font-size: 22px; }
}

.link-btn { display: inline-flex; align-items: center; text-decoration: none; }
