/* =====================================================================
   Components: buttons, cards, tables, forms, modals, badges, toast...
   ===================================================================== */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px; font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn--primary {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  border-color: transparent; color: #fff;
  box-shadow: var(--shadow-glow);
}
.btn--primary:hover { background: linear-gradient(135deg, var(--brand-400), var(--brand-500)); border-color: transparent; }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn--danger { color: var(--danger); border-color: var(--danger-bg); background: var(--danger-bg); }
.btn--danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn--sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn--icon { width: 38px; padding: 0; }
.btn--icon.btn--sm { width: 32px; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card__head h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.card__head .spacer { flex: 1; }
.card__body { padding: 20px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head__text h1 { margin: 0 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.page-head__text p { margin: 0; color: var(--text-3); font-size: 13.5px; }
.page-head__actions { margin-left: auto; display: flex; gap: 9px; flex-wrap: wrap; }

/* ---------- Toolbar (search/filter row) ---------- */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.toolbar .grow { flex: 1; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 13px; min-width: 220px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); color: var(--text-3);
  transition: all var(--transition);
}
.search-box:focus-within { border-color: var(--brand-400); box-shadow: 0 0 0 3px var(--brand-50); background: var(--surface); }
[data-theme="dark"] .search-box:focus-within { box-shadow: 0 0 0 3px rgba(59,99,240,0.2); }
.search-box input { border: none; background: transparent; outline: none; flex: 1; color: var(--text); }
.search-box svg { width: 16px; height: 16px; flex-shrink: 0; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 13px; border-radius: var(--r-full);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.chip__count { font-size: 11px; opacity: 0.7; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field label .req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea {
  height: 40px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2); color: var(--text);
  outline: none; width: 100%;
  transition: all var(--transition);
}
.textarea { height: auto; min-height: 84px; padding: 10px 13px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand-400); background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-50);
}
[data-theme="dark"] .input:focus, [data-theme="dark"] .select:focus, [data-theme="dark"] .textarea:focus { box-shadow: 0 0 0 3px rgba(59,99,240,0.2); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
.field--error .input, .field--error .select, .field--error .textarea { border-color: var(--danger); }
.field__err { font-size: 11.5px; color: var(--danger); }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch__track { width: 42px; height: 24px; border-radius: 999px; background: var(--border-strong); transition: background var(--transition); position: relative; flex-shrink: 0; }
.switch__track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform var(--transition); box-shadow: var(--shadow-sm); }
.switch input:checked + .switch__track { background: var(--brand-500); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  text-align: left; font-weight: 700; color: var(--text-2);
  padding: 12px 14px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px; letter-spacing: 0.2px;
  user-select: none;
}
table.grid thead th.sortable { cursor: pointer; }
table.grid thead th.sortable:hover { color: var(--text); }
table.grid thead th .th-sort { margin-left: 5px; opacity: 0.4; font-size: 10px; }
table.grid thead th.sorted .th-sort { opacity: 1; color: var(--brand-500); }
table.grid tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; color: var(--text); }
table.grid tbody tr { transition: background var(--transition); }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.center, table.grid th.center { text-align: center; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions .icon-btn { width: 30px; height: 30px; }
.row-actions .icon-btn svg { width: 15px; height: 15px; }
.cell-strong { font-weight: 700; }
.cell-code { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 12.5px; color: var(--brand-600); font-weight: 600; }
[data-theme="dark"] .cell-code { color: var(--brand-300); }

.checkbox { width: 17px; height: 17px; accent-color: var(--brand-500); cursor: pointer; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 10px; border-radius: var(--r-full);
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--success); background: var(--success-bg); }
.badge--warning { color: var(--warning); background: var(--warning-bg); }
.badge--danger  { color: var(--danger);  background: var(--danger-bg); }
.badge--info    { color: var(--info);    background: var(--info-bg); }
.badge--neutral { color: var(--neutral); background: var(--neutral-bg); }
.badge--brand   { color: var(--brand-600); background: var(--brand-50); }
[data-theme="dark"] .badge--brand { color: var(--brand-300); background: rgba(59,99,240,0.16); }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.pagination .info { color: var(--text-3); font-size: 13px; }
.pagination .spacer { flex: 1; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager button {
  min-width: 34px; height: 34px; padding: 0 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--r-sm); color: var(--text-2); font-weight: 600; font-size: 13px;
  transition: all var(--transition);
}
.pager button:hover:not(:disabled) { border-color: var(--brand-400); color: var(--brand-600); }
.pager button.active { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.pager button:disabled { opacity: 0.4; pointer-events: none; }
.page-size { display: flex; align-items: center; gap: 7px; color: var(--text-3); font-size: 13px; }
.page-size select { height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); color: var(--text); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 22, 40, 0.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn 160ms ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 640px; max-height: 90vh;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn 240ms cubic-bezier(0.16, 1, 0.3, 1);
}
.modal--wide { max-width: 920px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal__head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal__head h3 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.modal__head .spacer { flex: 1; }
.modal__body { padding: 22px; overflow-y: auto; }
.modal__foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .col-2 { grid-column: span 2; }
@media (max-width: 620px) { .form-grid { grid-template-columns: 1fr; } .form-grid .col-2 { grid-column: span 1; } }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px;
  min-width: 280px; max-width: 380px; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg);
  animation: toastIn 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
.toast.out { animation: toastOut 200ms ease forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }
.toast__ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.toast__ico svg { width: 18px; height: 18px; }
.toast--success .toast__ico { background: var(--success-bg); color: var(--success); }
.toast--error .toast__ico { background: var(--danger-bg); color: var(--danger); }
.toast--info .toast__ico { background: var(--info-bg); color: var(--info); }
.toast__msg { flex: 1; font-size: 13.5px; font-weight: 500; }

/* ---------- Empty / Loading ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-3); }
.empty svg { width: 56px; height: 56px; opacity: 0.4; margin-bottom: 14px; }
.empty h4 { margin: 0 0 4px; font-size: 16px; color: var(--text-2); }
.empty p { margin: 0; font-size: 13.5px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--brand-500); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- KPI stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px 20px; box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stat__label { font-size: 13px; color: var(--text-3); font-weight: 600; }
.stat__ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.stat__ico svg { width: 21px; height: 21px; }
.stat__value { font-size: 28px; font-weight: 800; letter-spacing: -0.8px; font-variant-numeric: tabular-nums; }
.stat__value small { font-size: 14px; font-weight: 600; color: var(--text-3); margin-left: 3px; }
.stat__trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 700; margin-top: 8px; }
.stat__trend.up { color: var(--success); }
.stat__trend.down { color: var(--danger); }
.stat__trend svg { width: 14px; height: 14px; }
.stat::after { content: ''; position: absolute; right: -30px; bottom: -30px; width: 100px; height: 100px; border-radius: 50%; background: var(--brand-50); opacity: 0.5; }
[data-theme="dark"] .stat::after { background: rgba(59,99,240,0.08); }

.ico-tint-brand { background: var(--brand-50); color: var(--brand-500); }
.ico-tint-teal { background: rgba(0,194,168,0.12); color: var(--accent); }
.ico-tint-violet { background: rgba(124,77,255,0.12); color: var(--accent-2); }
.ico-tint-amber { background: var(--warning-bg); color: var(--warning); }
.ico-tint-green { background: var(--success-bg); color: var(--success); }
.ico-tint-red { background: var(--danger-bg); color: var(--danger); }
[data-theme="dark"] .ico-tint-brand { background: rgba(59,99,240,0.16); color: var(--brand-300); }

/* ---------- Misc layout helpers ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1000px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.flex { display: flex; align-items: center; gap: 10px; }
.flex-col { display: flex; flex-direction: column; gap: 10px; }
.between { justify-content: space-between; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.hidden { display: none !important; }

/* =====================================================================
   POP (생산시점관리) — 작업자 단말 친화 UI
   ===================================================================== */
.pop-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.pop-worker {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-full); box-shadow: var(--shadow-sm);
}
.pop-worker .avatar { width: 34px; height: 34px; }
.pop-worker select { border: none; background: transparent; color: var(--text); font-weight: 700; font-size: 15px; outline: none; cursor: pointer; }

.pop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.pop-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px 20px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.pop-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--brand-300); }
.pop-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--brand-500); }
.pop-card.s-대기::before { background: var(--neutral); }
.pop-card.s-작업중::before { background: var(--warning); }
.pop-card.s-완료::before { background: var(--success); }
.pop-card.s-중단::before { background: var(--danger); }
.pop-card__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.pop-card__no { font-family: ui-monospace, monospace; font-size: 15px; font-weight: 800; color: var(--brand-600); }
[data-theme="dark"] .pop-card__no { color: var(--brand-300); }
.pop-card__item { font-size: 19px; font-weight: 800; letter-spacing: -0.4px; margin-bottom: 4px; }
.pop-card__meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-3); font-size: 13px; margin-bottom: 14px; }
.pop-card__meta b { color: var(--text-2); font-weight: 600; }
.pop-card__foot { display: flex; align-items: center; justify-content: space-between; padding-top: 12px; border-top: 1px solid var(--border); }
.pop-card__qty { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.pop-card__qty small { font-size: 13px; color: var(--text-3); font-weight: 600; }
.pop-card__prog { font-size: 12.5px; color: var(--text-3); font-weight: 700; }

/* POP 상세 */
.pop-detail-head {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px 24px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.pop-detail-head .d-no { font-family: ui-monospace, monospace; font-size: 17px; font-weight: 800; color: var(--brand-600); }
.pop-detail-head .d-item { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.pop-detail-head .d-spacer { flex: 1; }
.pop-detail-head .d-metric { text-align: center; }
.pop-detail-head .d-metric .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.pop-detail-head .d-metric .l { font-size: 12px; color: var(--text-3); font-weight: 600; margin-top: 5px; }

.proc-step {
  display: flex; align-items: center; gap: 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 22px; margin-bottom: 12px; box-shadow: var(--shadow-sm);
  transition: border-color var(--transition);
}
.proc-step.s-진행 { border-color: var(--warning); box-shadow: 0 0 0 3px var(--warning-bg); }
.proc-step.s-완료 { border-color: var(--success); }
.proc-step__seq {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 15px;
  display: grid; place-items: center; font-size: 20px; font-weight: 800;
  background: var(--surface-2); color: var(--text-3);
}
.proc-step.s-진행 .proc-step__seq { background: var(--warning-bg); color: var(--warning); }
.proc-step.s-완료 .proc-step__seq { background: var(--success-bg); color: var(--success); }
.proc-step__body { flex: 1; min-width: 0; }
.proc-step__name { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; }
.proc-step__sub { color: var(--text-3); font-size: 13px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.proc-step__times { display: flex; gap: 18px; font-size: 12.5px; color: var(--text-2); margin-top: 6px; }
.proc-step__times .mono { font-weight: 700; }
.proc-step__actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.btn--pop { height: 50px; padding: 0 26px; font-size: 16px; border-radius: 14px; font-weight: 800; }
.btn--start { background: linear-gradient(135deg, var(--success), #12823b); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(22,163,74,0.32); }
.btn--start:hover { filter: brightness(1.06); }
.btn--end { background: linear-gradient(135deg, var(--danger), #b01c1c); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(220,38,38,0.3); }
.btn--end:hover { filter: brightness(1.06); }
@media (max-width: 720px) {
  .proc-step { flex-wrap: wrap; }
  .proc-step__actions { width: 100%; }
  .btn--pop { flex: 1; }
}

/* 라우팅(제품별표준공정) 좌측 품목 리스트 */
.rt-item { transition: background var(--transition); }
.rt-item:hover { background: var(--surface-2); }
.rt-item.active { background: var(--brand-50) !important; }
[data-theme="dark"] .rt-item.active { background: rgba(59,99,240,0.16) !important; }

/* progress bar */
.progress { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--brand-400), var(--brand-600)); transition: width 400ms ease; }
