/* Layout: 상단 바 + 좌측 모델 목록 + 우측 BOM 작업 영역 (좁은 화면에서는 한 열) */
:root {
  --bg: #f3f5f2;
  --panel: #ffffff;
  --panel-2: #eaeeea;
  --fg: #18211d;
  --muted: #5b6862;
  --line: #d5ddd7;
  --accent: #17654a;      /* solder mask green */
  --accent-fg: #ffffff;
  --accent-soft: #dcefe6;
  --copper: #a85a1c;      /* 수삽 */
  --copper-soft: #f6e6d6;
  --smd: #1f5f8b;         /* SMD */
  --smd-soft: #dde9f3;
  --warn: #9a6a00;
  --warn-soft: #fbf0cf;
  --danger: #b3261e;
  --danger-soft: #f8dcd9;
  --tol: #0033cc;         /* 1%·K급 저항 글씨 */
  --nc: #d40000;          /* NC 글씨 */
  --font-body: "IBM Plex Sans KR", "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Consolas", "D2Coding", monospace;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111613; --panel: #18201c; --panel-2: #212b26; --fg: #e3ebe6; --muted: #98a69f; --line: #2f3b35;
    --accent: #4fbf8f; --accent-fg: #0b1510; --accent-soft: #1d3a2e; --copper: #e09a5c; --copper-soft: #3a2a1b;
    --smd: #7db6e0; --smd-soft: #1b2f3f; --warn: #e2bd55; --warn-soft: #3a3118; --danger: #f08a80; --danger-soft: #431f1c;
    --tol: #7fa8ff; --nc: #ff6b6b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111613; --panel: #18201c; --panel-2: #212b26; --fg: #e3ebe6; --muted: #98a69f; --line: #2f3b35;
  --accent: #4fbf8f; --accent-fg: #0b1510; --accent-soft: #1d3a2e; --copper: #e09a5c; --copper-soft: #3a2a1b;
  --smd: #7db6e0; --smd-soft: #1b2f3f; --warn: #e2bd55; --warn-soft: #3a3118; --danger: #f08a80; --danger-soft: #431f1c;
  --tol: #7fa8ff; --nc: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font-body); }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
h1, h2, h3 { text-wrap: balance; margin: 0; }

/* top bar */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 700; letter-spacing: .02em; }
.brand .chip { font-family: var(--font-mono); font-size: 11px; font-weight: 500; padding: 1px 6px; border-radius: 3px; background: var(--accent); color: var(--accent-fg); }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.topbar .grow { flex: 1 1 auto; }
.search { display: flex; gap: 6px; flex: 0 1 320px; min-width: 0; }
.search input { flex: 1; min-width: 0; }
.userbox { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.userbox .who { color: var(--muted); font-size: 13px; }

/* layout */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100% - 56px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.sidebar h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.model-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.model-list button { width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; display: grid; gap: 1px; }
.model-list button:hover { background: var(--panel-2); }
.model-list button.active { background: var(--accent-soft); }
.model-list .name { font-weight: 600; overflow-wrap: anywhere; }
.model-list .meta { font-size: 12px; color: var(--muted); }
.main { padding: 20px 24px 48px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .model-list { flex-direction: row; overflow-x: auto; }
  .model-list li { flex: 0 0 auto; }
  .main { padding: 16px 16px 40px; }
  .search { flex-basis: 100%; order: 3; }
}

/* controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); padding: 6px 12px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 6px 8px; }
textarea { resize: vertical; }
label.field { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { font-size: 14px; color: var(--fg); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }

/* model header */
.model-head { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; justify-content: space-between; }
.model-head h1 { font-size: 24px; line-height: 1.2; }
.model-head .sub { color: var(--muted); font-size: 13px; }
.revs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rev { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px 3px 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.rev.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rev b { font-family: var(--font-mono); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.dot.released { background: var(--accent); }
.dot.obsolete { background: var(--muted); }

.status { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.status.draft { background: var(--warn-soft); color: var(--warn); }
.status.released { background: var(--accent-soft); color: var(--accent); }
.status.obsolete { background: var(--panel-2); color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); }
.toolbar .opts { display: flex; gap: 12px; flex-wrap: wrap; margin-left: auto; font-size: 13px; color: var(--muted); }
.toolbar .opts label { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }

/* summary */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.sum { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 2px; }
.sum .k { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.sum .v { font-family: var(--font-mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.sum .v small { font-size: 12px; color: var(--muted); }
.swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.swatch.SMD { background: var(--smd); } .swatch.MANUAL { background: var(--copper); } .swatch.UNKNOWN { background: var(--warn); }

/* BOM table */
.section { display: grid; gap: 6px; }
.section-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.section-head h3 { font-size: 15px; display: flex; gap: 8px; align-items: center; }
.section-head .count { color: var(--muted); font-size: 13px; }
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.bom { width: 100%; border-collapse: collapse; font-size: 13px; }
table.bom th { text-align: left; font-weight: 600; font-size: 12px; letter-spacing: .02em; color: var(--muted); background: var(--panel-2); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.bom th.c-no { width: 48px; } table.bom th.c-part { width: 16%; } table.bom th.c-pkg { width: 12%; } table.bom th.c-val { width: 15%; } table.bom th.c-qty { width: 64px; }
table.bom th.c-fp { width: 13%; } table.bom th.c-rm { width: 13%; } table.bom th.c-mt { width: 90px; } table.bom th.c-x { width: 40px; }
table.bom td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.bom tr:last-child td { border-bottom: 0; }
table.bom td.no, table.bom td.qty { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; width: 1%; white-space: nowrap; }
table.bom td.val { font-family: var(--font-mono); white-space: nowrap; }
table.bom td.loc { font-family: var(--font-mono); font-size: 12px; overflow-wrap: anywhere; min-width: 220px; }
table.bom td.pkg { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
table.bom td.fp { font-family: var(--font-mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
table.bom td.rm { color: var(--muted); }
/* 글씨 색: 1%·K급 저항 파란색, NC 빨간색 */
table.bom tr.tol td, table.bom tr.tol input, table.bom tr.tol textarea { color: var(--tol); }
table.bom tr.nc td, table.bom tr.nc input, table.bom tr.nc textarea { color: var(--nc); }
table.bom tr.nc td.val, table.bom tr.nc td.val input { font-weight: 600; }
table.bom tr.flagged td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.flag { color: var(--danger); margin-right: 4px; cursor: help; }
.legend { display: flex; gap: 16px; font-size: 12px; flex-wrap: wrap; }
.legend .tol { color: var(--tol); } .legend .nc { color: var(--nc); }
.legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.lv-err { color: var(--danger); font-weight: 600; white-space: nowrap; } .lv-warn { color: var(--warn); font-weight: 600; white-space: nowrap; } .lv-info { color: var(--muted); white-space: nowrap; }
table.bom tfoot td { background: var(--panel-2); font-weight: 600; }
table.bom.section-SMD th:first-child { box-shadow: inset 3px 0 0 var(--smd); }
table.bom.section-MANUAL th:first-child { box-shadow: inset 3px 0 0 var(--copper); }
table.bom.section-UNKNOWN th:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.bom input, table.bom select, table.bom textarea { width: 100%; padding: 3px 6px; font-size: 13px; }
table.bom textarea { font-family: var(--font-mono); font-size: 12px; min-height: 30px; }
table.bom td.edit-qty input { width: 56px; text-align: right; }
table.bom tr.dup td.loc textarea { border-color: var(--danger); }

.badge { font-size: 11px; padding: 0 6px; border-radius: 3px; font-weight: 600; white-space: nowrap; }
.badge.SMD { background: var(--smd-soft); color: var(--smd); }
.badge.MANUAL { background: var(--copper-soft); color: var(--copper); }
.badge.UNKNOWN { background: var(--warn-soft); color: var(--warn); }

.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--warn-soft); color: var(--fg); font-size: 13px; }
.notice.info { background: var(--accent-soft); }
.notice.err { background: var(--danger-soft); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.muted { color: var(--muted); }

/* empty state */
.empty { display: grid; gap: 12px; justify-items: start; padding: 32px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); max-width: 640px; }
.empty h2 { font-size: 20px; }
.empty p { margin: 0; color: var(--muted); max-width: 60ch; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .4); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 8px; border: 1px solid var(--line); width: min(980px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; min-width: 0; }
.modal.narrow { width: min(460px, 100%); }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.modal header h2 { font-size: 17px; }
.modal .body { padding: 16px 18px; overflow: auto; display: grid; gap: 14px; min-width: 0; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: 22px; text-align: center; display: grid; gap: 8px; justify-items: center; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { font-size: 15px; }
.fmt { font-family: var(--font-mono); font-size: 12px; background: var(--panel-2); padding: 1px 6px; border-radius: 3px; }
.diff-added { color: var(--accent); font-weight: 600; } .diff-removed { color: var(--danger); font-weight: 600; } .diff-changed { color: var(--warn); font-weight: 600; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login form { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; }
.login h1 { font-size: 22px; }

.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 999px; z-index: 80; font-size: 13px; max-width: calc(100% - 32px); }

@media print {
  .topbar, .sidebar, .toolbar, .no-print, .revs { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  body { background: #fff; color: #000; }
  .tablewrap { border: 0; overflow: visible; }
  table.bom th, table.bom td { border: 1px solid #999; }
  table.bom tr.tol td { color: #0033cc; } table.bom tr.nc td { color: #d40000; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.drop.done { border-color: var(--accent); border-style: solid; }
/* 탭 (BOM | 자료) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .cnt { font-family: var(--font-mono); font-size: 11px; background: var(--panel-2); border-radius: 999px; padding: 0 6px; margin-left: 4px; color: var(--muted); }
.files { display: grid; gap: 14px; }
.file-cat.over { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: var(--radius); }
.file-empty { padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); font-size: 13px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; }
