/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fff;
  --fg: #222;
  --bg2: #f5f5f5;
  --border: #ccc;
  --accent: #0969da;
  --accent-dim: #0550ae;
  --row-hover: #f0f4ff;
  --box-fill: #d0e4ff;
  --whisker: #333;
  --median-line: #c00;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1b;
    --fg: #eee;
    --bg2: #252525;
    --border: #444;
    --accent: #58a6ff;
    --accent-dim: #79c0ff;
    --row-hover: #2a2d35;
    --box-fill: #1f3a5f;
    --whisker: #aaa;
    --median-line: #f44;
  }
}

body {
  font-family: "SF Mono", "Menlo", "Monaco", "Consolas", "Liberation Mono", monospace;
  font-size: 10pt;
  line-height: 1.4;
  color: var(--fg);
  background: var(--bg);
  padding: 12px 20px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Header === */
header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
header h1 {
  font-size: 14pt;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.subtitle {
  font-size: 9pt;
  color: #888;
  margin-top: 2px;
}

/* === Layout === */
main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#filters {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 4px;
}
.filter-item {
  display: flex;
  flex-direction: column;
}
#filters label {
  font-size: 9pt;
  font-weight: 600;
  margin-bottom: 3px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#filters select {
  font-family: inherit;
  font-size: 10pt;
  padding: 4px 6px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 3px;
  min-width: 200px;
}
#filters select:disabled {
  opacity: 0.5;
}

/* === Content === */
#content {
  min-width: 0;
}

.hidden { display: none !important; }

/* === Result Section === */
#result {
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px;
  background: var(--bg2);
}

#result h2 {
  font-size: 11pt;
  margin-bottom: 10px;
}
#box-plot-container {
  margin-bottom: 12px;
  overflow-x: auto;
}
#box-plot {
  display: block;
  max-width: 100%;
}
#coupang-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 10px 20px;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 10pt;
  font-weight: 700;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
}
#coupang-btn:hover {
  background: var(--bg2);
  text-decoration: none;
}
#coupang-notice {
  margin-top: 6px;
  font-size: 8pt;
  color: #888;
}

/* === Tables === */
table {
  border-collapse: collapse;
  font-size: 10pt;
}
th, td {
  text-align: left;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
}
th, td.num, td.date { white-space: nowrap; }
th {
  font-size: 9pt;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  position: sticky;
  top: 0;
  background: var(--bg2);
  user-select: none;
}
td { vertical-align: top; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

tbody tr:hover { background: var(--row-hover); }

/* === Products === */
#products-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  margin-bottom: 6px;
}
#products-title {
  font-size: 10pt;
}
th.sortable {
  cursor: pointer;
}
th.sortable:hover {
  color: var(--accent);
}
.sort-arrow {
  font-size: 8pt;
}
#products-table td a {
  color: var(--accent);
}
#products-table td a:hover {
  text-decoration: underline;
}

/* === Footer === */
footer {
  margin-top: 30px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 8pt;
  color: #888;
}

/* === Loading progress === */
#loading {
  padding: 20px 0;
}
#progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
#progress-bar-inner {
  width: 30%;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: progress-slide 1s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* === Responsive === */
@media (max-width: 500px) {
  body { padding: 12px 10px; }
  #filters { flex-direction: column; align-items: stretch; }
  #filters select { min-width: 0; width: 100%; }

  /* Card layout for product table */
  #products-table { width: 100%; border: none; }
  #products-table thead { display: none; }
  #products-table tbody tr {
    display: block;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  #products-table tbody tr:hover { background: var(--row-hover); }
  #products-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 3px 0;
    border-bottom: none;
    white-space: normal;
  }
  #products-table td::before { display: none; }
  #products-table td:first-child {
    flex-direction: column;
    gap: 2px;
  }
  #products-table td:first-child a {
    word-break: break-word;
  }
  #products-table td.num { text-align: right; }
}
