:root {
  --ink: #23272b;
  --steel: #5b6570;
  --muted: #8a929b;
  --line: #e3e6ea;
  --line-2: #eef0f3;
  --surface: #ffffff;
  --canvas: #f5f6f8;
  --biju: #e8790f;
  --biju-strong: #cf6a09;
  --biju-tint: #fef2e6;
  --ok: #1f9d63;
  --work: #2b6cb0;
  --danger: #d64545;
  --danger-tint: #fdecec;

  --data: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas,
    "Liberation Mono", monospace;
  --ui: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo",
    "Noto Sans KR", sans-serif;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(35, 39, 43, 0.06), 0 6px 20px rgba(35, 39, 43, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--biju);
  outline-offset: 2px;
}

/* ---------------- 로그인 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 400px at 50% -10%, #ffffff 0%, var(--canvas) 60%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 28px 28px;
}
.login-card img.logo { height: 26px; display: block; margin-bottom: 22px; }
.login-card h1 {
  font-size: 16px; margin: 0 0 2px; letter-spacing: -0.01em;
}
.login-card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 22px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--steel); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #fcfcfd; color: var(--ink);
}
.field input:focus { border-color: var(--biju); background: #fff; }
.btn-primary {
  width: 100%; margin-top: 8px; padding: 11px 14px;
  background: var(--biju); color: #fff; border: none;
  border-radius: var(--radius); font-size: 14px; font-weight: 600;
}
.btn-primary:hover { background: var(--biju-strong); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.login-error {
  display: none; margin-top: 12px; padding: 9px 11px; font-size: 12.5px;
  background: var(--danger-tint); color: var(--danger);
  border: 1px solid #f3c9c9; border-radius: var(--radius);
}
.login-error.show { display: block; }

/* ---------------- 앱 상단바 ---------------- */
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  position: sticky; top: 0; z-index: 20;
}
.topbar img.logo { height: 20px; }
.topbar .vendor {
  font-weight: 600; letter-spacing: -0.01em;
  padding-left: 16px; margin-left: 4px; border-left: 1px solid var(--line);
}
.topbar .vendor small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.topbar .spacer { flex: 1; }

.bell {
  position: relative; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: #fff; display: grid; place-items: center;
}
.bell:hover { border-color: var(--biju); }
.bell svg { width: 18px; height: 18px; stroke: var(--steel); fill: none; stroke-width: 1.8; }
.bell .badge {
  position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 9px; background: var(--biju); color: #fff;
  font-size: 11px; font-weight: 700; font-family: var(--data);
  display: none; align-items: center; justify-content: center; line-height: 1;
}
.bell .badge.show { display: flex; }
.linkbtn { background: none; border: none; color: var(--steel); font-size: 13px; padding: 8px; }
.linkbtn:hover { color: var(--ink); }

/* ---------------- 탭 ---------------- */
.tabs {
  display: flex; gap: 4px; padding: 14px 20px 0; background: var(--canvas);
  position: sticky; top: 56px; z-index: 10;
}
.tab {
  background: none; border: none; padding: 9px 14px 12px; font-size: 13.5px;
  color: var(--steel); border-bottom: 2px solid transparent; font-weight: 500;
}
.tab .cnt {
  font-family: var(--data); font-size: 11.5px; margin-left: 6px;
  color: var(--muted); background: var(--line-2); padding: 1px 6px; border-radius: 10px;
}
.tab.active { color: var(--ink); border-bottom-color: var(--biju); font-weight: 600; }
.tab.active .cnt { color: var(--biju); background: var(--biju-tint); }

/* ---------------- 테이블 ---------------- */
.content { padding: 12px 20px 40px; }
.table-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
}
.tbl-scroll { overflow-x: auto; }
table.orders { width: 100%; border-collapse: collapse; min-width: 1040px; }
table.orders th, table.orders td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-2);
  white-space: nowrap; vertical-align: middle;
}
table.orders thead th {
  position: sticky; top: 0; background: #fbfbfc; z-index: 1;
  font-size: 11.5px; font-weight: 600; color: var(--steel);
  letter-spacing: .02em; border-bottom: 1px solid var(--line);
}
table.orders tbody tr:hover { background: #fbfaf8; }
td.num, th.num { text-align: right; font-family: var(--data); font-size: 13px; }
td.code { font-family: var(--data); font-size: 12.5px; color: var(--steel); }
td.name { white-space: normal; min-width: 180px; font-weight: 500; }
.remaining { font-weight: 700; }
.remaining.zero { color: var(--muted); font-weight: 500; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px;
  padding: 2px 8px; border-radius: 20px; font-weight: 600;
}
.pill.unprocessed { background: var(--biju-tint); color: var(--biju-strong); }
.pill.processed { background: #eef4fb; color: var(--work); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.urgent {
  color: var(--danger); font-weight: 700; font-size: 11px;
  background: var(--danger-tint); padding: 2px 7px; border-radius: 4px;
}

select.state {
  font-family: var(--ui); font-size: 12.5px; padding: 5px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}
select.state[data-state=""] { color: var(--biju-strong); border-color: #f2cfa8; background: var(--biju-tint); }
select.state[data-state="접수"] { color: var(--steel); }
select.state[data-state="작업"] { color: var(--work); border-color: #cfe0f2; }
select.state[data-state="완료"] { color: var(--ok); border-color: #c6e8d5; background: #f2fbf6; }

.btn-print {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 5px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn-print:hover { border-color: var(--biju); color: var(--biju-strong); }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--steel); margin-bottom: 4px; font-size: 15px; }

.statusbar {
  padding: 8px 20px; font-size: 12px; color: var(--muted); font-family: var(--data);
}

/* ---------------- 모달 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(35, 39, 43, .38);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 520px;
  box-shadow: 0 12px 40px rgba(0,0,0,.22); max-height: 86vh; display: flex; flex-direction: column;
}
.modal header {
  padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px;
}
.modal header .h {
  width: 30px; height: 30px; border-radius: 8px; background: var(--biju-tint);
  color: var(--biju-strong); display: grid; place-items: center; flex: none;
}
.modal header h2 { font-size: 15px; margin: 0; }
.modal header p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.modal .body { padding: 16px 20px; overflow-y: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.btn-ghost { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 9px 14px; font-size: 13px; }
.btn-ghost:hover { border-color: var(--steel); }

.unread-item {
  display: flex; justify-content: space-between; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--line-2); font-size: 13px;
}
.unread-item:last-child { border-bottom: none; }
.unread-item .k { font-family: var(--data); font-size: 12px; color: var(--steel); }
.unread-item .q { font-family: var(--data); font-weight: 600; }

/* 라벨 출력 팝업 폼 */
.form-row { display: flex; gap: 12px; margin-bottom: 14px; }
.form-row .field { flex: 1; margin: 0; }
.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin-bottom: 16px; }
.info-grid dt { color: var(--muted); }
.info-grid dd { margin: 0; font-family: var(--data); }
.remain-box {
  background: var(--canvas); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px; display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px;
}
.remain-box .v { font-family: var(--data); font-size: 20px; font-weight: 700; }
.remain-box .v.neg { color: var(--danger); }

/* ---------------- 인쇄용 라벨 ---------------- */
#print-root { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-root, #print-root * { visibility: visible; }
  #print-root { display: block; position: absolute; inset: 0; }
  .pallet-label { page-break-after: always; }
}
.pallet-label {
  width: 100%; min-height: 100vh; padding: 10mm;
  display: flex; flex-direction: column; font-family: var(--ui); color: #000;
}
.pl-top {
  flex: 0 0 33%; display: flex; align-items: center; gap: 8mm;
  border-bottom: 3px solid #000; padding-bottom: 6mm;
}
.pl-qr { flex: none; }
.pl-qr svg, .pl-qr img { width: 44mm; height: 44mm; }
.pl-code .lbl { font-size: 5mm; color: #333; letter-spacing: .05em; }
.pl-code .code { font-size: 16mm; font-weight: 800; line-height: 1.05; font-family: var(--data); word-break: break-all; }
.pl-bot { flex: 1; padding-top: 6mm; }
.pl-bot table { width: 100%; border-collapse: collapse; }
.pl-bot td { border: 1px solid #000; padding: 3mm 4mm; font-size: 4.6mm; }
.pl-bot td.th { background: #f0f0f0; font-weight: 700; width: 34%; }
.pl-bot td.big { font-size: 7mm; font-weight: 700; font-family: var(--data); }
.pl-foot { margin-top: 5mm; font-size: 3.4mm; color: #555; display: flex; justify-content: space-between; }

@media (max-width: 640px) {
  .topbar .vendor { padding-left: 10px; }
  .content { padding: 10px; }
  .tabs { padding: 10px 10px 0; }
}
