/* 기본 리셋 및 변수 */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.15);
  --success: #3fb950;
  --warning: #d29922;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* 헤더 */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.02em;
}

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

.intro {
  max-width: 720px;
  margin: 1.5rem auto 0;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-muted);
}

.intro strong {
  color: var(--accent);
}

/* 탭 */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition: color 0.2s, background 0.2s;
}

.tab:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* 주별 업로드 4칸 */
.upload-row-weekly {
  grid-template-columns: repeat(4, 1fr);
}

.upload-zone-weekly {
  padding: 1.25rem 1rem;
}

/* 모달 */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

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

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.modal-body {
  padding: 1.25rem;
}

.modal-chart-wrap {
  margin-bottom: 1.25rem;
  min-height: 200px;
}

.modal-order-formula {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.modal-order-formula strong {
  color: var(--accent);
}

/* 주별 테이블 행 클릭 */
.data-table-weekly tbody tr {
  cursor: pointer;
}

.data-table-weekly tbody tr.order-needed td:nth-child(n+10) {
  font-weight: 600;
  color: var(--warning);
}

/* 업로드 영역 */
.upload-section {
  margin-bottom: 2rem;
}

.upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
}

.upload-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.upload-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.upload-zone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 1rem;
  color: var(--accent);
}

.upload-text {
  margin: 0 0 0.25rem 0;
  font-size: 0.95rem;
}

.upload-text strong {
  color: var(--accent);
}

.upload-filename {
  margin: 0;
  font-size: 0.8rem;
  color: var(--accent);
  word-break: break-all;
}

.upload-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* 컨트롤(검색, 통계) */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-wrap label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

#searchInput {
  width: 280px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
}

#searchInput::placeholder {
  color: var(--text-muted);
}

#searchInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.filter-wrap {
  display: flex;
  align-items: center;
}

.filter-wrap label {
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-wrap input[type="checkbox"] {
  margin-right: 0.35rem;
}

.stats {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.stats strong {
  color: var(--text);
}

.stats .order-count {
  color: var(--warning);
}

/* 테이블 섹션 */
.table-section {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-hover);
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:hover {
  background: var(--surface-hover);
}

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

.data-table tbody tr.order-needed {
  background: rgba(210, 153, 34, 0.12);
}

.data-table tbody tr.order-needed:hover {
  background: rgba(210, 153, 34, 0.18);
}

.data-table td:nth-child(8) {
  font-weight: 600;
}

.data-table tr.order-needed td:nth-child(8) {
  color: var(--warning);
}

/* 첫 열(보통 이름/코드) 강조 */
.data-table td:first-child {
  font-weight: 500;
}

/* 빈 상태 */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.empty-state.hidden {
  display: none;
}

.empty-state p {
  margin: 0.25rem 0;
}

/* 약국인을 위한 콘텐츠 섹션 (에드센스·SEO용) */
.content-section {
  margin-top: 3rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

.content-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: var(--text);
}

.content-lead {
  margin: 0 0 2rem 0;
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color 0.2s;
}

.content-card:hover {
  border-color: var(--accent);
}

.content-card h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  color: var(--text);
  line-height: 1.4;
}

.content-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.65;
}

/* 푸터 */
.site-footer {
  margin-top: 3rem;
  padding: 2rem 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}

.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
}

.footer-block {
  margin-bottom: 1.5rem;
}

.footer-block h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  color: var(--text);
}

.footer-block p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-link {
  color: var(--accent);
  text-decoration: none;
}

.footer-link:hover {
  text-decoration: underline;
}

.footer-copy {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* 대시보드 요약 (탭 하단) */
.dashboard-summary {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.summary-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
  color: var(--text);
}

.summary-charts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.summary-chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 280px;
}

.summary-chart-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.75rem 0;
  color: var(--text-muted);
}

.summary-chart-wrap {
  height: 220px;
  position: relative;
}

.summary-overstock .summary-list-wrap {
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.85rem;
}

.summary-overstock .summary-list-wrap table {
  width: 100%;
  border-collapse: collapse;
}

.summary-overstock .summary-list-wrap th,
.summary-overstock .summary-list-wrap td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.summary-overstock .summary-list-wrap th {
  font-weight: 600;
  color: var(--text-muted);
}

/* 반응형 */
@media (max-width: 600px) {
  .app {
    padding: 1rem;
  }

  .intro {
    margin: 1rem auto 0;
    font-size: 0.9rem;
  }

  .upload-zone {
    padding: 2rem 1rem;
  }

  .upload-row {
    grid-template-columns: 1fr;
  }

  .upload-row-weekly {
    grid-template-columns: 1fr 1fr;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  #searchInput {
    width: 100%;
  }

  .data-table {
    font-size: 0.8rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.5rem 0.6rem;
  }

  .content-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
  }

  .article-grid {
    grid-template-columns: 1fr;
  }

  .summary-charts {
    grid-template-columns: 1fr;
  }

  .footer-inner {
    padding: 0 1rem;
  }
}
