/* =====================================================================
 * 디테일링 관리자 UI — app.css
 * 직원용(폰·태블릿) · 모바일 우선 · 큰 터치 타깃 · 명확한 상태색
 * 자체 완결(외부 CDN/폰트 없음), 시스템 폰트, 라이트/다크 자동 대응.
 * ===================================================================== */

/* =====================================================================
 * 디자인 토큰
 * ===================================================================== */
:root {
  /* 브랜드 — 딥 오토모티브 틸(teal) */
  --brand:        #0d9488;   /* teal-600 */
  --brand-strong: #0f766e;   /* teal-700 */
  --brand-deep:   #134e4a;   /* teal-900 */
  --brand-weak:   #d5f5ef;   /* 은은한 틴트 */
  --brand-ink:    #0f5f57;   /* 틴트 위 텍스트 */
  --brand-ring:   rgba(13,148,136,.28);

  /* 중립(slate) */
  --bg:        #eef2f6;   /* 앱 배경 */
  --surface:   #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e9eef4;
  --line:      #e2e8f0;
  --line-2:    #cbd5e1;
  --text:      #0f172a;
  --text-2:    #52627a;
  --text-3:    #94a3b8;

  /* 헤더/딥 서피스 */
  --header:    #0b2b2a;   /* 딥 틸-차콜 */
  --header-2:  #103d3a;

  /* 시맨틱 */
  --success:   #16a34a;
  --success-d: #15803d;
  --success-weak: #dcfce7;
  --warning:   #f59e0b;
  --warning-d: #b45309;
  --warning-weak: #fef3c7;
  --danger:    #dc2626;
  --danger-d:  #b91c1c;

  /* 상태색 — 대기(회색)/진행중(파랑)/일시정지(주황)/완료(초록) */
  --st-pending:   #64748b;   /* 대기 = 회색 */
  --st-progress:  #2563eb;   /* 진행중 = 파랑 (은은한 pulse) */
  --st-progress-rgb: 37,99,235;
  --st-paused:    #f59e0b;   /* 일시정지 = 주황 */
  --st-completed: #16a34a;   /* 완료 = 초록 */

  /* 기하 */
  --radius:    16px;
  --radius-lg: 20px;
  --radius-sm: 12px;
  --radius-xs: 10px;

  /* 그림자 (soft) */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.06);
  --shadow:    0 1px 3px rgba(15,23,42,.06), 0 6px 18px rgba(15,23,42,.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 12px 30px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 44px rgba(15,23,42,.22);

  --tap: 56px;                                   /* 최소 터치 높이 */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "맑은 고딕", sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
body { background: var(--bg); overflow-x: hidden; }
img { display: block; max-width: 100%; }
button { font-family: inherit; }
::selection { background: var(--brand-ring); }

/* =====================================================================
 * 버튼
 * ===================================================================== */
.btn {
  appearance: none; border: 0; cursor: pointer;
  border-radius: var(--radius-sm);
  font-weight: 700; font-size: 16px; letter-spacing: -.2px;
  padding: 0 18px; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s ease, background .16s ease, box-shadow .16s ease,
              opacity .16s ease, border-color .16s ease, color .16s ease;
  user-select: none; line-height: 1.1; white-space: nowrap;
  -webkit-user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--brand-ring); outline-offset: 2px; }

.btn-sm { min-height: 42px; font-size: 14px; padding: 0 14px; border-radius: 10px; gap: 6px; }
.btn-lg { min-height: 62px; font-size: 18px; border-radius: var(--radius); }
.btn-xl { width: 100%; min-height: 66px; font-size: 20px; border-radius: var(--radius); margin-top: 18px; }

.btn-primary {
  background: var(--brand); color: #fff;
  box-shadow: 0 6px 18px rgba(13,148,136,.32);
}
.btn-primary:hover { background: var(--brand-strong); }
.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line-2); box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--line-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(100,116,139,.12); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 6px 18px rgba(22,163,74,.30); }
.btn-success:hover { background: var(--success-d); }
.btn-warning { background: var(--warning); color: #fff; box-shadow: 0 6px 18px rgba(245,158,11,.28); }
.btn-warning:hover { background: var(--warning-d); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 18px rgba(220,38,38,.28); }
.btn-danger:hover { background: var(--danger-d); }

.icon-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  width: 46px; height: 46px; border-radius: 12px; font-size: 20px; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.icon-btn:hover { background: var(--surface-2); }

/* =====================================================================
 * 키패드 (로그인 + 시작화면 공용)
 * ===================================================================== */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.key {
  appearance: none; border: 0; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); font-size: 27px; font-weight: 700;
  min-height: 64px; box-shadow: var(--shadow-xs);
  transition: transform .06s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.key:hover { background: var(--surface-2); }
.key:active { transform: scale(.95); background: var(--brand-weak); border-color: var(--brand); }
.key:focus-visible { outline: 3px solid var(--brand-ring); outline-offset: 2px; }
.key-muted { color: var(--text-2); font-size: 18px; font-weight: 700; background: var(--surface-2); }
.key-muted:active { background: var(--surface-3); border-color: var(--line-2); }

/* =====================================================================
 * 로그인 화면 (2단계: 전화번호 → PIN)
 * ===================================================================== */
.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 560px at 50% -12%, #12706a 0%, rgba(15,94,88,0) 60%),
    radial-gradient(900px 520px at 100% 110%, #0b3b39 0%, rgba(11,59,57,0) 55%),
    linear-gradient(160deg, #0b2b2a 0%, #071f1e 100%);
}
.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px calc(20px + env(safe-area-inset-left,0px)) calc(24px + var(--safe-b));
}
.login-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border-radius: 24px; padding: 30px 24px 26px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255,255,255,.06);
  animation: rise .3s cubic-bezier(.2,.7,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } to { opacity: 1; transform: none; } }

.login-brand { text-align: center; margin-bottom: 20px; }
.login-logo {
  width: 66px; height: 66px; margin: 0 auto 14px; border-radius: 20px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; box-shadow: 0 8px 22px rgba(13,148,136,.38);
}
.login-title { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -.4px; }
.login-sub { margin: 8px 0 0; color: var(--text-2); font-size: 15px; }

/* 단계 전환 */
.login-step { animation: fade .2s ease; }
.login-step[hidden] { display: none; }
.login-back {
  margin: 0 0 6px -6px; color: var(--text-2);
}
.step-head { text-align: center; margin-bottom: 14px; }
.step-head .login-sub { margin-top: 4px; }
.phone-badge {
  display: inline-block; margin-top: 8px;
  background: var(--brand-weak); color: var(--brand-ink);
  font-weight: 800; font-size: 15px; letter-spacing: .5px;
  padding: 6px 14px; border-radius: 999px;
}

/* 전화번호 표시(로그인 1단계) */
.login-phone-field {
  background: var(--surface-2); border: 2px solid var(--line);
  border-radius: var(--radius); min-height: 68px;
  display: flex; align-items: center; justify-content: center; margin: 4px 0 16px;
}
.login-phone-field .phone-text { font-size: 28px; font-weight: 800; letter-spacing: 1px; color: var(--text); }
.login-phone-field .phone-text.placeholder { color: var(--text-3); font-weight: 600; letter-spacing: 0; }

/* PIN 점 표시(로그인 2단계) */
.pin-display { display: flex; gap: 18px; justify-content: center; margin: 14px 0 16px; }
.pin-dot {
  width: 18px; height: 18px; border-radius: 50%; background: transparent;
  border: 2.5px solid var(--line-2); transition: transform .14s ease, background .14s ease, border-color .14s ease;
}
.pin-dot.filled { background: var(--brand); border-color: var(--brand); transform: scale(1.12); }

.login-error {
  color: var(--danger); text-align: center; font-size: 14px; margin: 0 0 14px;
  font-weight: 700; min-height: 0;
}
.login-error[hidden] { display: none; }
.login-hint { text-align: center; color: var(--text-3); font-size: 12.5px; margin: 12px 0 0; }
.login-foot { color: rgba(255,255,255,.5); font-size: 12px; margin-top: 22px; text-align: center; }

.login-card .keypad { margin-top: 2px; }

/* =====================================================================
 * 앱 셸 / 상단바
 * ===================================================================== */
.app-body { background: var(--bg); }
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; padding-top: calc(10px + var(--safe-t));
  background: linear-gradient(180deg, var(--header) 0%, var(--header-2) 100%);
  color: #fff; box-shadow: 0 2px 14px rgba(7,31,30,.28);
}
.topbar-home {
  display: flex; align-items: center; gap: 9px; background: transparent; border: 0;
  color: #fff; cursor: pointer; padding: 8px 10px; border-radius: 12px; min-height: 46px;
  transition: background .15s ease;
}
.topbar-home:hover { background: rgba(255,255,255,.09); }
.topbar-logo {
  font-size: 20px; width: 34px; height: 34px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.12);
}
.topbar-name { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.topbar-actions { display: flex; gap: 4px; align-items: center; }
.topbar .btn { min-height: 46px; padding: 0 12px; font-size: 15px; }
.topbar .btn-ghost { color: #d5e8e6; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.10); color: #fff; }

.badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 800;
  margin-left: 5px; box-shadow: 0 0 0 2px rgba(255,255,255,.14);
}
.badge-count[hidden] { display: none; }

.view { flex: 1; width: 100%; max-width: 1000px; margin: 0 auto; padding: 16px; }

.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.screen-title { font-size: 25px; font-weight: 800; margin: 10px 0 4px; text-align: center; letter-spacing: -.5px; }
.screen-sub { color: var(--text-2); text-align: center; margin: 0 0 20px; font-size: 15px; }

.card {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px;
  border: 1px solid var(--line);
}
.sub-h { font-size: 13.5px; font-weight: 800; color: var(--text-2); margin: 20px 0 10px; letter-spacing: .1px; }
.sub-h:first-child { margin-top: 0; }
.sub-h .opt { font-weight: 600; color: var(--text-3); font-size: 12px; }

/* =====================================================================
 * 시작 화면 (전화번호 조회)
 * ===================================================================== */
.start-screen { max-width: 460px; margin: 0 auto; }
.phone-display {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  min-height: 78px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px; box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.phone-text { font-size: 32px; font-weight: 800; letter-spacing: 1px; color: var(--text); }
.phone-text.placeholder { color: var(--text-3); font-weight: 600; letter-spacing: 0; font-size: 22px; }
.keypad-lg .key { min-height: 66px; font-size: 29px; }

/* =====================================================================
 * 조회 결과
 * ===================================================================== */
.back-bar { margin-bottom: 12px; }

.customer-card { padding-top: 20px; }
.customer-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 56px; height: 56px; border-radius: 18px; flex: 0 0 auto;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; box-shadow: 0 6px 16px rgba(13,148,136,.30);
}
.customer-name { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.customer-phone { color: var(--text-2); font-size: 16px; margin-top: 3px; font-weight: 600; }

.new-banner {
  background: var(--brand-weak); color: var(--brand-ink); font-weight: 700;
  padding: 13px 15px; border-radius: var(--radius-sm); margin-bottom: 6px; font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.new-banner::before { content: "✨"; }

.car-list { display: flex; flex-direction: column; gap: 10px; }
.car-pick {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px;
  min-height: var(--tap); background: var(--surface);
  transition: border-color .14s ease, background .14s ease, box-shadow .14s ease;
}
.car-pick:hover { border-color: var(--line-2); }
.car-pick.on { border-color: var(--brand); background: var(--brand-weak); box-shadow: 0 0 0 3px var(--brand-ring); }
.car-pick input { width: 22px; height: 22px; accent-color: var(--brand); flex: 0 0 auto; }
.car-model { font-weight: 800; font-size: 17px; }
.car-plate { color: var(--text-2); font-weight: 700; margin-left: auto; }

.empty-inline { color: var(--text-2); padding: 6px 0 12px; font-size: 14px; }
.field-row { display: flex; gap: 10px; }
.field-row .input { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 6px; }
.input {
  width: 100%; border: 2px solid var(--line); border-radius: var(--radius-sm);
  padding: 14px; font-size: 17px; background: var(--surface); color: var(--text);
  min-height: var(--tap); transition: border-color .14s ease, box-shadow .14s ease;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.textarea { min-height: 78px; resize: vertical; line-height: 1.45; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; cursor: pointer; border: 2px solid var(--line);
  background: var(--surface); color: var(--text-2);
  border-radius: 999px; padding: 10px 16px; font-size: 15px; font-weight: 700;
  min-height: 46px; transition: all .13s ease;
}
.chip:hover { border-color: var(--line-2); }
.chip.on {
  border-color: var(--brand); background: var(--brand); color: #fff;
  box-shadow: 0 4px 12px rgba(13,148,136,.28);
}

.resume-box { margin: 16px 0 6px; }
.resume-list { display: flex; flex-direction: column; gap: 8px; }
.resume-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px;
}
.resume-car { font-weight: 700; }
.resume-item .btn { margin-left: auto; }

/* =====================================================================
 * 배지 / 상태
 * ===================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 13px; border-radius: 999px; font-weight: 800; font-size: 13px; color: #fff;
  white-space: nowrap;
}
.badge-lg { font-size: 15px; padding: 9px 16px; }
.badge::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,.9); flex: 0 0 auto;
}
.st-progress   { background: var(--st-progress); }
.st-paused     { background: var(--st-paused); }
.st-completed  { background: var(--st-completed); }
.st-pending    { background: var(--st-pending); }

/* 진행중 = 은은한 pulse */
.badge.st-progress { animation: badge-pulse 2.2s ease-in-out infinite; }
.badge.st-progress::before { animation: dot-pulse 2.2s ease-in-out infinite; }
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(var(--st-progress-rgb), .0); }
  40%      { box-shadow: 0 0 0 6px rgba(var(--st-progress-rgb), .18); }
}
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) {
  .badge.st-progress, .badge.st-progress::before { animation: none; }
}

/* =====================================================================
 * 작업 화면
 * ===================================================================== */
.job-screen { padding-bottom: 128px; }
.job-header { padding: 18px; }
.job-header-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.job-name { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.job-car { color: var(--text-2); font-size: 16px; margin-top: 4px; font-weight: 600; }
.job-plate { color: var(--text); font-weight: 800; }
.job-services { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.tag {
  background: var(--brand-weak); color: var(--brand-ink); border-radius: 8px;
  padding: 5px 11px; font-size: 13px; font-weight: 700;
}

.job-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0 14px; }
.job-toolbar .btn { flex: 1 1 auto; }
.photo-counter { color: var(--text-2); font-size: 14px; font-weight: 700; margin-left: auto; }

/* 사진 그리드 */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid-empty { display: block; }

.tile {
  position: relative; margin: 0; background: #0b1220;
  border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3;
  box-shadow: var(--shadow); border: 2px solid transparent;
  touch-action: none;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.tile:active { transform: scale(.99); }
.tile.dragging { opacity: .9; border-color: var(--brand); box-shadow: var(--shadow-lg); transform: scale(1.03); z-index: 5; }
.tile.is-hidden .tile-img { opacity: .32; filter: grayscale(.7); }
.tile-img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }

.tile-order {
  position: absolute; top: 8px; left: 8px; z-index: 2;
  background: rgba(11,18,32,.78); color: #fff; font-weight: 800; font-size: 13px;
  min-width: 26px; height: 26px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
  backdrop-filter: blur(2px);
}
.drag-handle {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  width: 42px; height: 42px; border: 0; border-radius: 11px;
  background: rgba(11,18,32,.66); color: #fff; font-size: 18px; cursor: grab;
  touch-action: none; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px); transition: background .12s ease;
}
.drag-handle:active { cursor: grabbing; background: var(--brand); }

.tile-hidden-flag {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 2;
  background: rgba(220,38,38,.94); color: #fff; font-size: 12px; font-weight: 800;
  padding: 4px 11px; border-radius: 8px;
}
.tile-actions {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  display: flex; gap: 6px; padding: 10px 8px 8px; justify-content: center;
  background: linear-gradient(to top, rgba(0,0,0,.6), rgba(0,0,0,0));
  opacity: .96;
}
.tile-btn {
  width: 44px; height: 44px; border: 0; border-radius: 11px; cursor: pointer;
  background: rgba(255,255,255,.94); color: var(--text); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); transition: transform .1s ease, background .12s ease;
}
.tile-btn:hover { background: #fff; }
.tile-btn:active { transform: scale(.92); }
.tile-danger { background: rgba(220,38,38,.94); color: #fff; }
.tile-danger:hover { background: var(--danger); }

/* 빈 상태 */
.empty-state {
  text-align: center; padding: 52px 20px; color: var(--text-2);
  background: var(--surface); border: 2px dashed var(--line-2); border-radius: var(--radius-lg);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .9; }
.empty-title { font-size: 18px; font-weight: 800; color: var(--text); }
.empty-desc { font-size: 14px; margin-top: 6px; line-height: 1.5; }

/* 하단 액션 바 (thumb-reachable, sticky) */
.job-actions {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + var(--safe-b));
  box-shadow: 0 -6px 24px rgba(15,23,42,.10);
}
.action-row { display: flex; gap: 10px; max-width: 1000px; margin: 0 auto; }
.action-row .btn { flex: 1; }
/* 완료+저장을 가장 도드라지게 */
.action-row .btn-success { flex: 1.35; }
.done-banner, .paused-banner {
  max-width: 1000px; margin: 0 auto 10px; padding: 11px 14px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 15px; text-align: center;
}
.done-banner { background: var(--success-weak); color: var(--success-d); }
.paused-banner { background: var(--warning-weak); color: var(--warning-d); }

/* =====================================================================
 * 미지정 사진함 드로어
 * ===================================================================== */
.drawer-scrim {
  position: fixed; inset: 0; background: rgba(7,31,30,.5); z-index: 40;
  animation: fade .16s ease; -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.drawer-scrim[hidden] { display: none; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(560px, 94vw); background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .24s cubic-bezier(.2,.7,.3,1);
  box-shadow: var(--shadow-lg);
}
.drawer[hidden] { display: none; }
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; padding-top: calc(16px + var(--safe-t));
  background: linear-gradient(180deg, var(--header) 0%, var(--header-2) 100%); color: #fff;
}
.drawer-title { margin: 0; font-size: 19px; font-weight: 800; }
.drawer-head .icon-btn { color: #fff; }
.drawer-head .icon-btn:hover { background: rgba(255,255,255,.14); }
.drawer-desc { color: var(--text-2); font-size: 14px; padding: 14px 18px 0; margin: 0; line-height: 1.5; }
.drawer-toolbar { display: flex; gap: 8px; padding: 14px 18px; flex-wrap: wrap; }
.drawer-toolbar .btn { flex: 1 1 auto; min-height: 50px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 0 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.drawer-loading { display: flex; justify-content: center; padding: 44px; }

.ua-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
.ua-tile {
  position: relative; margin: 0; aspect-ratio: 1/1; border-radius: var(--radius-sm); overflow: hidden;
  background: #0b1220; border: 3px solid transparent; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .14s ease, transform .1s ease;
}
.ua-tile:active { transform: scale(.98); }
.ua-tile.sel { border-color: var(--brand); }
.ua-img { width: 100%; height: 100%; object-fit: cover; }
.ua-check {
  position: absolute; top: 6px; left: 6px; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,.92); color: transparent; border: 2px solid var(--line-2);
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 15px;
  transition: all .14s ease;
}
.ua-tile.sel .ua-check { background: var(--brand); color: #fff; border-color: var(--brand); transform: scale(1.06); }
.ua-actions { position: absolute; right: 0; bottom: 0; display: flex; gap: 5px; padding: 6px; }

/* =====================================================================
 * 라이트박스 / 모달 / 토스트 / 로딩
 * ===================================================================== */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade .16s ease; -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 10px; object-fit: contain; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox-close {
  position: absolute; top: calc(16px + var(--safe-t)); right: 16px; width: 50px; height: 50px;
  border: 0; border-radius: 14px; background: rgba(255,255,255,.16); color: #fff;
  font-size: 22px; cursor: pointer; transition: background .15s ease;
}
.lightbox-close:hover { background: rgba(255,255,255,.28); }

.modal-scrim {
  position: fixed; inset: 0; z-index: 70; background: rgba(7,31,30,.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .16s ease; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.modal-scrim[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); padding: 24px;
  width: 100%; max-width: 380px; box-shadow: var(--shadow-lg);
  animation: rise .22s cubic-bezier(.2,.7,.3,1);
}
.modal-msg { font-size: 17px; font-weight: 600; margin: 0 0 20px; line-height: 1.5; text-align: center; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

.toast-stack {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: 92vw; pointer-events: none;
}
.toast {
  background: #0b2b2a; color: #fff; padding: 13px 18px; border-radius: 14px;
  font-size: 15px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(12px); transition: opacity .26s ease, transform .26s ease;
  max-width: 92vw; border: 1px solid rgba(255,255,255,.08);
}
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: #1f2d3a; }

.app-loading {
  position: fixed; inset: 0; z-index: 90; background: rgba(238,242,246,.6);
  display: none; align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.app-loading.on { display: flex; }
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--line-2); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
 * 반응형
 * ===================================================================== */
@media (min-width: 700px) {
  .view { padding: 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); }
  .ua-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media (min-width: 1000px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* 소형 폰 (~380px) */
@media (max-width: 380px) {
  .view { padding: 12px; }
  .key { min-height: 58px; font-size: 25px; }
  .keypad-lg .key { min-height: 60px; font-size: 26px; }
  .phone-text { font-size: 27px; }
  .btn-lg { min-height: 56px; font-size: 16px; }
  .action-row { gap: 8px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .job-name, .customer-name { font-size: 20px; }
}

/* =====================================================================
 * 다크 모드 (prefers-color-scheme)
 * ===================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --brand:        #2dd4bf;   /* teal-400 (다크에서 대비 확보) */
    --brand-strong: #14b8a6;
    --brand-deep:   #99f6e4;
    --brand-weak:   #123b39;
    --brand-ink:    #99f6e4;
    --brand-ring:   rgba(45,212,191,.30);

    --bg:        #0a0f16;
    --surface:   #131c26;
    --surface-2: #1a2430;
    --surface-3: #222f3d;
    --line:      #263241;
    --line-2:    #38495b;
    --text:      #eef4f8;
    --text-2:    #9fb0c1;
    --text-3:    #6b7d90;

    --header:    #08201f;
    --header-2:  #0c2e2c;

    --success-weak: #0f3320;
    --warning-weak: #3a2a08;

    --st-pending:   #7c8aa0;
    --st-progress:  #3b82f6;
    --st-progress-rgb: 59,130,246;
    --st-paused:    #f59e0b;
    --st-completed: #22c55e;

    --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
    --shadow:    0 1px 3px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5), 0 12px 30px rgba(0,0,0,.5);
    --shadow-lg: 0 12px 44px rgba(0,0,0,.6);

    color-scheme: dark;
  }
  body { background: var(--bg); }

  .btn-primary { color: #04211e; box-shadow: 0 6px 18px rgba(45,212,191,.24); }
  .btn-primary:hover { background: var(--brand-strong); }
  .avatar, .login-logo { color: #04211e; }
  .chip.on { color: #04211e; }
  .tag { color: var(--brand-deep); }

  .login-card { border-color: rgba(255,255,255,.05); }
  .login-phone-field { background: var(--surface-2); }

  .app-loading { background: rgba(10,15,22,.6); }
  .toast-info { background: #22303e; }

  .done-banner { color: #86efac; }
  .paused-banner { color: #fcd34d; }
}
