/* ==========================================================================
   HACCPLog 현장 PWA
   설계 전제: 작업장 태블릿, 장갑 낀 손, 낮은 조도, 한 손 조작
   - 터치 타겟 최소 48px, 주 버튼은 화면 하단 1/3
   - 색만으로 정보를 전달하지 않는다 (아이콘 + 텍스트 병기)
   - 명도대비 4.5:1 이상
   ========================================================================== */

:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --success: #15803d;
    --success-bg: #f0fdf4;
    --radius: 10px;
    --tap: 48px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Malgun Gothic", "맑은 고딕", "Noto Sans KR", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); }

/* ---------- 레이아웃 ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-header .site {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header .user {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.app-main {
    padding: 16px;
    padding-bottom: 120px;
    max-width: 780px;
    margin: 0 auto;
}

.app-footer-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    display: flex;
    gap: 10px;
    max-width: 780px;
    margin: 0 auto;
}

.app-footer-bar .btn { flex: 1; }

/* ---------- 버튼 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--tap);
    padding: 12px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-outline { border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; }

/* ---------- 카드 ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 17px;
    font-weight: 700;
    margin: 0 0 4px;
}

.card-meta {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* 상태 배지 - 색 + 텍스트를 함께 쓴다 */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid;
}

.badge-due    { background: var(--danger-bg);  color: var(--danger);  border-color: #fecaca; }
.badge-draft  { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }
.badge-done   { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.badge-normal { background: #f1f5f9;           color: var(--text-muted); border-color: var(--border); }

/* ---------- 진행률 ---------- */

.progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.progress-bar {
    flex: 1;
    height: 12px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar > span {
    display: block;
    height: 100%;
    background: var(--primary);
}

.progress-label { font-size: 15px; font-weight: 700; white-space: nowrap; }

/* ---------- 경고 배너 ---------- */

.alert {
    display: block;
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid;
}

.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: #fecaca; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }
.alert-info    { background: #eff6ff;           color: var(--primary); border-color: #bfdbfe; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }

/* ---------- 폼 ---------- */

.field { margin-bottom: 18px; }

.field-label {
    display: block;
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
}

.field-label .req { color: var(--danger); margin-left: 3px; }

.field-help {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.field-error {
    font-size: 14px;
    color: var(--danger);
    font-weight: 600;
    margin-top: 6px;
}

.input,
select.input,
textarea.input {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 17px;
    font-family: inherit;
}

textarea.input { min-height: 96px; resize: vertical; }

.input:focus {
    outline: 3px solid #bfdbfe;
    border-color: var(--primary);
}

.input.has-error { border-color: var(--danger); background: var(--danger-bg); }

.input[readonly] { background: #f8fafc; color: var(--text-muted); }

.input-group { display: flex; gap: 8px; align-items: stretch; }
.input-group .input { flex: 1; }
.input-unit {
    display: flex;
    align-items: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #f8fafc;
    font-weight: 700;
    color: var(--text-muted);
}

/* 적합/부적합 - 현장 입력 기본형. 화면 폭의 40% 이상 */
.passfail { display: flex; gap: 10px; }

.passfail label {
    flex: 1;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}

.passfail input { position: absolute; opacity: 0; width: 0; height: 0; }

.passfail input:checked + span { color: #fff; }
.passfail label:has(input[value="적합"]:checked)   { background: var(--success); border-color: var(--success); color: #fff; }
.passfail label:has(input[value="부적합"]:checked) { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.passfail label:has(input:focus-visible) { outline: 3px solid #bfdbfe; }

/* 3단계 선택 (양호/보통/불량) */
.tristate { display: flex; gap: 8px; }
.tristate label {
    flex: 1;
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-weight: 700;
    cursor: pointer;
}
.tristate input { position: absolute; opacity: 0; }
.tristate label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 체크박스 목록 */
.checklist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 10px 0;
    border-bottom: 1px solid #e2e8f0;
}

.checklist-item:last-child { border-bottom: 0; }
.checklist-item .label { flex: 1; font-size: 15px; font-weight: 600; }
.checklist-item .control { flex: 0 0 auto; width: 58%; max-width: 260px; }

/* 체크 묶음: 누르기 쉬운 칩을 가로로 흘린다 (세로 목록은 반복 행 격자를 세로로 늘려 화면을 깨뜨린다) */
.multi-check { display: flex; flex-wrap: wrap; gap: 8px; }

.multi-check label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 8px 14px;
    border: 2px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.multi-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }
.multi-check label:has(input:checked) { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.multi-check label:has(input:focus-visible) { outline: 3px solid #bfdbfe; }

/* ---------- 섹션 ---------- */

.section { margin-bottom: 20px; }

.section-title {
    font-size: 16px;
    font-weight: 800;
    padding: 10px 0;
    margin: 0 0 6px;
    border-bottom: 2px solid var(--text);
}

/* 접기 */
details.collapse { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 12px; }
details.collapse > summary { padding: 14px 16px; font-weight: 700; cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
details.collapse > div { padding: 0 16px 16px; }

/* ---------- 반복 행 (모바일에서는 행별 카드) ---------- */

.row-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 14px;
    margin-bottom: 12px;
}

.row-card.is-deviation {
    border-color: var(--danger);
    border-width: 2px;
    background: var(--danger-bg);
}

.row-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.row-no { font-weight: 800; font-size: 15px; }

.row-remove {
    min-height: 40px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--danger);
    font-weight: 700;
    cursor: pointer;
}

/* ---------- 모달 ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .6);
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.modal {
    background: var(--surface);
    width: 100%;
    max-width: 480px;
    border-radius: 16px 16px 0 0;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}

.modal h2 { margin: 0 0 6px; font-size: 19px; }
.modal p { margin: 0 0 16px; color: var(--text-muted); font-size: 14px; }

/* PIN 입력 */
.pin-input {
    width: 100%;
    text-align: center;
    letter-spacing: .5em;
    font-size: 28px;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
}

/* ---------- 목록 ---------- */

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    text-decoration: none;
    color: inherit;
    min-height: var(--tap);
}

.list-item .title { font-weight: 700; }
.list-item .meta { font-size: 13px; color: var(--text-muted); }

.empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
}

/* ---------- 사용자 선택(간편 로그인) ---------- */

.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
}

.user-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 110px;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.user-tile .avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    font-weight: 800;
}

.user-tile .name { font-weight: 700; }
.user-tile .role { font-size: 12px; color: var(--text-muted); }

/* ---------- 유틸 ---------- */

.offline-bar {
    background: var(--warning-bg);
    color: var(--warning);
    border-bottom: 1px solid #fde68a;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* 넓은 화면에서는 반복 행을 표로 */
@media (min-width: 900px) {
    .app-main { max-width: 1100px; }
    .app-footer-bar { max-width: 1100px; }
    /* 위쪽 정렬: 아래 정렬이면 키 큰 항목 하나 때문에 나머지가 바닥으로 밀려 큰 빈칸이 생긴다 */
    .row-card { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px 18px; align-items: start; }
    .row-card-head { grid-column: 1 / -1; margin-bottom: 0; }
    .row-card .field { margin-bottom: 0; }
    .row-card .field--multi_check,
    .row-card .field--textarea,
    .row-card .field--signature,
    .row-card .field--photo { grid-column: 1 / -1; }
}

/* ---------- 사진 첨부 ---------- */

.photo-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.photo-item {
    position: relative;
    width: 110px;
    height: 110px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #f1f5f9;
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 삭제 버튼도 터치 타겟을 확보한다 */
.photo-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 44px;
    min-height: 32px;
    padding: 4px 8px;
    border: 0;
    border-radius: 6px;
    background: rgba(185, 28, 28, .92);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.photo-field input[type="file"] {
    padding: 10px;
    font-size: 15px;
}

.photo-field input[type="file"]:disabled { opacity: .5; }

/* ==========================================================================
   로그인 (/app/login)
   태블릿 세로·가로, 장갑 낀 손 기준. 카드 하나에 시선을 모으고
   나머지는 눈에 띄지 않게 내린다.
   ========================================================================== */

/* hidden 속성이 display를 지정한 컴포넌트(.modal-backdrop 등)에도 먹게 한다 */
[hidden] { display: none !important; }

.auth-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
    background:
        radial-gradient(1100px 520px at 50% -10%, #e0e9ff 0%, rgba(224, 233, 255, 0) 70%),
        var(--bg);
}

/* justify-content:center 대신 margin:auto —
   내용이 화면보다 길어져도 위쪽이 잘려 못 보는 일이 없다 */
.auth-shell {
    width: 100%;
    max-width: 420px;
    margin: auto;
}

.auth-shell.is-wide { max-width: 620px; }

/* 태블릿 가로처럼 세로가 짧을 때는 여백을 줄인다 */
@media (max-height: 780px) {
    .auth-body { padding-top: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
    .auth-brand { margin-bottom: 16px; gap: 8px; }
    .auth-mark { width: 44px; height: 44px; border-radius: 13px; }
    .auth-mark svg { width: 24px; height: 24px; }
    .auth-wordmark { font-size: 22px; }
    .auth-card { padding: 20px 18px; }
}

/* ---------- 브랜드 ---------- */

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 22px;
    text-decoration: none;
    color: inherit;
}

.auth-mark {
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    border-radius: 15px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(29, 78, 216, .28);
}

.auth-mark svg { width: 28px; height: 28px; display: block; }

.auth-wordmark {
    font-size: 25px;
    font-weight: 800;
    letter-spacing: -.5px;
    line-height: 1.1;
}

.auth-wordmark em { font-style: normal; color: var(--primary); }

.auth-tagline {
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: .2px;
}

/* ---------- 카드 ---------- */

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px 20px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 26px rgba(15, 23, 42, .07);
}

.auth-card + .auth-card { margin-top: 14px; }

.auth-head { margin-bottom: 18px; }

.auth-title {
    margin: 0;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -.2px;
}

.auth-sub {
    margin: 4px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

/* 사업장 이름 + 공용 배지 */
.auth-tenant {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.auth-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

/* ---------- 비밀번호 표시 토글 ---------- */

.pw-wrap { position: relative; display: flex; }
.pw-wrap .input { padding-right: 76px; }

.pw-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.pw-toggle:hover { background: #f1f5f9; color: var(--text); }
.pw-toggle:focus-visible { outline: 3px solid #bfdbfe; outline-offset: 1px; }

/* ---------- 보조 링크 ---------- */

.auth-links {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: 16px 0 0;
    font-size: 14px;
}

.auth-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    padding: 6px 2px;
}

.auth-links a:hover { color: var(--primary); text-decoration: underline; }
.auth-links .sep { color: #cbd5e1; }

/* ---------- 접기 영역 ---------- */

.auth-disclose {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, .6);
    overflow: hidden;
}

.auth-disclose > summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    list-style: none;
    -webkit-tap-highlight-color: transparent;
}

.auth-disclose > summary::-webkit-details-marker { display: none; }

.auth-disclose > summary::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .15s ease;
}

.auth-disclose[open] > summary::before { transform: rotate(45deg); }
.auth-disclose[open] > summary { color: var(--text); }
.auth-disclose > summary:hover { color: var(--text); }
.auth-disclose .disclose-body { padding: 0 16px 16px; }

/* ---------- 하단 ---------- */

.auth-foot {
    margin-top: 18px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-foot .signup-line { margin-bottom: 10px; }

/* ---------- 사용자 선택(공용 태블릿) ---------- */

.auth-card .user-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }

.auth-card .user-tile { transition: border-color .12s ease, background .12s ease; }
.auth-card .user-tile:hover { border-color: #93b4fb; background: #f8fbff; }
.auth-card .user-tile:active { background: #eff6ff; }
.auth-card .user-tile:focus-visible { outline: 3px solid #bfdbfe; outline-offset: 2px; }

/* ---------- PIN 모달 ---------- */

.modal-backdrop .modal { box-shadow: 0 -8px 40px rgba(15, 23, 42, .25); }

.pin-input:focus { border-color: var(--primary); outline: 3px solid #bfdbfe; }

@media (min-width: 640px) {
    .modal-backdrop { align-items: center; }
    .modal-backdrop .modal { border-radius: 16px; }
}

/* ---------- 헤더: 좁은 화면 ----------
   사업장명·이름과 버튼 4개가 한 줄에 들어가지 않으면 버튼 글자가 세로로 찌그러진다.
   휴대폰 폭에서는 버튼 줄을 아래로 내려 가로로 나눠 쓴다. */
.app-header > div:first-child { min-width: 0; }
.app-header nav .btn { white-space: nowrap; }

@media (max-width: 560px) {
    .app-header { flex-wrap: wrap; row-gap: 10px; }
    .app-header > div:first-child { flex: 1 1 100%; }
    .app-header nav { flex: 1 1 100%; }
    .app-header nav .btn { flex: 1; padding-left: 6px !important; padding-right: 6px !important; }
}

/* 시각 입력 옆 "지금" 버튼: 좁은 칸에서도 글자가 세로로 쪼개지지 않게 */
.input-group .js-now { flex: 0 0 auto; white-space: nowrap; padding-left: 12px; padding-right: 12px; }
.input-group input[type="time"] { min-width: 0; }