:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2430;
  --muted: #6b7684;
  --line: #e3e6eb;
  --primary: #2f6fed;
  --primary-ink: #ffffff;
  --danger: #d6453d;
  --ok: #1f9d63;
  --plus: #1f7a4d;
  --minus: #b33a32;
  /* 엑셀 범례와 같은 색: 경과=분홍, D-30=노랑, D-60=초록, D-90=보라 */
  --exp-over-bg: #ffd6dc; --exp-over-fg: #a3182f;
  --exp-30-bg: #ffe8a3;   --exp-30-fg: #7a5200;
  --exp-60-bg: #d3f0d6;   --exp-60-fg: #1e6b2c;
  --exp-90-bg: #e2ddff;   --exp-90-fg: #4b3aa8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a; --surface: #1b1f26; --surface-2: #232833; --text: #e8ebf0; --muted: #98a2b0;
    --line: #2d333d; --primary: #5b8ff9; --danger: #f06a62; --ok: #3fc58a; --plus: #4cc38a; --minus: #f07a72;
    --exp-over-bg: #4d1d27; --exp-over-fg: #ffb3c0;
    --exp-30-bg: #4a3a10;   --exp-30-fg: #ffd970;
    --exp-60-bg: #1d3f24;   --exp-60-fg: #9fe0aa;
    --exp-90-bg: #2f2856;   --exp-90-fg: #c8bfff;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Pretendard", -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0; font-weight: 700; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* buttons & inputs */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.xs { padding: 2px 8px; font-size: 12px; font-weight: 500; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
label.check input { width: 16px; height: 16px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 20px; min-height: 56px;
}
.brand { font-weight: 800; font-size: 16px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs button {
  border: 0; background: none; font: inherit; color: var(--muted); font-weight: 600;
  padding: 17px 12px 15px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }
.user { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live-dot.on { background: var(--ok); }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }
.tab { display: flex; flex-direction: column; gap: 16px; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.card .value { font-size: 22px; font-weight: 800; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.entry-grid { grid-template-columns: minmax(320px, 440px) 1fr; align-items: start; }
.legend { display: flex; gap: 4px; }
.legend i { font-style: normal; }

/* list rows */
.list { display: flex; flex-direction: column; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.list .item .grow { flex: 1; min-width: 0; }
.list .item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item .meta { color: var(--muted); font-size: 12px; }
.list .num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.empty { color: var(--muted); padding: 12px 2px; }

/* badges */
.badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
/* 상미기한 경과: 진한 빨강 배지 + 줄 강조 */
.exp-over { background: var(--danger); color: #fff; }
table.data tr.row-over td { background: var(--exp-over-bg); }
table.data tr.row-over td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.panel-over { border-top: 4px solid var(--danger); }
.panel-over .panel-head h2 { color: var(--danger); }
.panel-over .list .item { background: var(--exp-over-bg); border-radius: 8px; padding-left: 10px; padding-right: 10px; margin-bottom: 4px; }
.exp-30 { background: var(--exp-30-bg); color: var(--exp-30-fg); }
.exp-60 { background: var(--exp-60-bg); color: var(--exp-60-fg); }
.exp-90 { background: var(--exp-90-bg); color: var(--exp-90-fg); }
.t-production, .t-convert_in, .t-opening { color: var(--plus); }
.t-shipment, .t-sample, .t-convert_out { color: var(--minus); }

/* toolbar */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=search] { width: 240px; }
.spacer { flex: 1; }

/* tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: calc(100vh - 190px); }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--muted); font-weight: 700; z-index: 1; }
table.data td.n, table.data th.n { text-align: right; }
table.data tr.group td { font-weight: 700; background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.data tr.lot td:first-child { padding-left: 26px; color: var(--muted); }
/* 구분(자사품/외주사) 머리줄: 크고 눈에 띄게 */
table.data tr.cat-row td { font-size: 1.12em; font-weight: 800; color: var(--primary); padding-top: 14px;
  background: color-mix(in srgb, var(--primary) 9%, var(--surface)); border-top: 2px solid var(--primary); }
table.data tr.cat-row .cat-count { font-size: .8em; font-weight: 500; color: var(--muted); margin-left: 6px; }
table.data tr.total td { font-weight: 800; background: var(--surface-2); position: sticky; bottom: 0; }
table.data tr.inactive td { opacity: .5; }

/* 재고 현황 사진 저장용 (화면 밖에서 잠깐 그렸다가 지움). 항상 밝은 색, 고정 너비 */
.capture {
  --bg: #ffffff; --surface: #ffffff; --surface-2: #f0f2f5; --text: #1c2430; --muted: #6b7684; --line: #e3e6eb;
  --primary: #2f6fed; --danger: #d6453d;
  --exp-over-bg: #ffd6dc; --exp-over-fg: #a3182f; --exp-30-bg: #ffe8a3; --exp-30-fg: #7a5200;
  --exp-60-bg: #d3f0d6; --exp-60-fg: #1e6b2c; --exp-90-bg: #e2ddff; --exp-90-fg: #4b3aa8;
  position: absolute; left: 0; top: 0; z-index: -1; width: 1200px; padding: 16px;
  background: #ffffff; color: var(--text); font-size: 18px;
}
.capture-head { margin-bottom: 10px; }
.capture-head h1 { margin: 0; font-size: 30px; color: #000; }
.capture-head div { color: #444; font-size: 17px; }
/* 재고 날짜 선택: 달력 버튼 위에 투명한 날짜 입력칸을 겹쳐서, 버튼을 누르면 언제든 달력이 열림 */
.date-nav { display: inline-flex; align-items: center; gap: 4px; }
.date-pick { position: relative; display: inline-block; }
.date-pick .date-btn { font-weight: 700; min-width: 150px; justify-content: center; }
.date-pick input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; border: 0; }
.date-pick.past-date .date-btn { border: 2px solid var(--danger); color: var(--danger); background: var(--exp-over-bg); }
/* 사진용 엑셀 스타일 표 */
.capture h2.cap-cat { margin: 18px 0 6px; font-size: 26px; font-weight: 800; color: #000; }
/* 구분마다 표 열 너비를 똑같이 맞춤 */
.capture table.xl { table-layout: fixed; }
.capture .xl th:nth-child(1) { width: 31%; }
.capture .xl th:nth-child(2) { width: 11%; }
.capture .xl th:nth-child(3) { width: 9%; }
.capture .xl th:nth-child(4), .capture .xl th:nth-child(5), .capture .xl th:nth-child(7) { width: 8.5%; }
.capture .xl th:nth-child(6) { width: 7.5%; }
.capture .xl th:nth-child(8) { width: 6%; }
.capture .xl th:nth-child(9) { width: 10%; }
.capture .xl td.xl-name { overflow: hidden; text-overflow: ellipsis; }
.capture table.xl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 20px; color: #000; }
.capture .xl th, .capture .xl td { border: 1px solid #000; padding: 5px 9px; text-align: center; white-space: nowrap; }
.capture .xl td.xl-name { text-align: left; }
.capture .xl th { background: #d9d9d9; font-weight: 700; }
.capture .xl td.n { text-align: right; }
.capture .xl td.xl-cat { font-size: 22px; font-weight: 800; line-height: 1.25; background: #fff; width: 48px; }
.capture .xl tr.xl-sum td { background: #bdd7ee; font-weight: 600; }
.capture .xl tr.xl-total td { background: #1f3864; color: #fff; font-weight: 800; }
/* 엑셀 범례 색 (진한 강조 대신 엑셀과 같은 연한 색) */
.capture .xl td.exp-90, .capture .xl-legend .exp-90 { background: #ccccff; color: #000; }
.capture .xl td.exp-60, .capture .xl-legend .exp-60 { background: #c6efce; color: #000; }
.capture .xl td.exp-30, .capture .xl-legend .exp-30 { background: #ffeb9c; color: #000; }
.capture .xl td.exp-over, .capture .xl-legend .exp-over { background: #ffc7ce; color: #000; }
.capture .xl-legend { display: flex; gap: 6px; margin-top: 10px; font-size: 16px; }
.capture .xl-legend span { padding: 2px 10px; border: 1px solid #999; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--primary) 6%, transparent); }
.zero { color: var(--muted); }

/* form */
.form { display: flex; flex-direction: column; gap: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 4px; font: inherit; font-weight: 600; cursor: pointer; color: var(--text); }
.seg button.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
.sum-line { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; font-variant-numeric: tabular-nums; }

/* dialog */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(10, 14, 20, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* responsive */
@media (max-width: 900px) {
  .grid2, .entry-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; padding: 8px 16px 0; gap: 4px 12px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { padding: 10px 10px 10px; }
  .user { margin-left: auto; }
  main { padding: 16px; }
  .toolbar input[type=search] { width: 100%; }
  .table-wrap { max-height: none; }
}
@media print {
  .topbar, .toolbar, .btn { display: none !important; }
  .table-wrap { max-height: none; overflow: visible; box-shadow: none; }
}
