/* DWCI v2 공통 레이아웃·컴포넌트 (SPEC §6) — 전 화면 공용. 인라인 style 금지 전제. */

/* ---------- 리셋/베이스 ---------- */
/* hidden 속성은 항상 숨김(작성자 display 규칙이 UA [hidden]{display:none}를 이기는 문제 방지).
   .modal-overlay 등 display를 지정한 컴포넌트가 hidden 상태에서도 화면을 덮던 버그 교정. */
[hidden] { display: none !important; }
.mb-4 { margin-bottom: var(--sp-4); }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
}
img { max-width: 100%; display: block; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
::placeholder { color: var(--text-faint); }

.page-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.page-desc { color: var(--text-muted); margin-top: var(--sp-1); }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-6);
}
.page-head-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline-form { display: inline; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

/* ---------- 앱 셸: 사이드바 + 상단바 ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-width);
  display: flex; flex-direction: column;
  background: var(--sidebar-bg); color: var(--sidebar-text);
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  color: var(--sidebar-text-active);
}
.sidebar-logo { display: inline-flex; color: #818cf8; }
.sidebar-title { font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.sidebar-nav { flex: 1; padding: var(--sp-2) var(--sp-3); overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 10px var(--sp-3); margin-bottom: 2px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text); font-weight: var(--fw-medium);
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); text-decoration: none; }
.nav-item.is-active { background: var(--sidebar-active); color: var(--sidebar-text-active); }
.nav-icon { flex: none; opacity: 0.9; }
.sidebar-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--sidebar-border);
  font-size: var(--fs-xs); color: var(--text-faint);
}
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(15, 23, 42, 0.5);
}

.app-main {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-width);
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3);
  height: 60px; padding: 0 var(--sp-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: var(--sp-3); }
.topbar-user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-user-name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.topbar-user-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.sidebar-toggle { display: none; }

.content {
  flex: 1; width: 100%; max-width: 1280px;
  padding: var(--sp-8) var(--sp-6) var(--sp-12);
  margin: 0 auto;
}

/* ---------- 인증(비로그인) 레이아웃 ---------- */
.layout-auth { background: var(--bg); }
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
}
.auth-card-holder { width: 100%; max-width: 400px; }
.auth-card { padding: var(--sp-8); }
.auth-card-head { text-align: center; margin-bottom: var(--sp-6); }
.auth-logo {
  display: inline-flex; padding: var(--sp-3);
  border-radius: var(--radius-lg);
  background: var(--primary-soft); color: var(--primary);
  margin-bottom: var(--sp-3);
}
.auth-title { font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.auth-sub { color: var(--text-muted); margin-top: var(--sp-1); }

/* ---------- 카드 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
}
.card-narrow { max-width: 480px; }
.card-header { margin-bottom: var(--sp-5); }
.card-title { font-size: var(--fs-lg); font-weight: var(--fw-bold); }
.card-desc { color: var(--text-muted); margin-top: var(--sp-1); }
.card-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* KPI 카드 */
.kpi-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  margin-bottom: var(--sp-6);
}
.kpi-card { padding: var(--sp-5); }
.kpi-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: var(--fs-2xl); font-weight: var(--fw-bold); letter-spacing: -0.02em; margin-top: var(--sp-1); }
.kpi-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-1); }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition), box-shadow var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 22px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  background: transparent; border: none; border-radius: var(--radius-md);
  color: var(--text-muted); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 폼 ---------- */
.form-field { margin-bottom: var(--sp-4); }
.form-field-inline { display: flex; align-items: center; gap: var(--sp-3); }
.form-label { display: block; font-weight: var(--fw-semibold); margin-bottom: var(--sp-2); }
.form-label .required { color: var(--danger); }
.form-help { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-1); }
.form-error { font-size: var(--fs-xs); color: var(--danger); margin-top: var(--sp-1); }
.form-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-6); flex-wrap: wrap; }
.form-row { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.input, .select, .textarea {
  width: 100%; padding: 9px 12px;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--focus-ring);
}
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }
.textarea { min-height: 110px; resize: vertical; }
.select { appearance: auto; }
.checkbox { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* 검색/필터 툴바 */
.toolbar {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}
.toolbar .input, .toolbar .select { width: auto; }
.toolbar-search { position: relative; }
.toolbar-search .input { min-width: 240px; }
.toolbar-spacer { flex: 1; }

/* ---------- 테이블 ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td {
  padding: 11px var(--sp-4); text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.table th {
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--surface-2); white-space: nowrap;
}
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table-zebra tbody tr:nth-child(even) { background: var(--surface-2); }
.table-zebra tbody tr:hover { background: var(--primary-soft); }
.table .cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.table .cell-actions { text-align: right; white-space: nowrap; }
.table a.row-link { color: var(--text); font-weight: var(--fw-medium); }
.table a.row-link:hover { color: var(--primary); }
.table-thumb {
  width: 44px; height: 44px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------- 뱃지 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.badge-emoji { font-size: 11px; line-height: 1; }
.badge-pending { background: var(--warning-soft); color: var(--warning-soft-text); }
.badge-confirmed { background: var(--info-soft); color: var(--info-soft-text); }
.badge-shipped { background: var(--teal-soft); color: var(--teal-soft-text); }
.badge-completed { background: var(--success-soft); color: var(--success-soft-text); }
.badge-cancelled { background: var(--danger-soft); color: var(--danger-soft-text); }
.badge-rejected { background: var(--danger-soft); color: var(--danger-soft-text); }
.badge-neutral { background: var(--surface-2); color: var(--text-muted); }
.badge-primary { background: var(--primary-soft); color: var(--primary-soft-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-soft-text); }
.badge-count {
  min-width: 20px; justify-content: center; padding: 2px 7px;
  background: var(--danger); color: #fff;
}

/* ---------- flash / 토스트 ---------- */
.flash-stack { margin-bottom: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); }
.flash {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-weight: var(--fw-medium);
}
.flash-msg { flex: 1; }
.flash-close {
  border: none; background: transparent; cursor: pointer;
  color: inherit; font-size: var(--fs-md); line-height: 1; padding: 2px;
  opacity: 0.6;
}
.flash-close:hover { opacity: 1; }
.flash-success { background: var(--success-soft); border-color: #bbf7d0; color: var(--success-soft-text); }
.flash-error { background: var(--danger-soft); border-color: #fecaca; color: var(--danger-soft-text); }
.flash-warning { background: var(--warning-soft); border-color: #fde68a; color: var(--warning-soft-text); }
.flash-info { background: var(--info-soft); border-color: #bae6fd; color: var(--info-soft-text); }

#toast-root {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 90;
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: #1e293b; color: #f1f5f9;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-weight: var(--fw-medium);
  opacity: 0; transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast::before {
  content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%;
  background: var(--info);
}
.toast-success::before { background: var(--success); }
.toast-error::before { background: var(--danger); }
.toast-warning::before { background: var(--warning); }

/* ---------- 모달 / 확인 다이얼로그 ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  padding: var(--sp-5);
}
.modal {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-6);
  /* 내용이 뷰포트보다 길면 모달 내부 스크롤 — 제목·버튼이 화면 밖으로 잘리지 않게 */
  max-height: calc(100vh - var(--sp-10));
  overflow-y: auto;
}
.modal-lg { max-width: 720px; }
.modal-title { font-size: var(--fs-md); font-weight: var(--fw-bold); margin-bottom: var(--sp-2); }
.modal-body { color: var(--text-muted); word-break: break-word; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-6); }
body.modal-open { overflow: hidden; }

/* ---------- 페이지네이션 ---------- */
.pagination-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); flex-wrap: wrap;
  margin-top: var(--sp-5);
}
.pagination-info { font-size: var(--fs-xs); color: var(--text-muted); }
.pagination { display: flex; gap: var(--sp-1); list-style: none; margin: 0; padding: 0; }
.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  transition: background var(--transition), border-color var(--transition);
}
a.page-link:hover { background: var(--surface-2); text-decoration: none; }
.page-link.is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.is-disabled { opacity: 0.4; pointer-events: none; }
.page-link.is-ellipsis { border: none; background: transparent; color: var(--text-faint); }

/* ---------- 빈 상태 ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--sp-12) var(--sp-6);
  color: var(--text-muted);
}
.empty-icon { color: var(--border-strong); margin-bottom: var(--sp-4); }
.empty-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.empty-desc { margin-top: var(--sp-1); }
.empty-actions { margin-top: var(--sp-5); }

/* ---------- 아바타 ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; object-fit: cover;
  background: var(--primary-soft); color: var(--primary-soft-text);
  font-weight: var(--fw-bold); flex: none; overflow: hidden;
  border: 1px solid var(--border);
}
.avatar-sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar-md { width: 44px; height: 44px; font-size: var(--fs-sm); }
.avatar-lg { width: 80px; height: 80px; font-size: var(--fs-xl); }

/* ---------- 상품 카드 ---------- */
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.product-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.product-card-link { display: block; color: inherit; }
.product-card-link:hover { text-decoration: none; }
.product-card-thumb {
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
}
.product-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-card-noimg { color: var(--text-faint); }
.product-card-body { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3) var(--sp-4) var(--sp-4); }
.product-card-brand { font-size: var(--fs-xs); color: var(--text-muted); }
.product-card-name {
  font-weight: var(--fw-semibold);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.product-card-price { font-weight: var(--fw-bold); margin-top: 2px; }
.product-card-code { font-size: var(--fs-xs); color: var(--text-faint); }

/* ---------- 에러 페이지 ---------- */
.error-page {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: var(--sp-12) var(--sp-6);
}
.error-code { font-size: 56px; font-weight: var(--fw-bold); color: var(--border-strong); line-height: 1; }
.error-title { font-size: var(--fs-xl); font-weight: var(--fw-bold); margin-top: var(--sp-4); }
.error-msg { color: var(--text-muted); margin-top: var(--sp-2); }
.error-actions { margin-top: var(--sp-6); }

/* ---------- 구분/유틸 ---------- */
.divider { height: 1px; background: var(--border); border: none; margin: var(--sp-6) 0; }
.stack-v { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-h { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.section { margin-bottom: var(--sp-8); }
.section-title { font-size: var(--fs-md); font-weight: var(--fw-bold); margin-bottom: var(--sp-4); }

/* ---------- 반응형: 사이드바 드로어 ---------- */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .content { padding: var(--sp-5) var(--sp-4) var(--sp-10); }
  .topbar { padding: 0 var(--sp-4); }
  .topbar-user-meta { display: none; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .toolbar-search .input { min-width: 0; width: 100%; }
}
@media (min-width: 901px) {
  .sidebar-backdrop { display: none; }
}
