/* ======================================
   SellSync - Reusable UI Components
   ====================================== */

/* ─── Buttons ─── */
/* .btn { display: inline-flex } must not override the HTML hidden attribute */
[hidden] {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition-fast);
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 14px rgba(108, 99, 255, 0.35);
}
.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(108, 99, 255, 0.5);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 14px;
}

.btn-icon-only {
  padding: 8px;
  border-radius: var(--radius-sm);
}

/* ─── Stat Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: var(--spacing-lg);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
  cursor: default;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.stat-card:hover::before { opacity: 1; }
.stat-card:hover {
  border-color: var(--border-default);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon.purple { background: var(--primary-alpha); color: var(--primary-light); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.blue { background: var(--info-light); color: var(--info); }

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -1px;
}

.stat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-trend-up { color: var(--success); }
.stat-trend-down { color: var(--danger); }

/* ─── Data Table ─── */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
  flex-wrap: wrap;
}

.table-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.table-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-input {
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px 8px 34px;
  font-size: 13px;
  color: var(--text-primary);
  width: 220px;
  transition: all var(--transition-fast);
}
.search-input::placeholder { color: var(--text-placeholder); }
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
  width: 260px;
}

.filter-select {
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 30px 8px 12px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239395A8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: all var(--transition-fast);
}
.filter-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  padding: 11px 16px;
  background: var(--bg-elevated);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  text-align: left;
}

.data-table th:first-child { border-radius: 0; }

.data-table td {
  padding: 13px 16px;
  font-size: 13px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  transition: background var(--transition-fast);
}
.data-table tbody tr:hover {
  background: rgba(255,255,255,0.025);
}

/* ─── Status Badge ─── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.status-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-active { background: var(--success-light); color: var(--success); }
.status-warning { background: var(--warning-light); color: var(--warning); }
.status-danger { background: var(--danger-light); color: var(--danger); }
.status-info { background: var(--info-light); color: var(--info); }
.status-neutral { background: var(--bg-elevated); color: var(--text-secondary); }

/* ─── Info Banner ─── */
.info-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: var(--spacing-md);
}
.info-banner.info {
  background: var(--info-light);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: var(--info);
}
.info-banner.warning {
  background: var(--warning-light);
  border: 1px solid rgba(245, 158, 11, 0.2);
  color: var(--warning);
}
.info-banner.danger {
  background: var(--danger-light);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* ─── Empty State ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-xl);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.empty-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  max-width: 300px;
}

/* ─── Pagination ─── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-info {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}
.page-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.page-btn.active {
  background: var(--primary-alpha);
  color: var(--primary-light);
  border-color: rgba(108, 99, 255, 0.3);
  font-weight: 700;
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border-subtle);
}

/* ─── Form Elements ─── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}
.form-control::placeholder { color: var(--text-placeholder); }
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

.form-control-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239395A8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* 판매채널 선택 + 「가져오기」 — .form-control 의 width:100% 로 줄바꿈 되지 않도록 한 줄 고정 */
.sales-channel-pull-inline {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}
.sales-channel-pull-inline select.form-control {
  width: auto;
  min-width: 168px;
  max-width: 260px;
  flex: 0 0 auto;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* 상품 등록: 스캔 vs 직접 입력 — 상단 정렬(포커스 시 상태 문구로 오른쪽이 밀리지 않음) */
.form-row.pr-scan-dual-row {
  align-items: start;
}

.pr-scan-hid-status {
  margin-top: 8px;
  min-height: 1.35em;
  font-size: 12px;
  font-weight: 500;
  color: var(--success);
  visibility: hidden;
}
.pr-scan-hid-status.pr-scan-hid-status--visible {
  visibility: visible;
}

.pr-scan-manual-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: var(--radius-md);
  width: fit-content;
}

.tab-btn {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* Purchase order list — Boxhero-style status tabs */
.po-status-tabs {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px var(--spacing-lg);
  width: 100%;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.po-status-tabs .tab-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 2px 12px;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  box-shadow: none;
  white-space: nowrap;
}

.po-status-tabs .tab-btn:hover {
  color: var(--text-primary);
}

.po-status-tabs .tab-btn.active {
  background: transparent;
  color: var(--primary-light);
  font-weight: 600;
  box-shadow: none;
  border-bottom-color: var(--primary);
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-enter {
  animation: fadeInUp 0.3s ease;
}

/* ─── Chip / Tag ─── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* ─── Progress Bar ─── */
.progress-bar-wrap {
  width: 100%;
  height: 5px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transition: width var(--transition-slow);
}
.progress-bar-fill.danger { background: linear-gradient(90deg, var(--danger), #FF8A80); }
.progress-bar-fill.warning { background: linear-gradient(90deg, var(--warning), #FFD54F); }
.progress-bar-fill.success { background: linear-gradient(90deg, var(--success), #69F0AE); }

/* ─── Tooltip ─── */
[data-tooltip] {
  position: relative;
}
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  box-shadow: var(--shadow-md);
}

/* ─── Page help (collapsible summary + field ? icons) ─── */
.page-help {
  margin-bottom: 16px;
}
.page-help-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-tertiary);
  cursor: pointer;
}
.page-help-toggle:hover {
  color: var(--text-secondary);
}
.page-help-chevron {
  display: inline-block;
  font-size: 10px;
  transition: transform var(--transition-fast);
}
.page-help-toggle[aria-expanded="true"] .page-help-chevron {
  transform: rotate(180deg);
}
.page-help-panel {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.2);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-secondary);
}
.page-help-panel[hidden] {
  display: none;
}
.form-label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.help-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-tertiary);
  cursor: help;
  vertical-align: middle;
  position: relative;
  flex-shrink: 0;
}
.help-icon-btn:hover,
.help-icon-btn.is-active {
  color: var(--primary-light);
  border-color: rgba(108, 99, 255, 0.35);
}
.help-icon-btn::after {
  content: attr(data-help);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 180px;
  max-width: min(280px, 85vw);
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  text-align: left;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 9999;
}
.help-icon-btn:hover::after,
.help-icon-btn.is-active::after {
  opacity: 1;
  visibility: visible;
}

/* ─── Page header help (? top-right of title row) ─── */
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-title-row h1 {
  flex: 1;
  min-width: 0;
}
.page-header-help {
  position: relative;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}
.page-header-help-btn {
  width: 28px;
  height: 28px;
  font-size: 14px;
  font-weight: 800;
  background: rgba(108, 99, 255, 0.14);
  border-color: rgba(108, 99, 255, 0.45);
  color: var(--primary-light);
  box-shadow: 0 1px 3px rgba(108, 99, 255, 0.15);
}
.page-header-help-btn:hover,
.page-header-help-btn.is-active {
  background: rgba(108, 99, 255, 0.24);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}
.page-header-help .page-header-help-btn::after {
  content: none;
  display: none;
}
.page-header-help-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 280px;
  max-width: min(480px, 92vw);
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid rgba(108, 99, 255, 0.28);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.55;
  text-align: left;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 9999;
}
.page-header-help:hover .page-header-help-tooltip,
.page-header-help-btn.is-active + .page-header-help-tooltip {
  opacity: 1;
  visibility: visible;
}
