/* REFAD 버스 탑승 체크 — B&W 브랜드, Pretendard, 모바일 우선 */
:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b6b6b;
  --line: #e6e6e6;
  --line-strong: #cfcfcf;
  --fill: #f5f5f5;
  --ok: #1a7f37;
  --ok-bg: #e7f4ec;
  --danger: #cf222e;
  --danger-bg: #fdeced;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  font-size: 16px;
  line-height: 1.4;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---- 상단 바 ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--fg); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 10px;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 8px; }
.brand-sub { font-weight: 500; font-size: 12px; opacity: .7; letter-spacing: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.session-pick select {
  appearance: none; -webkit-appearance: none;
  background: #fff; color: var(--fg); border: none; border-radius: 8px;
  font-weight: 700; font-size: 14px; padding: 8px 28px 8px 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23111' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; opacity: .9; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: #9a9a9a; }
.conn.online .dot { background: #36d36a; }
.conn.offline .dot { background: #ffb020; }
.conn .pending { background: #ffb020; color: #111; border-radius: 10px; padding: 0 6px; font-weight: 700; margin-left: 2px; }

/* ---- 탭 ---- */
.tab { display: none; padding: 0 0 16px; }
.tab.active { display: block; }

/* ---- 체크인 툴바 ---- */
.toolbar { position: sticky; top: 56px; z-index: 10; background: var(--bg); padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.bus-filter { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.bus-filter::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1.5px solid var(--line-strong); background: #fff; color: var(--fg);
  border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--fg); color: #fff; border-color: var(--fg); }
.chip .badge { font-size: 11px; opacity: .7; font-weight: 600; }
.chip.active .badge { opacity: .85; }

.search-row { display: flex; align-items: center; gap: 8px; position: relative; }
.search {
  flex: 1; border: 1.5px solid var(--line-strong); border-radius: 10px; padding: 12px 14px;
  font-size: 16px; outline: none; background: var(--fill);
}
.search:focus { border-color: var(--fg); background: #fff; }
.search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.icon-btn { border: none; background: var(--fill); border-radius: 10px; width: 44px; height: 48px; font-size: 16px; color: var(--muted); cursor: pointer; flex: 0 0 auto; }
.confirm-btn { flex: 0 0 auto; border: none; background: var(--fg); color: #fff; border-radius: 10px; padding: 0 18px; height: 48px; font-size: 15px; font-weight: 800; cursor: pointer; }
.confirm-btn:active { transform: scale(.98); }

.filter-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--fg); }
.count { font-size: 14px; font-weight: 700; }
.count b { font-size: 16px; }

/* 호차 차량 정보 */
.businfo-bar { background: var(--fill); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; font-weight: 700; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.businfo-bar a { color: var(--fg); text-decoration: underline; }
.bus-meta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; font-size: 13px; font-weight: 700; margin: 2px 0 10px; }
.bus-meta .bm-plate { background: var(--fill); border-radius: 6px; padding: 3px 8px; }
.bus-meta .bm-phone { color: var(--fg); text-decoration: none; border: 1.5px solid var(--line-strong); border-radius: 999px; padding: 3px 10px; }
.businfo-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.businfo-no { flex: 0 0 46px; font-weight: 800; font-size: 14px; }
.businfo-input { margin-top: 0 !important; flex: 1; min-width: 0; width: auto !important; padding: 10px 12px; font-size: 14px; }

/* 담당자 관리 */
.op-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.op-info { font-size: 15px; min-width: 0; }
.op-info b { font-weight: 800; }
.op-info .op-phone { color: var(--muted); font-weight: 600; margin-left: 8px; font-size: 13px; }
.op-del { flex: 0 0 auto; border: 1.5px solid var(--line-strong); color: var(--danger); background: #fff; border-radius: 8px; padding: 7px 12px; font-weight: 700; font-size: 13px; cursor: pointer; }
.op-add { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.op-add .input { margin-top: 0; }
.op-me { font-size: 11px; font-weight: 800; background: var(--fg); color: #fff; border-radius: 6px; padding: 2px 7px; margin-left: 8px; }

/* 명단 편집 */
.roster-edit-list { margin-top: 12px; max-height: 320px; overflow-y: auto; }
.roster-edit-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; }
.roster-edit-row:active { background: var(--fill); }
.roster-edit-row .re-name { font-weight: 800; font-size: 15px; }
.roster-edit-row .re-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.roster-edit-row .re-bus { flex: 0 0 auto; font-size: 12px; font-weight: 800; background: var(--fg); color: #fff; border-radius: 6px; padding: 3px 8px; }
.roster-edit-row .re-bus.none { background: var(--line-strong); }

/* 모달 */
.modal-overlay { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 380px; max-height: 90vh; overflow-y: auto; }
.modal-card h2 { margin: 0 0 6px; font-size: 18px; }
.modal-card .input { margin-top: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions .btn { flex: 1; min-width: 0; }

/* 출발 시각 / 미탑승 알림 */
.depart-alert { border-radius: 10px; padding: 9px 12px; margin-bottom: 10px; font-size: 13px; font-weight: 800; text-align: center; }
.depart-alert.ok { background: var(--fill); color: var(--fg); }
.depart-alert.soon { background: #fff4e5; color: #9a5b00; border: 1.5px solid #ffb020; }
.depart-alert.over { background: var(--danger-bg); color: var(--danger); border: 1.5px solid var(--danger); animation: departPulse 1s ease-in-out infinite; }
.depart-alert.done { background: var(--ok-bg); color: var(--ok); border: 1.5px solid var(--ok); }
@keyframes departPulse { 50% { opacity: .55; } }
.depart-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.depart-label { flex: 0 0 96px; font-weight: 700; font-size: 14px; }
.depart-row .input { margin-top: 0; flex: 1; }

/* 전광판 모드 */
.board-mode-btn { width: 100%; border: 1.5px solid var(--line-strong); background: #fff; color: var(--fg); border-radius: 12px; padding: 12px; font-weight: 800; font-size: 15px; cursor: pointer; margin-bottom: 16px; }
body.board-mode .tabbar { display: none; }
body.board-mode { padding-bottom: 0; }
body.board-mode .board-mode-btn { position: fixed; top: 12px; right: 14px; width: auto; margin: 0; z-index: 60; padding: 8px 14px; }
body.board-mode .board-overview .big { font-size: 56px; }
body.board-mode .board-overview .big small { font-size: 22px; }
body.board-mode .board-buses { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
body.board-mode .buscard { padding: 24px; }
body.board-mode .buscard .title { font-size: 26px; }
body.board-mode .buscard .frac { font-size: 30px; }
body.board-mode .bar { height: 16px; }
@media (min-width: 620px) { body.board-mode #tab-board { max-width: 1100px; } }

/* ---- 명단 리스트 ---- */
.list { list-style: none; margin: 0; padding: 8px 12px 0; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: #fff; border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px 14px; margin-bottom: 10px; cursor: pointer; text-align: left;
  transition: transform .05s ease, border-color .1s ease;
}
.row:active { transform: scale(.99); }
.row.boarded { border-color: var(--ok); background: var(--ok-bg); }
.row .mark {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--line-strong); display: grid; place-items: center;
  font-size: 16px; color: transparent;
}
.row.boarded .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.row .at { font-size: 12px; color: var(--ok); font-weight: 700; }
.busbadge {
  flex: 0 0 auto; font-size: 12px; font-weight: 800; background: var(--fg); color: #fff;
  border-radius: 8px; padding: 4px 8px; min-width: 40px; text-align: center;
}
.busbadge.none { background: var(--line-strong); }
.busbadge.mismatch { background: var(--danger); }

.empty-hint { text-align: center; color: var(--muted); padding: 40px 24px; }

/* ---- 현황판 ---- */
#tab-board { padding: 16px; }
.board-overview { background: var(--fg); color: #fff; border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.board-overview .big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; }
.board-overview .big small { font-size: 16px; font-weight: 600; opacity: .7; }
.session-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.sgrid-cell { background: rgba(255,255,255,.1); border-radius: 10px; padding: 8px 6px; text-align: center; cursor: pointer; }
.sgrid-cell.active { background: #fff; color: var(--fg); }
.sgrid-cell .l { font-size: 11px; opacity: .85; }
.sgrid-cell .v { font-weight: 800; font-size: 15px; margin-top: 2px; }

.buscard { border: 1.5px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.buscard .head { display: flex; align-items: center; justify-content: space-between; }
.buscard .title { font-weight: 800; font-size: 18px; }
.buscard .frac { font-weight: 800; font-size: 18px; }
.buscard .frac.full { color: var(--ok); }
.bar { height: 10px; border-radius: 6px; background: var(--fill); overflow: hidden; margin: 12px 0; }
.bar > span { display: block; height: 100%; background: var(--fg); border-radius: 6px; transition: width .3s ease; }
.bar > span.full { background: var(--ok); }
.missing-title { font-size: 13px; font-weight: 700; color: var(--danger); margin-bottom: 8px; }
.missing-list { display: flex; flex-wrap: wrap; gap: 8px; }
.missing-chip { display: inline-flex; align-items: center; gap: 6px; border: 1.5px solid var(--danger); color: var(--danger);
  border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 13px; text-decoration: none; }
.all-done { color: var(--ok); font-weight: 700; font-size: 14px; }

/* ---- 관리 ---- */
#tab-admin { padding: 16px; }
.card { border: 1.5px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card.danger { border-color: var(--danger); }
.input { width: 100%; border: 1.5px solid var(--line-strong); border-radius: 10px; padding: 12px 14px; font-size: 16px; outline: none; margin-top: 8px; }
.input:focus { border-color: var(--fg); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn { flex: 1; min-width: 140px; border: none; background: var(--fg); color: #fff; border-radius: 12px; padding: 14px 16px; font-size: 15px; font-weight: 700; cursor: pointer; }
.btn.ghost { background: #fff; color: var(--fg); border: 1.5px solid var(--line-strong); }
.btn.danger-btn { background: var(--danger); }
.version { text-align: center; margin-top: 20px; }

/* ---- 토스트 ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--fg); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 14px;
  transition: all .25s ease; z-index: 50; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* ---- 하단 탭바 ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom); height: calc(var(--tabbar-h) + var(--safe-bottom));
}
.tabbtn {
  flex: 1; border: none; background: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 700; padding-top: 8px;
}
.tabbtn span { font-size: 20px; line-height: 1; }
.tabbtn.active { color: var(--fg); }

/* 데스크탑에서 폭 제한 */
@media (min-width: 620px) {
  .topbar, .toolbar, .tab, .tabbar { max-width: 600px; margin-left: auto; margin-right: auto; }
  .toolbar { top: 56px; }
  body { background: #fafafa; }
  .tab { background: var(--bg); min-height: 60vh; }
}

/* ---- QR 스캔 버튼 ---- */
.scan-btn {
  width: 100%; border: none; background: var(--fg); color: #fff; border-radius: 12px;
  padding: 14px; font-size: 16px; font-weight: 800; cursor: pointer; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.scan-btn:active { transform: scale(.99); }

/* ---- QR 스캔 오버레이 ---- */
.scan-overlay {
  position: fixed; inset: 0; z-index: 100; background: #000;
  display: flex; flex-direction: column;
}
.scan-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px; color: #fff;
}
.scan-ctx-label { font-weight: 700; font-size: 14px; }
#scanCtx { opacity: .85; font-weight: 600; }
.scan-close { border: 1.5px solid rgba(255,255,255,.5); background: rgba(255,255,255,.08); color: #fff;
  border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; cursor: pointer; }

.scan-video-wrap { position: relative; flex: 1; overflow: hidden; display: grid; place-items: center; background: #000; }
#scanVideo { width: 100%; height: 100%; object-fit: cover; }
.scan-reticle {
  position: absolute; width: min(72vw, 320px); aspect-ratio: 1 / 1;
  border: 3px solid rgba(255,255,255,.95); border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); pointer-events: none;
}

.scan-feedback { padding: 16px; text-align: center; color: #fff; min-height: 72px; transition: background .15s ease; }
.scan-feedback.idle { background: rgba(255,255,255,.08); }
.scan-feedback.ok   { background: var(--ok); }
.scan-feedback.dup  { background: #b07a00; }
.scan-feedback.miss { background: var(--danger); }
.scan-feedback .sf-title { font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.scan-feedback .sf-sub { font-size: 13px; opacity: .9; margin-top: 4px; word-break: break-all; }

.scan-bottom {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 14px); color: #fff;
}
.scan-count { font-size: 14px; font-weight: 700; opacity: .9; }
.scan-manual { border: 1.5px solid rgba(255,255,255,.5); background: transparent; color: #fff;
  border-radius: 10px; padding: 10px 14px; font-weight: 700; font-size: 14px; cursor: pointer; }

@media (min-width: 620px) {
  .scan-reticle { width: min(60vh, 360px); }
}

/* ---- 로그인 ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-brand { font-weight: 800; font-size: 20px; letter-spacing: .14em; color: var(--fg); }
.login-title { font-size: 26px; font-weight: 800; margin: 6px 0 4px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.login-card .input { margin-top: 10px; text-align: center; }
.login-error { color: var(--danger); font-size: 13px; font-weight: 700; min-height: 18px; margin: 12px 0 0; }
.login-btn { width: 100%; margin-top: 10px; }
