/* 약품 재고 체크 - 모던 대시보드 스타일 */

/* ============= CSS 변수 및 기본 설정 ============= */
:root {
  /* 라이트 테마 */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  /* 브랜드 컬러 - 모던하고 세련된 색상 조합 */
  --primary: #7c3aed;      /* 보라색 - 메인 액센트 */
  --primary-dark: #6d28d9;  /* 진한 보라 */
  --success: #14b8a6;      /* 청록색 - 긍정적 상태 */
  --warning: #8b5cf6;      /* 연보라 - 주의 상태 */
  --danger: #f43f5e;       /* 로즈핑크 - 긴급/오류 */
  
  /* 그라디언트 - 세련된 현대적 그라데이션 */
  --gradient-primary: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  --gradient-success: linear-gradient(135deg, #06b6d4 0%, #14b8a6 100%);
  --gradient-warning: linear-gradient(135deg, #a855f7 0%, #8b5cf6 100%);
  --gradient-danger: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
}

/* 다크 테마 */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: #334155;
}

/* ============= 기본 요소 스타일링 ============= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: all 0.3s ease;
}

/* ============= 네비게이션 ============= */
.top-nav {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.nav-brand i {
  font-size: 1.5rem;
  color: var(--primary);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.system-settings-btn, .theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.5rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.system-settings-btn:hover, .theme-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* 아이콘 + 텍스트 라벨 네비 버튼 */
.nav-label-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============= 메인 컨테이너 ============= */
.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ============= 대시보드 헤더 ============= */
.dashboard-header {
  text-align: center;
}

.dashboard-header h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ============= 컨트롤 패널 ============= */
.control-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2rem;
  align-items: start;
}

.control-card {
  display: flex;
  gap: 1rem;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem 2rem;
  border: none;
  border-radius: 16px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
  position: relative;
  overflow: hidden;
}

.control-btn i {
  font-size: 1.5rem;
}

.control-btn.primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: var(--shadow-md);
}

.control-btn.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.control-btn.danger {
  background: var(--gradient-danger);
  color: white;
  box-shadow: var(--shadow-md);
}

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

/* ============= 상태 그리드 ============= */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.status-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.status-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  z-index: 200;
}

.status-icon {
  width: 48px;
  height: 48px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 1.25rem;
}

.status-content h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.status-content p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
}

/* ============= 결과 섹션 ============= */
.results-section {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 2rem;
}

/* ============= 로그 패널 ============= */
.log-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 850px;
}

.log-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: between;
  align-items: center;
  background: var(--bg-tertiary);
}

.log-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.clear-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.log-content {
  flex: 1;
  overflow-y: auto;
  background: #1a1a1a;
  color: #ffffff;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
}

.log-placeholder {
  padding: 2rem;
  text-align: center;
  color: #6b7280;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.log-placeholder i {
  font-size: 2rem;
  opacity: 0.5;
}

/* 로그 라인 스타일 */
.log-line {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line:last-child {
  border-bottom: none;
}

.log-line.log-info { color: #d1d5db; }
.log-line.log-success { color: #d1d5db; }
.log-line.log-warning { color: #d1d5db; }
.log-line.log-error { color: #d1d5db; }
.log-line.log-search { color: #d1d5db; }

/* 스크롤바 스타일링 */
.log-content::-webkit-scrollbar {
  width: 6px;
}

.log-content::-webkit-scrollbar-track {
  background: #2a2a2a;
}

.log-content::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 3px;
}

.log-content::-webkit-scrollbar-thumb:hover {
  background: #6a6a6a;
}

/* ============= 결과 대시보드 ============= */
.results-dashboard {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: 0;
}

/* ============= 상세 결과 ============= */
.detailed-results {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-height: 850px;
}

.results-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-tertiary);
}

.results-header h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.results-header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.results-stats {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-item {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  position: relative;
}

.stat-item i {
  font-size: 1rem;
}

.stat-item .stat-label {
  font-weight: 500;
}

.stat-item strong {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  min-width: 1ch;
}

.stat-item.stat-success i,
.stat-item.stat-success strong {
  color: var(--success);
}

.stat-item.stat-warning i,
.stat-item.stat-warning strong {
  color: var(--warning);
}

.stat-item.stat-danger i,
.stat-item.stat-danger strong {
  color: var(--danger);
}

.last-update {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.results-content {
  padding: 1rem;
  min-height: 300px;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* 결과 컬럼 구성 */
.results-columns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.results-col {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
}


.col-body {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* 반응형 */
@media (max-width: 1200px) {
  .results-columns { grid-template-columns: 1fr; }
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 4rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h4 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 0.875rem;
  margin: 0;
}

/* ============= 상태 점 ============= */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 2s infinite;
}

.status-dot.connected {
  background: var(--success);
}

.status-dot.disconnected {
  background: var(--danger);
}

.status-dot.searching {
  background: var(--warning);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============= 푸터 ============= */
.footer {
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  margin-top: 4rem;
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ============= 반응형 디자인 ============= */
@media (max-width: 1200px) {
  .results-section {
    grid-template-columns: 1fr;
  }
  
  .control-panel {
    grid-template-columns: 1fr;
    text-align: center;
  }
}

@media (max-width: 768px) {
  .main-container {
    padding: 1rem;
  }
  
  .nav-content {
    padding: 1rem;
    flex-direction: column;
    gap: 1rem;
  }
  
  .dashboard-header h1 {
    font-size: 2rem;
  }
  
  .control-card {
    flex-direction: column;
    align-items: stretch;
  }
  
  .status-grid {
    grid-template-columns: 1fr;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .results-header-right {
    width: 100%;
    justify-content: space-between;
  }

  .footer-content {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }
  
  .log-content {
    height: 250px;
  }
}

/* ============= 애니메이션 ============= */
.fade-in {
  animation: fadeIn 0.5s ease-in-out;
}

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

/* ============= 로딩 스피너 ============= */
.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============= 실시간 결과 카드 ============= */
.real-time-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
}

.drug-result-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    transition: all 0.3s ease;
    border-left: 4px solid var(--dist-color, var(--text-muted));
}

.drug-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.drug-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.drug-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-exclusion {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.btn-exclusion:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-exclusion:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-exclusion.btn-exclusion-added {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-exclusion.btn-exclusion-added:hover {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.btn-open-site {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.btn-open-site:hover {
    background: var(--bg-tertiary);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-open-site:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-open-site .bi-arrow-repeat.spin {
    animation: btn-open-site-spin 0.9s linear infinite;
}

@keyframes btn-open-site-spin {
    to { transform: rotate(360deg); }
}

.empty-state-small {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.empty-state-small i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}

.empty-state-small p {
    margin: 0;
    font-size: 0.875rem;
}

.drug-header h5 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.drug-stock {
    display: flex;
    gap: 1rem;
}

.stock-item {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}


/* ============= 유틸리티 클래스 ============= */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.d-flex { display: flex; }
.d-grid { display: grid; }
.d-none { display: none; }

.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* ============= 긴급 알림 팝업 ============= */
.urgent-alert-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.urgent-alert-popup.show {
  opacity: 1;
}

.urgent-alert-content {
  background: var(--bg-primary);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 500px;
  overflow: hidden;
  transform: scale(0.9);
  transition: transform 0.3s ease;
  border: 3px solid var(--danger);
}

.urgent-alert-popup.show .urgent-alert-content {
  transform: scale(1);
}

.urgent-alert-header {
  background: var(--gradient-danger);
  color: white;
  padding: 1.5rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: relative;
}

.urgent-icon {
  font-size: 1.5rem;
  animation: urgentBell 2s infinite;
}

.urgent-alert-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  flex: 1;
}

.urgent-close-btn {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.urgent-close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.urgent-alert-body {
  padding: 2rem;
}

.urgent-drug-info h4 {
  margin: 0 0 1rem 0;
  color: var(--text-primary);
  font-size: 1.125rem;
  font-weight: 600;
}

.urgent-stock-info {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.urgent-stock-info .stock-item {
  background: var(--bg-secondary);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.urgent-distributor {
  margin-bottom: 1rem;
}

.urgent-alert-footer {
  padding: 1rem 2rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auto-close-countdown {
  display: flex;
  justify-content: center;
  align-items: center;
}

.countdown-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.urgent-question {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-primary);
  font-weight: 500;
  padding: 0.5rem 0;
  line-height: 1.5;
}

.urgent-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.urgent-buttons button {
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 80px;
}

.urgent-buttons .btn-cancel {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.urgent-buttons .btn-cancel:hover {
  background: var(--bg-secondary);
  border-color: var(--text-secondary);
}

.urgent-buttons .btn-confirm {
  background: var(--gradient-danger);
  color: white;
}

.urgent-buttons .btn-confirm:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.urgent-buttons .btn-confirm:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
}

@keyframes urgentBell {
  0%, 50%, 100% { transform: rotate(0deg); }
  10%, 30% { transform: rotate(-10deg); }
  20%, 40% { transform: rotate(10deg); }
}

/* ============= 긴급 로그 스타일 ============= */
.log-urgent {
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.1) 0%, rgba(244, 63, 94, 0.05) 100%);
  border-left: 4px solid var(--danger);
  color: var(--danger);
  font-weight: 600;
  animation: urgentLogPulse 2s infinite;
}

@keyframes urgentLogPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}