/* ITMS — 기본 스타일 (외부 CDN 없이 동작) */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #e2e6ea;
  --line-strong: #cfd5dc;
  --text: #1d2733;
  --muted: #6b7785;
  --side: #17212b;
  --side-text: #c9d2dc;
  --side-muted: #7d8a97;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #1a7f4b;   --ok-soft: #e6f4ec;
  --warn: #9a6400; --warn-soft: #fdf3dc;
  --err: #c0362c;  --err-soft: #fbe9e7;
  --info: #2457a6; --info-soft: #e8eff9;
  --radius: 8px;
  --font: "Pretendard", "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: Consolas, "D2Coding", ui-monospace, monospace; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* 레이아웃 */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; flex: none; background: var(--side); color: var(--side-text); padding: 14px 10px 30px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand b { display: block; font-size: 16px; letter-spacing: .5px; }
.brand small { display: block; color: var(--side-muted); font-size: 11.5px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; background: var(--accent); color: #fff; font-weight: 800; font-size: 13px; }
.nav-group { font-size: 11px; color: var(--side-muted); padding: 14px 10px 4px; letter-spacing: .3px; }
.nav-item { display: flex; justify-content: space-between; align-items: center; color: var(--side-text); padding: 6px 10px; border-radius: 6px; font-size: 13.5px; }
.nav-item:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item.disabled { color: #56636f; cursor: default; }
.nav-item.disabled:hover { background: none; }
.nav-item em { font-style: normal; font-size: 10.5px; border: 1px solid #3a4652; border-radius: 4px; padding: 0 4px; color: #6f7c88; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .search { flex: 1; max-width: 420px; }
.topbar .search input { width: 100%; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; white-space: nowrap; }
.topbar .who small { color: var(--muted); margin-left: 4px; }
.bell { position: relative; font-size: 16px; margin-left: auto; cursor: default; }
.bell b { position: absolute; top: -6px; right: -10px; background: var(--err); color: #fff; font-size: 10px; border-radius: 9px; padding: 0 5px; }
.menu-toggle { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; }
.content { padding: 20px 22px 60px; max-width: 1400px; width: 100%; }

/* 빈 레이아웃 (로그인·설치) */
body.blank { display: grid; place-items: start center; min-height: 100vh; padding-top: 8vh; }
.blank-wrap { width: min(420px, 92vw); }
.blank-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.blank-brand b { font-size: 20px; }
.blank-brand small { color: var(--muted); }

/* 카드·페이지 머리 */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin: 0; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card.narrow { max-width: 560px; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* 통계 */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
a.stat:hover { border-color: var(--accent); text-decoration: none; }
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: 12.5px; }
.stat.warn .num { color: var(--warn); }
.stat.err .num { color: var(--err); }

/* 표 */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { background: #f8f9fb; font-weight: 600; font-size: 12.5px; color: #44505c; white-space: nowrap; }
table.list tbody tr:hover { background: #fafbfc; }
table.list td.num, table.list th.num { text-align: right; }
table.list .empty { text-align: center; color: var(--muted); padding: 28px; }
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { width: 120px; text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px 6px 0; vertical-align: top; }
table.kv td { padding: 6px 0; }
.count { color: var(--muted); font-size: 13px; margin: 6px 0; }

/* 배지 */
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; background: #eef1f4; color: #44505c; white-space: nowrap; }
.st-stock    { background: #eef1f4; color: #44505c; }
.st-inuse    { background: var(--ok-soft); color: var(--ok); }
.st-repair   { background: var(--warn-soft); color: var(--warn); }
.st-returned { background: #fdeee0; color: #a3530b; }
.st-spare    { background: var(--info-soft); color: var(--info); }
.st-disposed { background: #e9e9ec; color: #6b6b75; }
.st-lost     { background: var(--err-soft); color: var(--err); }
.role { background: var(--accent-soft); color: var(--accent); }

/* 폼 */
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d3fb; border-color: var(--accent); }
textarea { width: 100%; min-height: 70px; }
.form { display: grid; gap: 12px; }
.form label { display: block; font-weight: 600; font-size: 13px; }
.form label > input, .form label > select, .form label > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.form label small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.form label.check { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.form label.check > input { display: inline-block; width: auto; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form > .btn:not(.block) { justify-self: start; }
.qr svg { width: 200px; height: 200px; display: block; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; font-weight: 500; }
.checks label { display: flex; align-items: center; gap: 5px; font-weight: 500; }
.checks label > input { display: inline-block; width: auto; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input[type=search] { min-width: 220px; }
.info-box { background: #f8f9fb; border: 1px dashed var(--line-strong); border-radius: 6px; padding: 10px 12px; font-size: 12.5px; color: var(--muted); }

/* 버튼 */
.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line-strong); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f4f6f8; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5fd0; }
.btn.danger { color: var(--err); border-color: #efc2bd; }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn-link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.inline { display: inline; }

/* 알림 */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid transparent; }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cd; }
.alert.error { background: var(--err-soft); color: var(--err); border-color: #f2c4bf; }
.alert.warn { background: var(--warn-soft); color: var(--warn); border-color: #f1dca6; }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #c8d8f0; }
.alert .secret { display: inline-block; font-family: Consolas, ui-monospace, monospace; font-size: 16px; background: #fff; border: 1px solid currentColor; padding: 2px 10px; border-radius: 4px; margin: 4px 0; letter-spacing: 1px; }

/* 동작 패널 (자산 상세) */
.actions-panel details { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; background: #fff; }
.actions-panel summary { padding: 9px 12px; cursor: pointer; font-weight: 600; list-style: none; }
.actions-panel summary::-webkit-details-marker { display: none; }
.actions-panel summary::before { content: '▸ '; color: var(--muted); }
.actions-panel details[open] summary::before { content: '▾ '; }
.actions-panel details > div { padding: 4px 12px 12px; }
.actions-panel .form label { font-size: 12.5px; }

/* 이력 */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline .meta { color: var(--muted); font-size: 12px; }
.timeline .chg { font-size: 12.5px; margin-top: 2px; }
.timeline .chg span.old { color: var(--muted); text-decoration: line-through; }
.tag { display: inline-block; font-size: 11.5px; padding: 0 6px; border-radius: 4px; background: #eef1f4; color: #44505c; margin-right: 4px; }
.tree-pad { display: inline-block; color: var(--muted); }

@media (max-width: 960px) {
  .grid.side, .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; box-shadow: 0 0 20px rgba(0,0,0,.3); }
  .sidebar.open { left: 0; }
  .menu-toggle { display: block; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .topbar .who small { display: none; }
  .content { padding: 14px 12px 50px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}

/* ---- M2: QR 스캔 */
.scan-box { position: relative; background: #111; border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; max-width: 520px; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18% 22%; border: 3px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25); pointer-events: none; }
.row-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---- M2: 라벨 */
.label-sheet-wrap { overflow: auto; background: #e9ecef; padding: 16px; border-radius: 8px; }
.label-sheet { background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.15); margin: 0 auto 16px; position: relative; box-sizing: border-box; }
.label-grid { position: absolute; display: grid; }
.label-cell { box-sizing: border-box; overflow: hidden; display: flex; align-items: center; gap: 2mm; padding: 2mm 2.5mm; font-family: "Malgun Gothic", sans-serif; color: #000; }
.label-sheet.preview .label-cell { outline: 1px dashed #c5ccd3; }
.label-cell .lq svg { width: 100%; height: 100%; display: block; }
.label-cell .lq { flex: none; }
.label-cell .lt { min-width: 0; line-height: 1.25; }
.label-cell .lno { font-family: Consolas, "Courier New", monospace; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.label-cell .lm, .label-cell .ls { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label-cell .lorg { color: #333; }
.label-cell.empty { visibility: hidden; }
.check-col { width: 28px; }
.bar-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

[hidden] { display: none !important; }

/* ---- 휴대폰: 표를 카드로 (table.stack) */
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; box-sizing: border-box; }
  table.stack tr { border: 1px solid var(--line, #e3e7eb); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; background: #fff; }
  table.stack td { border: 0 !important; padding: 5px 0 !important; display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; text-align: right; }
  table.stack td::before { content: attr(data-label); font-family: var(--font); color: var(--muted); font-size: 12.5px; text-align: left; flex: none; min-width: 64px; }
  table.stack td.stack-title { font-size: 16px; justify-content: flex-start; text-align: left; border-bottom: 1px solid #eef1f4 !important; padding-bottom: 8px !important; margin-bottom: 4px; }
  table.stack td.stack-title::before { display: none; }
  table.stack td.empty { justify-content: center; text-align: center; }
  table.stack td.empty::before { display: none; }
  table.stack .btn { padding: 8px 16px; font-size: 14px; }
  .card:has(> .table-wrap > table.stack), .card:has(> table.stack) { background: transparent; border: 0; box-shadow: none; padding: 0; }
}

/* ---- M3: 교체 */
.progress { height: 8px; background: #edf0f3; border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); }
.stage-board { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; margin-bottom: 6px; }
.sb { display: flex; flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: inherit; }
.sb:hover { border-color: var(--accent); }
.sb.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.sb-no { font-size: 11px; color: var(--muted); }
.sb-name { font-size: 13px; }
.sb b { font-size: 22px; line-height: 1.1; }
.sb.done b { color: var(--ok); }
.sb.warn b { color: var(--warn); }
.dots { display: flex; gap: 4px; margin-bottom: 3px; }
.dot { width: 18px; height: 6px; border-radius: 3px; background: #e3e7eb; }
.dot.on { background: var(--ok); }
.dot.cur { background: var(--accent); }
.steps { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; margin-bottom: 16px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.step-no { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #edf0f3; color: var(--muted); font-weight: 700; font-size: 13px; }
.step-name { font-size: 13px; font-weight: 600; }
.step-date { font-size: 11px; color: var(--muted); min-height: 14px; }
.step.done .step-no { background: var(--ok); color: #fff; }
.step.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.step.current .step-no { background: var(--accent); color: #fff; }
tr.row-warn td { background: var(--warn-soft); }
.inline-form { display: flex; gap: 6px; margin-top: 10px; }
.inline-form input { flex: 1; }
.add-box { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.add-box summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
.form.narrow { max-width: 560px; }
@media (max-width: 960px) {
  .stage-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .steps { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.timeline .chg .nowrap { white-space: normal; }
.timeline li { overflow-wrap: anywhere; }

/* ---- M4: SW */
.matrix-wrap { overflow-x: auto; }
table.matrix th.mcol { writing-mode: horizontal-tb; white-space: nowrap; font-size: 12px; text-align: center; }
table.matrix td.mcell, table.matrix th.mcell { text-align: center; font-size: 12px; white-space: nowrap; }
table.matrix td.mcell.on { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
table.matrix thead th { position: sticky; top: 0; background: #f6f8fa; z-index: 1; }
.secret-key { background: var(--warn-soft); padding: 2px 8px; border-radius: 4px; letter-spacing: .5px; user-select: all; }

/* ---- M5: 작업 보고 · 알림 */
.type-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-weight: 400; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 18px; padding: 6px 12px; cursor: pointer; background: #fff; font-size: 14px; }
.pill:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill input { margin: 0; }
.checks { display: grid; gap: 6px; margin-bottom: 6px; }
.checks.cols { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.devbox { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; }
.devbox legend { font-weight: 600; padding: 0 4px; }
.devbox .mode-direct { display: grid; gap: 6px; }
.kv-line { font-size: 15px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photos figure { margin: 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.noti-list { list-style: none; margin: 0; padding: 0; }
.noti-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.noti-list li.unread a { font-weight: 700; }
.noti-list li.unread::before { content: "●"; color: var(--accent); margin-right: 6px; font-size: 10px; }
.bell { position: relative; color: inherit; text-decoration: none; }
.noti-banner { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.btn.block { width: 100%; justify-content: center; }

.nav-count { font-style: normal; background: var(--err); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 6px; }
.form .pill, .type-pills label.pill { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.form .devbox { min-width: 0; }
.devbox select, .devbox input { width: 100%; box-sizing: border-box; }
.form .checks label.check { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.form .pill > input, .type-pills .pill > input { display: inline-block; width: auto; margin: 0; }
