:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --brand: #1d4ed8;
  --up: #c2410c;
  --down: #1d4ed8;
  --warn: #b45309;
  --alert: #b91c1c;
  --ok: #15803d;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 20px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  line-height: 1.5;
}

.topbar {
  background: var(--brand);
  color: #fff;
  padding: 20px 16px;
  text-align: center;
}
.topbar h1 {
  margin: 0;
  font-size: 1.7rem;
}
.subtitle {
  margin: 6px 0 0;
  font-size: 1rem;
  opacity: 0.9;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.field {
  display: block;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.field input {
  width: 100%;
  font-size: 1.25rem;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
}

.input-with-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.list-btn {
  min-width: 78px;
  padding: 0 14px;
  border: 2px solid var(--brand);
  border-radius: 12px;
  background: #ffffff;
  color: var(--brand);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}

.suggestions {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.suggestion,
.list-item {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f9fafb;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.suggestion strong,
.list-item strong {
  font-size: 1.05rem;
}

.suggestion small,
.list-item small {
  color: var(--muted);
  font-size: 0.88rem;
}

.suggestion:hover,
.list-item:hover {
  border-color: var(--brand);
  background: #eef2ff;
}

.list-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.45);
}

.list-dialog {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: min(640px, 100%);
  max-height: min(760px, 92vh);
  padding: 18px;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 20px 70px rgba(17, 24, 39, 0.28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-close {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.modal-search {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 1.05rem;
}

.modal-body {
  display: grid;
  gap: 8px;
  overflow-y: auto;
  margin-top: 12px;
  padding-right: 4px;
}

.big-btn {
  width: 100%;
  font-size: 1.4rem;
  font-weight: 800;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  min-height: 64px;
}
.big-btn:active {
  transform: translateY(1px);
}
.big-btn.reload {
  background: #047857;
  margin-top: 8px;
}
.ghost-btn {
  width: 100%;
  margin-top: 10px;
  font-size: 1.05rem;
  padding: 14px;
  border: 2px solid var(--brand);
  border-radius: 12px;
  background: #fff;
  color: var(--brand);
  cursor: pointer;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: 1rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
}
.chip .x {
  color: var(--muted);
  font-weight: 700;
}
.chip-empty {
  color: var(--muted);
  font-size: 0.95rem;
}

.status {
  padding: 16px;
  text-align: center;
  font-size: 1.1rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 12px;
  margin-bottom: 16px;
}
.status.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--alert);
}

.price-card {
  text-align: center;
}
.price-head {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.price-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}
.price-value {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -1px;
}
.price-unit {
  font-size: 1.4rem;
  color: var(--muted);
}
.price-change {
  margin-top: 8px;
  font-size: 1.25rem;
  font-weight: 800;
}
.price-change.up {
  color: var(--up);
}
.price-change.down {
  color: var(--down);
}
.price-change.flat {
  color: var(--muted);
}
.muted {
  color: var(--muted);
  font-size: 1rem;
}

.signal-badge {
  display: inline-block;
  font-size: 1.3rem;
  font-weight: 900;
  padding: 10px 18px;
  border-radius: 12px;
  background: #f3f4f6;
}
.signal-badge.level-ok {
  background: #dcfce7;
  color: var(--ok);
}
.signal-badge.level-warn {
  background: #fef3c7;
  color: var(--warn);
}
.signal-badge.level-alert {
  background: #fee2e2;
  color: var(--alert);
}

.reason-list {
  margin: 12px 0 0;
  padding-left: 20px;
  font-size: 1.02rem;
}
.reason-list li {
  margin-bottom: 6px;
}

.disclaimer {
  font-size: 0.92rem;
  color: var(--muted);
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  padding: 12px 14px;
}

.footer {
  text-align: center;
  padding: 24px 16px 40px;
}
.footer a {
  color: var(--brand);
  font-size: 1rem;
  display: block;
  margin-top: 10px;
}

.history-page {
  padding-top: 16px;
}
.history-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.history-hero h2 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
}
.ghost-link {
  flex: 0 0 auto;
  color: var(--brand);
  border: 2px solid var(--brand);
  border-radius: 12px;
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 800;
}
.history-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.metric-card {
  margin-bottom: 0;
}
.metric-label {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}
.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 2rem;
  line-height: 1.1;
}
.bar-list {
  display: grid;
  gap: 14px;
}
.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
  font-size: 1rem;
}
.bar-track {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}
.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}
.history-list {
  display: grid;
  gap: 10px;
}
.history-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.history-item:last-child {
  border-bottom: 0;
}
.history-item span {
  color: var(--muted);
  white-space: nowrap;
}

/* ── API call stats ── */
.api-stat-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.api-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  text-align: center;
}
.api-stat-label { font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.api-stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.api-stat-value.good { color: #16a34a; }
.api-stat-value.mid  { color: #d97706; }
.api-stat-value.low  { color: #dc2626; }
.api-stat-sub { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.api-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100px;
  margin-bottom: 8px;
  padding-bottom: 20px;
  position: relative;
}
.api-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.api-bar-stack {
  width: 100%;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 3px 3px 0 0;
  overflow: hidden;
  min-height: 4px;
}
.seg { display: block; min-height: 1px; }
.seg-ae { background: #3b82f6; }
.seg-ac { background: #93c5fd; }
.seg-we { background: #f97316; }
.seg-wc { background: #fcd34d; }
.api-bar-date { font-size: 0.6rem; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.api-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
  align-items: center;
}
.leg {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  vertical-align: middle;
}
.leg-ae { background: #3b82f6; }
.leg-ac { background: #93c5fd; }
.leg-we { background: #f97316; }
.leg-wc { background: #fcd34d; }
@media (max-width: 480px) {
  .api-stat-summary { grid-template-columns: 1fr 1fr; }
  .api-stat-summary .api-stat-card:last-child { grid-column: 1 / -1; }
}

.daily-list {
  display: grid;
  gap: 0;
}
.daily-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.daily-row:last-child {
  border-bottom: 0;
}
.daily-date {
  flex: 0 0 auto;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  min-width: 7em;
}
.daily-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.daily-badge {
  display: inline-block;
  font-size: 0.88rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
}
.daily-badge.auction {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}
.daily-badge.weather {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

/* ── 결과 필터 바 ── */
.result-filter-bar {
  padding: 14px 16px;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 130px;
}
.filter-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}
.filter-select {
  font-size: 1rem;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.filter-select:focus {
  outline: none;
  border-color: var(--brand);
}
.filter-reset-btn {
  font-size: 0.95rem;
  padding: 10px 16px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.filter-reset-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

@media (max-width: 400px) {
  html {
    font-size: 18px;
  }
  .price-value {
    font-size: 2.5rem;
  }
  .history-hero,
  .history-item {
    display: block;
  }
  .ghost-link {
    display: inline-block;
    margin-top: 12px;
  }
  .history-grid {
    grid-template-columns: 1fr;
  }
  .history-item span {
    display: block;
    margin-top: 4px;
    white-space: normal;
  }
}
