:root {
  --bg: #1f2124;
  --panel: #2b2d31;
  --panel2: #34373c;
  --input: #3c3f44;
  --line: #4a4d53;
  --text: #f1f2f4;
  --muted: #a3a7ae;
  --primary: #2f7cf6;
  --accent: #8b5cf6;
  --info: #17a2b8;
  --ok: #28a745;
  --warn: #f0b429;
  --danger: #d9443a;
  --danger-bg: #5c0000;
  --danger-fg: #ff9e9e;
  --sel: #24497f;
  --blue-fg: #80b3ff;
  --radius: 6px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; }
.hidden { display: none !important; }
h1, h3 { margin: 0 0 10px; }
h3 { font-size: 15px; }
h3 small { color: var(--muted); font-weight: normal; font-size: 12px; }
code { background: var(--input); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.err { color: var(--danger-fg); min-height: 20px; }

input, select, textarea {
  background: var(--input); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; font: inherit; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
input[readonly] { background: var(--panel); color: var(--muted); }
textarea { resize: vertical; }

.btn {
  background: #4b4e54; color: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.accent { background: var(--accent); border-color: var(--accent); }
.btn.info { background: var(--info); border-color: var(--info); }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #222; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sq { width: 40px; padding: 8px 0; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn.big { padding: 13px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > .btn { flex: 1; }
.top .row > .btn { flex: none; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 0; }
.hint { color: var(--muted); font-size: 12px; }
.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); }

/* 로그인 */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 8px; }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 0 12px 8px; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; flex-wrap: wrap; }
.top .title { font-size: 16px; font-weight: 700; }

.trip-list { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); min-height: 120px; }
.trip { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.trip:hover { background: #3d4046; }
.trip.on { background: var(--sel); }
.trip .d { font-size: 12px; color: var(--muted); }
.trip .n { font-weight: 600; }
.trip .meter { height: 4px; background: var(--input); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.trip .meter i { display: block; height: 100%; background: var(--ok); }
.trip .meter i.full { background: var(--warn); }
.empty { padding: 16px; color: var(--muted); text-align: center; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-bottom: none; padding: 8px 18px; cursor: pointer; font: inherit; border-radius: 6px 6px 0 0; white-space: nowrap; }
.tabs button.on { background: var(--bg); border-bottom: 2px solid var(--primary); font-weight: 700; }
.pane { display: none; flex: 1; flex-direction: column; min-height: 0; padding-top: 8px; }
.pane.on { display: flex; }
.pane.scroll { overflow: auto; }
.split-v { display: grid; grid-template-rows: 1fr 2fr; gap: 8px; flex: 1; min-height: 0; }

/* 표 */
.tbl-wrap { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); min-height: 0; }
table.grid { border-collapse: collapse; width: max-content; min-width: 100%; }
.grid th, .grid td { border: 1px solid var(--line); padding: 5px 8px; text-align: center; white-space: nowrap; }
.grid th { background: #4b4e54; position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none; font-weight: 600; }
.grid tbody tr:nth-child(even) { background: #303338; }
.grid tbody tr:hover { background: #3d4046; }
.grid tbody tr.sel { background: var(--sel); }
.grid td.id { background: #4b4e54; }
.grid td.exp-bad { background: var(--danger-bg); color: var(--danger-fg); }
.grid td.rem { color: var(--blue-fg); }
.grid td.l { text-align: left; white-space: pre-wrap; max-width: 380px; }
.grid.log td { text-align: left; }
.seq-in { width: 54px; padding: 2px 4px; text-align: center; }

/* 모달 */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; min-height: 0; }
.modal > header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.modal > .body { padding: 14px 16px; overflow: auto; flex: 1; min-height: 0; }
.modal > footer { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); }
.modal.full { width: 100%; height: 100%; }
.x { background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }

.form { display: grid; grid-template-columns: 90px 1fr; gap: 7px 10px; align-items: center; }
.form label { font-weight: 600; font-size: 13px; text-align: right; }
.form .with-btn { display: flex; gap: 6px; min-width: 0; }
.form .with-btn input { flex: 1; }
input.bad { background: var(--danger-bg); color: var(--danger-fg); border-color: var(--danger); }

.cust-edit { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(320px, 1fr); gap: 16px; width: min(1150px, 92vw); }
.imgbox { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; min-height: 300px; display: grid; place-items: center; overflow: hidden; cursor: zoom-in; color: var(--muted); }
/* 이미지는 칸 크기에 맞춰 잘림 없이 전체 표시 */
.imgbox { position: relative; }
.imgbox img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.cust-edit .imgbox { height: min(60vh, 520px); }
.pp-list { font-size: 12px; color: var(--muted); margin-top: 10px; }
.pp-list b { color: var(--text); }

/* 스캔 — 화면 크기에 비례해 배치. 오른쪽 입력칸은 스크롤 없이 화면 높이에 맞춰 줄어듦 */
.modal-bg:has(.modal.full) { padding: clamp(0px, 1vw, 12px); }
.modal.full > header { padding: clamp(6px, 1.2vh, 12px) 16px; }
.modal.full > .body { padding: clamp(6px, 1.2vh, 14px) clamp(8px, 1vw, 16px); overflow: hidden; }
.scan { display: grid; grid-template-columns: minmax(150px, 15fr) minmax(0, 55fr) minmax(250px, 28fr); gap: clamp(8px, 1vw, 14px); height: 100%; min-height: 0; }
.scan > div { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: clamp(4px, .8vh, 8px); }
.scan .trip-list { flex: 1; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: clamp(4px, 1vh, 10px); text-align: center; color: var(--muted); }
.drop.over { border-color: var(--primary); color: var(--text); background: #2a3a55; }
.scan .tbl-wrap { flex: 4; min-height: 60px; }
.scan .imgbox { flex: 6; min-height: 100px; }

.scan-side { overflow-x: hidden; overflow-y: auto; }   /* 정상 크기에선 스크롤 없음, 아주 작은 화면에서만 세로 스크롤 */
.scan-side .form { grid-template-columns: auto minmax(0, 1fr); gap: clamp(2px, .55vh, 7px) 8px; min-width: 0; }
.scan-side .form label { font-size: clamp(11px, 1.45vh, 13px); white-space: nowrap; }
.scan-side .form input, .scan-side .form textarea { width: 100%; padding: clamp(2px, .55vh, 8px) 8px; font-size: clamp(12px, 1.6vh, 14px); }
.scan-side .form textarea { height: clamp(28px, 8vh, 100px); resize: none; }
.scan-side .with-btn .btn { flex: none; padding: 0 10px; }
.scan-actions { display: flex; flex-direction: column; gap: clamp(4px, .7vh, 8px); margin-top: auto; }
.scan-actions .btn { white-space: normal; padding: clamp(4px, 1.1vh, 12px) 8px; }
#scSaveAll { margin-top: clamp(0px, 1.2vh, 16px); }

/* 태블릿·작은 노트북: 2단 — 왼쪽 위 여행상품, 왼쪽 아래 대기열, 오른쪽 입력칸(전체 높이) */
@media (max-width: 1200px) {
  .scan { grid-template-columns: minmax(0, 1fr) minmax(250px, 36%); grid-template-rows: auto minmax(0, 1fr); }
  .scan > div:first-child { grid-column: 1; grid-row: 1; }
  .scan > div:nth-child(2) { grid-column: 1; grid-row: 2; }
  .scan > .scan-side { grid-column: 2; grid-row: 1 / span 2; }
  .scan > div:first-child .trip-list { max-height: clamp(64px, 13vh, 120px); }
}
/* 휴대폰: 1단 (세로로만 스크롤) */
@media (max-width: 760px) {
  .modal.full > .body { overflow: auto; }
  .scan { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; height: auto; }
  .scan > div:first-child, .scan > div:nth-child(2), .scan > .scan-side { grid-column: auto; grid-row: auto; }
  .scan .tbl-wrap { flex: none; max-height: 200px; }
  .scan .imgbox { flex: none; min-height: 220px; }
  .scan-side { overflow: visible; }
  .scan-side .form textarea { height: 70px; }
  .scan-actions { margin-top: 8px; }
}
.st-wait { color: var(--warn); }
.st-ok { color: #6fdc8c; }
.st-db { color: var(--blue-fg); }
.st-err { color: var(--danger-fg); }

.viewer { position: fixed; inset: 0; background: #111; z-index: 60; overflow: auto; cursor: zoom-out; }
.viewer img { display: block; margin: 0 auto; max-width: none; width: 150%; }
@media (max-width: 1200px) { .viewer img { width: 100%; } }

.recover { display: flex; flex-direction: column; gap: 12px; max-width: 1100px; padding-bottom: 20px; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; }
.stats div b { display: block; font-size: 22px; }
.progress { height: 8px; background: var(--input); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.mini { max-height: 320px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--line); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.error { background: var(--danger-bg); }

/* 좁은 화면 */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .side { border-right: none; border-bottom: 1px solid var(--line); }
  .trip-list { max-height: 240px; }
  .main { padding: 0 16px 16px; }
  .pane.on { min-height: 70vh; }
  .cust-edit { grid-template-columns: 1fr; width: 100%; }
  .form { grid-template-columns: 80px 1fr; }
  .scan-side .form { grid-template-columns: auto minmax(0, 1fr); }
}

/* 계정 */
body:not(.is-admin) .admin-only { display: none !important; }
.login-box .muted { text-align: center; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--input); }
.badge.admin { background: var(--accent); }
.badge.off { background: var(--danger-bg); color: var(--danger-fg); }
.temp-pw { font: 700 22px/1.4 Consolas, monospace; letter-spacing: 2px; background: var(--input); padding: 10px 16px; border-radius: 6px; text-align: center; user-select: all; }

/* 출발일 기준 조회 */
.date-filter { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.date-filter label { font-weight: 600; color: var(--text); white-space: nowrap; }
.date-filter input { flex: 1; min-width: 0; padding: 5px 6px; }
.date-filter .btn { flex: none; }
.st-chk { color: var(--warn); font-weight: 600; }
.scan-warn { background: #4a3b10; border: 1px solid var(--warn); color: #ffd97a; border-radius: 6px; padding: 6px 8px; font-size: 12px; white-space: pre-line; }

.brand { font-weight: 800; font-size: 16px; padding: 2px 2px 4px; }
.brand small, .ver-login { color: var(--muted); font-weight: 400; font-size: 11px; }
.ver-login { text-align: center; }

/* 4꼭지 크롭 편집기 */
.crop-wrap { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; background: #111; border-radius: 8px; overflow: hidden; touch-action: none; user-select: none; }
.crop-stage { position: relative; }
.crop-stage img { display: block; max-width: 100%; max-height: 100%; pointer-events: none; }
.crop-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.crop-shade { fill: rgba(0,0,0,.55); fill-rule: evenodd; }
.crop-edge { fill: rgba(47,124,246,.08); stroke: #2f7cf6; stroke-width: 2; }
.crop-top { stroke: #f0b429; stroke-width: 5; stroke-linecap: round; }
.crop-handle { fill: #fff; stroke: #2f7cf6; stroke-width: 3; cursor: grab; }
.crop-handle:active { cursor: grabbing; }
.crop-hint { color: var(--muted); font-size: 12px; }
.crop-loupe { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid #2f7cf6; pointer-events: none; background-repeat: no-repeat; box-shadow: 0 4px 16px rgba(0,0,0,.6); display: none; }
