:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;
  --text: #111827;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }
p { margin: 0; }
code {
  background: #f1f5f9;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.num { text-align: right; }

/* ---------- 로그인 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #dbeafe 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #e0e7ff 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-brand h1 { font-size: 20px; }
.login-brand p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.logo {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #fff; font-weight: 800; font-size: 22px;
  flex: 0 0 auto;
}
.logo.small { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
.login-foot { margin-top: 16px; text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- 폼 공통 ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: #334155; }
.field input, .field select, .inline-field input {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 9px 11px;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 40px;
}
.field input:focus, .field select:focus, .inline-field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}
.field.compact { margin-bottom: 0; }
.grow { flex: 1 1 260px; }
.form-error {
  margin: 4px 0 12px;
  padding: 9px 11px;
  border-radius: 9px;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 13px;
}

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: #1e293b;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: #f8fafc; border-color: #94a3b8; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
.btn.primary:disabled { background: #93c5fd; border-color: #93c5fd; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef2f7; color: #1e293b; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; padding: 11px; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  color: #94a3b8; font-size: 16px; line-height: 1;
  width: 28px; height: 28px; border-radius: 7px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- 상단 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto;
  padding: 12px 22px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 16px; letter-spacing: -0.01em; }
.brand-text .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.chip {
  font-size: 12.5px; color: #334155; background: #f1f5f9;
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px;
}
.tabs {
  max-width: 1240px; margin: 0 auto; padding: 0 22px;
  display: flex; gap: 4px;
}
.tab {
  border: none; background: none; cursor: pointer;
  padding: 11px 14px 12px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: #1e293b; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.container { max-width: 1240px; margin: 0 auto; padding: 22px 22px 60px; }
.tab-panel { display: flex; flex-direction: column; gap: 16px; }
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.panel-head .muted { margin-top: 6px; max-width: 820px; font-size: 13.5px; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ---------- 업로드 ---------- */
.upload-row { display: flex; gap: 20px; align-items: stretch; }
.drop-zone {
  flex: 1 1 auto;
  min-height: 150px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 12px;
  background: #fbfdff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 20px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone:focus, .drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  outline: none;
}
.drop-icon {
  width: 38px; height: 38px; border-radius: 50%;
  background: #dbeafe; color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; margin-bottom: 9px;
}
.drop-title { font-weight: 600; font-size: 14.5px; }
.drop-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.upload-side { flex: 0 0 210px; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.file-name {
  margin-top: 12px; font-size: 13px; color: #1e293b;
  background: #f1f5f9; border-radius: 8px; padding: 8px 11px;
}

/* ---------- 통계 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--muted); }
.stat strong { font-size: 24px; letter-spacing: -0.02em; }
.stat.accent strong { color: var(--primary); }
.stat.warn strong { color: var(--warn); }

/* ---------- 테이블 ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.table-wrap.tall { max-height: 560px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; min-width: 760px; }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f8fafc;
  color: #475569;
  font-size: 12.5px; font-weight: 700;
  text-align: left;
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 8px 11px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fbff; }
.table tbody tr.low-stock td { background: #fffdf5; }
.table tbody tr.low-stock:hover td { background: #fff9e8; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-no { width: 52px; }
.table .col-check { width: 36px; }
.table .col-state { width: 44px; }
.table .col-del { width: 36px; }
.table .col-qty { width: 128px; }
.compact-table { min-width: 580px; font-size: 13px; }
.order-table td { padding-top: 6px; padding-bottom: 6px; }
.cell-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; white-space: nowrap; }
.cell-name { min-width: 240px; }
.cell-option { color: #334155; white-space: nowrap; }
.barcode { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #475569; white-space: nowrap; }
.stock-neg { color: var(--danger); font-weight: 700; }
.qty-input {
  width: 96px; padding: 6px 8px; text-align: right;
  border: 1px solid var(--border-strong); border-radius: 7px;
  font-variant-numeric: tabular-nums;
}
.qty-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.qty-input.saved { border-color: #86efac; background: var(--ok-soft); }
.qty-input.error { border-color: #fca5a5; background: var(--danger-soft); }
.state-dot { font-size: 12px; color: var(--ok); }
.state-dot.saving { color: var(--muted); }
.state-dot.error { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 13.5px; }

/* ---------- 결과 ---------- */
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.result-head .muted { margin-top: 4px; }
.result-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge {
  display: inline-block; min-width: 22px; text-align: center;
  background: var(--primary-soft); color: var(--primary);
  border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700;
  margin-left: 6px; vertical-align: 2px;
}
.badge.warn-badge { background: var(--warn-soft); color: var(--warn); }
.pill {
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; color: #334155;
}
.summary-title { font-weight: 700; font-size: 14.5px; }
details > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: #94a3b8; font-size: 12px; }
details[open] > summary::before { content: "▾"; }
details .table-wrap { margin-top: 12px; }
.all-items { margin-top: 14px; }
.all-items > summary { color: var(--muted); font-size: 13px; }
.placeholder { text-align: center; padding: 40px 20px; }
.placeholder-art { font-size: 34px; margin-bottom: 8px; }
.placeholder h3 { margin-bottom: 6px; }

/* ---------- 기준표 ---------- */
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.bulk-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--primary-soft); border: 1px solid #bfdbfe;
  border-radius: 10px; padding: 10px 12px; margin-bottom: 12px;
  font-size: 13.5px;
}
.inline-field { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: #334155; }
.inline-field input { width: 104px; min-height: 34px; padding: 5px 8px; text-align: right; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 8px; }

/* ---------- 안내 ---------- */
.guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.guide-grid h3 { margin-bottom: 10px; }
.steps { margin: 0; padding-left: 20px; color: #334155; }
.steps li { margin-bottom: 7px; }
.plain { margin: 0; padding-left: 18px; color: #334155; }
.plain li { margin-bottom: 7px; }

/* ---------- 모달 ---------- */
.modal {
  border: none; border-radius: 16px; padding: 22px;
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.24);
}
.modal.wide { width: min(860px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 23, 42, 0.42); }
.modal h3 { margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.import-summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13.5px; }
.import-summary b { color: var(--primary); }
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13.5px; color: #334155; }
.modal .table-wrap { max-height: 320px; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #0f172a; color: #fff;
  padding: 11px 18px; border-radius: 10px;
  font-size: 13.5px; z-index: 100; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.3);
  max-width: calc(100vw - 32px);
}
.toast.error { background: #b91c1c; }
.toast.ok { background: #065f46; }

/* ---------- 반응형 ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .guide-grid { grid-template-columns: 1fr; }
  .upload-row { flex-direction: column; }
  .upload-side { flex: 1 1 auto; }
}
@media (max-width: 620px) {
  body { font-size: 14px; }
  .topbar-inner { padding: 10px 14px 6px; }
  .brand-text .sub { display: none; }
  .tabs { padding: 0 14px; overflow-x: auto; }
  .container { padding: 16px 14px 48px; }
  h2 { font-size: 19px; }
  .card { padding: 14px; border-radius: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 11px 12px; }
  .stat strong { font-size: 20px; }
  .panel-actions { width: 100%; }
  .panel-actions .btn { flex: 1 1 auto; }
  .result-actions { width: 100%; justify-content: space-between; }
  .table { min-width: 680px; }
  .modal { padding: 18px; }
}

/* ---------- 부팅 ---------- */
.boot-box { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #cbd5e1; border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
