/* ========================================================
   Enterprise Backoffice High-Density UI/UX Design System
   전사 공통 디자인 토큰 및 고밀도 백오피스 컴포넌트 스타일시트
   규칙: 안전성 > 일관성 > 생산성 > 미관
   ======================================================== */

@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

:root {
  /* 1. 디자인 토큰 (3장) */
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --bg-page: #F5F6F8;
  --bg-surface: #FFFFFF;
  --border: #E2E5EA;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;

  /* 상태 토큰 */
  --status-success: #16A34A;
  --status-success-bg: #DCFCE7;
  --status-info: #2563EB;
  --status-info-bg: #DBEAFE;
  --status-warning: #D97706;
  --status-warning-bg: #FEF3C7;
  --status-danger: #DC2626;
  --status-danger-bg: #FEE2E2;
  --status-neutral: #6B7280;
  --status-neutral-bg: #F3F4F6;

  /* 크기 및 간격 */
  --radius-ctrl: 4px;
  --radius-card: 8px;
  --radius-badge: 4px;
  --ctrl-height: 32px;
  --ctrl-min-height: 28px;
  --table-row-height: 36px;
  --table-row-compact: 32px;
  --lnb-width: 240px;
  --lnb-collapsed-width: 64px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, Roboto, "Helvetica Neue", "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  background-color: var(--bg-page);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
}

/* 숫자 폰트 tabular-nums 적용 */
.tabular-num, .metric-value, td, .price, .count {
  font-variant-numeric: tabular-nums;
}

/* 레이아웃 구조 */
.app-container {
  display: flex;
  min-height: 100vh;
  background-color: var(--bg-page);
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: auto;
  transition: margin-left 0.2s ease;
}

/* 상단 헤더 바 (고밀도 48px) */
.global-header, .top-header {
  height: 48px;
  min-height: 48px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breadcrumb-trail, .breadcrumbs {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.breadcrumb-home {
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.breadcrumb-home:hover {
  color: var(--primary);
}
.breadcrumb-sep {
  color: #cbd5e1;
}
.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

.market-status-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: var(--status-info-bg);
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  font-size: 11.5px;
  color: var(--primary);
  font-weight: 500;
}

.market-status-bar .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-success);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: var(--radius-ctrl);
  border: 1px solid var(--border);
  background: var(--bg-page);
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 600;
}

.user-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b06000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 브레드크럼 */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.breadcrumbs span.current {
  color: var(--text-primary);
  font-weight: 600;
}

.breadcrumbs svg {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.server-clock {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 본문 영역 */
.content-area {
  flex: 1;
  padding: 16px 20px;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* 페이지 타이틀 박스 */
.page-title-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* 카드 규격 (그림자 없음, 테두리만) */
.panel-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: none !important;
  margin-bottom: 16px;
}

/* 컨트롤 (버튼 / 인풋 32px 규격) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ctrl-height);
  padding: 0 12px;
  font-size: 12.5px;
  font-weight: 500;
  border-radius: var(--radius-ctrl);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background-color: #ffffff;
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover {
  background-color: var(--bg-page);
  border-color: #cbd5e1;
}

.btn-danger {
  background-color: var(--status-danger);
  color: #ffffff;
  border-color: var(--status-danger);
}

.btn-danger-outline {
  background-color: #ffffff;
  color: var(--status-danger);
  border-color: var(--status-danger);
}

.btn-danger-outline:hover {
  background-color: var(--status-danger-bg);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed !important;
}

/* 폼 인풋 */
.search-input, .form-input, select.search-input {
  height: var(--ctrl-height);
  padding: 0 10px;
  font-size: 12.5px;
  color: var(--text-primary);
  background-color: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  transition: border-color 0.15s ease;
}

.search-input:focus, .form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.form-label .required {
  color: var(--status-danger);
  margin-left: 2px;
}

/* 상태 뱃지 (4px 라운드, 텍스트 라벨 필수) */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-badge);
  line-height: 1.2;
}

.badge-success {
  color: var(--status-success);
  background-color: var(--status-success-bg);
}

.badge-info {
  color: var(--status-info);
  background-color: var(--status-info-bg);
}

.badge-warning {
  color: var(--status-warning);
  background-color: var(--status-warning-bg);
}

.badge-danger {
  color: var(--status-danger);
  background-color: var(--status-danger-bg);
}

.badge-neutral {
  color: var(--status-neutral);
  background-color: var(--status-neutral-bg);
}

/* 데이터 테이블 (행 높이 36px) */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  background-color: var(--bg-surface);
}

.data-table thead th {
  height: var(--table-row-height);
  padding: 0 12px;
  background-color: var(--bg-page);
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table tbody td {
  height: var(--table-row-height);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.data-table.compact thead th,
.data-table.compact tbody td {
  height: var(--table-row-compact);
  padding: 0 8px;
}

.data-table tbody tr:hover {
  background-color: #fafbfc;
}

.data-table th.sticky-col,
.data-table td.sticky-col {
  position: sticky;
  left: 0;
  background-color: inherit;
  z-index: 2;
}

/* 일괄 선택 바 ("N건 선택됨") */
.bulk-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-ctrl);
  padding: 6px 12px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: #1e40af;
}

/* 메트릭 그리드 (KPI 카드) */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  box-shadow: none !important;
}

.metric-title {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.metric-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 4px 0 2px 0;
}

.metric-delta {
  font-size: 11px;
  font-weight: 500;
}

.metric-delta.up { color: var(--status-success); }
.metric-delta.down { color: var(--status-danger); }

/* Toast 알림 시스템 (우상단 3개 스택) */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 400px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  animation: slideInRight 0.2s ease forwards;
}

.toast-success { border-left: 4px solid var(--status-success); }
.toast-error { border-left: 4px solid var(--status-danger); }
.toast-info { border-left: 4px solid var(--status-info); }
.toast-warning { border-left: 4px solid var(--status-warning); }

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

/* 모달 오버레이 */
.modal-overlay {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}


/* ========================================================
   Pipeline Stepper & Panel Card Components
   7대 핵심 운영 파이프라인 및 모니터링 패널
   ======================================================== */

.pipeline-section {
  margin-bottom: 16px;
}

.pipeline-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
}

.pipeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.pipeline-title {
  display: flex;
  align-items: center;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.pipeline-stepper {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.step-item {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-ctrl);
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
}

.step-item:hover {
  border-color: var(--primary);
  background: #f0f7ff;
}

.step-item.active {
  border-color: var(--primary);
  background: var(--status-info-bg);
}

.step-item.active .step-num {
  color: var(--primary);
  font-weight: 700;
}

.step-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.step-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step-status {
  font-size: 11.5px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* 패널 카드 */
.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  margin-bottom: 16px;
  overflow: hidden;
}

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

.panel-title {
  display: flex;
  align-items: center;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
}

.product-thumb-preview {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-ctrl);
  background: var(--bg-page);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}


/* ========================================================
   3대 표준 상태 인디케이터 (녹색 / 빨간색 / 회색)
   - 녹색: 정상 연동됨 (Connected)
   - 빨간색: API 통신 / 연결 문제 (Error)
   - 회색: 미연동 (Disconnected)
   ======================================================== */
.status-indicator-dot {
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}
.status-indicator-dot.online {
  background-color: var(--status-success, #16A34A);
  box-shadow: 0 0 0 2px var(--status-success-bg, #DCFCE7);
}
.status-indicator-dot.offline {
  background-color: var(--status-danger, #DC2626);
  box-shadow: 0 0 0 2px var(--status-danger-bg, #FEE2E2);
}
.status-indicator-dot.neutral {
  background-color: #9CA3AF;
  box-shadow: 0 0 0 2px #F3F4F6;
}


/* ========================================================
   글로벌 아이콘 & 반응형 안전 패치 (v20261019)
   ======================================================== */
i[data-lucide], svg.lucide {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.search-input, .form-input, select.search-input, select.select-box {
  min-width: 0;
  box-sizing: border-box;
}

/* 모바일 & 태블릿 반응형 미디어 쿼리 */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }
  .snb-area {
    width: 100% !important;
    min-width: 100% !important;
    height: auto !important;
    position: static !important;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content-area {
    padding: 12px;
    max-width: 100%;
  }
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .pipeline-stepper {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
  .pipeline-stepper {
    grid-template-columns: 1fr;
  }
  .global-header {
    padding: 0 10px;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .header-left, .header-right {
    gap: 6px;
  }
  .server-clock {
    display: none !important;
  }
  .market-status-bar {
    display: none !important;
  }
}

/* ?????& ?????????????????? (v20261026 ????? */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }
  .snb-area {
    width: 100% !important;
    min-width: 100% !important;
    height: auto !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 300 !important;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .global-header, .top-header {
    position: static;
    height: auto;
    min-height: 44px;
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .content-area {
    padding: 12px;
    max-width: 100%;
    overflow-x: hidden;
  }
  .metric-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .pipeline-stepper {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
  }
  /* ???????? ?????4~6??????? ????????) ????????????? ????*/
  div[style*="grid-template-columns: repeat(6"],
  div[style*="grid-template-columns:repeat(6"],
  div[style*="grid-template-columns: repeat(5"],
  div[style*="grid-template-columns:repeat(5"],
  div[style*="grid-template-columns: repeat(4"],
  div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  div[style*="grid-template-columns: 320px 1fr"],
  div[style*="grid-template-columns: 1.15fr 0.85fr"],
  div[style*="grid-template-columns: 1.2fr 1fr 1fr 1.6fr auto"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  /* ???????? ??????? ???????? */
  .panel-card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 12.5px;
  }
  .content-area {
    padding: 10px 8px;
  }
  .global-header, .top-header {
    padding: 6px 10px;
    min-height: 42px;
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-left, .header-right {
    gap: 6px;
    flex-wrap: wrap;
  }
  .breadcrumb-trail, .breadcrumbs {
    font-size: 11.5px;
    max-width: 210px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .server-clock,
  .market-status-bar,
  .user-profile-badge .user-name {
    display: none !important;
  }
  /* ????? ??? ????? & ??? ??? ???????? */
  .page-title-box,
  .panel-header,
  .pipeline-header,
  .bulk-action-bar {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }
  .page-title-box > div,
  .panel-header > div,
  .bulk-action-bar > div {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .page-title {
    font-size: 16px;
  }
  /* KPI ??? 2????? (?????????????) */
  .metric-grid,
  div[style*="grid-template-columns: repeat(6"],
  div[style*="grid-template-columns:repeat(6"],
  div[style*="grid-template-columns: repeat(5"],
  div[style*="grid-template-columns:repeat(5"],
  div[style*="grid-template-columns: repeat(4"],
  div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .metric-card {
    padding: 10px 12px !important;
  }
  .metric-value {
    font-size: 17px !important;
  }
  /* 7??? ??????????2~3????? ????? 1????? ??? */
  .pipeline-stepper,
  div[style*="grid-template-columns: repeat(3"],
  div[style*="grid-template-columns:repeat(3"],
  div[style*="grid-template-columns: 1fr 1fr"],
  div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  /* ?????min-width ??? ??? (???????????? ???) */
  div[style*="min-width:260px"],
  div[style*="min-width: 260px"],
  div[style*="min-width:280px"],
  div[style*="min-width: 280px"],
  div[style*="min-width:220px"],
  div[style*="min-width: 220px"],
  select[style*="min-width"],
  input[style*="min-width"],
  .search-input,
  .select-box {
    min-width: 0 !important;
    max-width: 100% !important;
  }
  /* ??????? ????? ???????????????????*/
  .panel-card div[style*="flex-wrap:wrap"] > div[style*="min-width"],
  .panel-card div[style*="flex-wrap: wrap"] > div[style*="min-width"],
  .panel-card div[style*="flex-wrap:wrap"] > select.select-box,
  .panel-card div[style*="flex-wrap: wrap"] > select.select-box {
    flex: 1 1 100% !important;
    width: 100% !important;
  }
  /* ???????????? ??? ????????? ?????*/
  .data-table {
    font-size: 12px;
  }
  .data-table thead th,
  .data-table tbody td {
    padding: 6px 8px !important;
  }
  /* ??? ?????????? ??? */
  .modal-overlay > div,
  div[style*="position:fixed"][style*="z-index"] > div {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: 90vh !important;
    margin: 8px !important;
    padding: 14px !important;
    overflow-y: auto !important;
  }
  /* Toast ??????????????? */
  #toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }
  .toast {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 380px) {
  .metric-grid,
  div[style*="grid-template-columns: repeat(6"],
  div[style*="grid-template-columns:repeat(6"],
  div[style*="grid-template-columns: repeat(4"],
  div[style*="grid-template-columns:repeat(4"] {
    grid-template-columns: 1fr !important;
  }
}
