:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2128;
  --muted: #667085;
  --border: #e2e5ea;
  --primary: #2457d6;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefc;
  --ok: #16794a;
  --ok-soft: #e3f4ea;
  --warn: #a15c00;
  --warn-soft: #fdf0dc;
  --danger: #c4301c;
  --danger-soft: #fbe6e3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e8eaee;
    --muted: #9aa3af;
    --border: #2e343d;
    --primary: #6b93ff;
    --primary-ink: #0b1020;
    --primary-soft: #1e2a47;
    --ok: #5fd39a;
    --ok-soft: #173326;
    --warn: #f2b45c;
    --warn-soft: #3a2b14;
    --danger: #ff7a66;
    --danger-soft: #3d1d18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* ── 상단 내비게이션 ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.05rem; color: var(--text); white-space: nowrap; }
.brand span { color: var(--primary); }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-weight: 600; }
.nav a.active, .nav a:hover { background: var(--primary-soft); color: var(--primary); }
.me-box { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.me-name { font-size: .88rem; font-weight: 600; }
@media (max-width: 760px) { .me-name { display: none; } }
.nav-count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

/* ── 카드/그리드 ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.6rem; font-weight: 800; }
.stat.warn .value { color: var(--warn); }

/* ── 버튼/폼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-lg { min-height: 52px; font-size: 1.05rem; padding: 12px 20px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: .85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* iOS 확대 방지 */
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; flex: 1 1 140px; }

/* ── 테이블 ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 700; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── 배지 ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.in_use { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.badge.pending { background: var(--warn-soft); color: var(--warn); border: 1px dashed currentColor; }
.badge.approved { background: var(--primary-soft); color: var(--primary); }
.badge.rejected { background: var(--danger-soft); color: var(--danger); }
.badge.low { background: var(--danger-soft); color: var(--danger); }
.badge.ai { background: var(--primary-soft); color: var(--primary); }

/* ── 리스트 ── */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ── 사진 ── */
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); cursor: zoom-in; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tag { position: absolute; left: 2px; bottom: 2px; font-size: .65rem; padding: 0 4px; border-radius: 4px; background: rgba(0,0,0,.6); color: #fff; }
.thumb .x { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; cursor: pointer; line-height: 20px; padding: 0; }
.thumbs.lg .thumb { width: 96px; height: 96px; }

/* ── 모달 ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.modal-close { border: 0; background: none; font-size: 1.5rem; cursor: pointer; color: var(--muted); line-height: 1; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 200; display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1c2128; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 300; font-weight: 600; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast.error { background: var(--danger); }

.qr-box { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.qr-box img { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 12px; }
.callout { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: .88rem; }
.callout.info { background: var(--primary-soft); color: var(--primary); }

/* ── 3D 모델 ── */
.viewer3d { position: relative; width: 100%; height: 420px; border-radius: var(--radius); overflow: hidden;
  background: radial-gradient(circle at 50% 35%, var(--surface) 0%, var(--surface-2) 100%); border: 1px solid var(--border); touch-action: none; }
.viewer3d canvas { display: block; width: 100%; height: 100%; }
.viewer-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-weight: 600; text-align: center; padding: 16px; pointer-events: none; }
.viewer-tools { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.model-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); box-shadow: var(--shadow); }
.model-card:hover { border-color: var(--primary); }
.model-card .thumb-box { aspect-ratio: 4 / 3; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.model-card .thumb-box img { width: 100%; height: 100%; object-fit: contain; }
.model-card .meta { padding: 10px 12px; }
.fmt-big { font-size: 1.4rem; font-weight: 800; color: var(--muted); letter-spacing: .05em; }
.model-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.model-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: .85rem; font-weight: 600; max-width: 100%; }
.model-chip img, .model-chip .fmt { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: 0 0 28px; }
.model-chip .fmt { display: inline-flex; align-items: center; justify-content: center; font-size: .55rem; color: var(--muted); }
.model-chip small { color: var(--muted); font-weight: 500; }
.model-chip.selectable { cursor: pointer; }
.model-chip.selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.progress { height: 6px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .2s; }
.review { padding: 8px 10px; border-radius: 8px; font-size: .88rem; }
.review.approved { background: var(--primary-soft); color: var(--primary); }
.review.rejected { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 640px) {
  .viewer3d { height: 320px; }
  .container { padding: 14px; }
  .topbar { padding: 8px 14px; gap: 10px; }
  .field-row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

@media print {
  .topbar, .no-print, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
