:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-soft: #f8faf9;
  --ink: #1f2933;
  --muted: #667085;
  --line: #e4e7ec;
  --green: #18794e;
  --green-dark: #0f5132;
  --blue: #2563eb;
  --amber: #946200;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
  font-family:
    "Segoe UI",
    "Noto Sans KR",
    system-ui,
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.refresh-btn {
  background-color: #f8fafc;
  border: 1.5px solid var(--line);
  color: var(--ink);
  font-weight: 850;
  font-size: 0.95rem;
  padding: 6px 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.refresh-btn:active {
  background-color: #edf2f7;
  transform: translateY(1px);
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.5rem, 2vw, 2.1rem);
  line-height: 1.2;
}

h2 {
  font-size: 1.25rem;
}

.status-pill,
.selection-chip {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--muted);
  background: #ffffff;
  white-space: nowrap;
}

.status-pill.ok {
  border-color: #b9dec9;
  color: var(--green-dark);
  background: #f0faf4;
}

.status-pill.error {
  border-color: #f4c7c3;
  color: var(--danger);
  background: #fff5f3;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.query-panel {
  padding: 18px;
  position: sticky;
  top: 18px;
  background-color: #f0f7ff; /* 연한 파랑: 입력 영역 */
  border: 1px solid var(--line);
  border-left: 6px solid var(--blue);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.result-panel {
  min-width: 0;
  padding: 20px;
  background-color: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 1.25rem;
  font-weight: 850;
  color: var(--blue);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: "🔍";
}

.field-grid.compact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 4px;
  position: relative;
  min-width: 0;
}

.field span {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  font-size: 1.1rem;
}

/* 날짜 입력칸 모바일 깨짐 방지 */
input[type="date"] {
  padding: 8px 10px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%232563eb' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}

input:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(24, 121, 78, 0.14);
}

.selection-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.selection-chip {
  border-radius: 7px;
  max-width: 100%;
  white-space: normal;
  font-size: 0.9rem;
  padding: 4px 10px;
}

.advanced {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 4px 0 12px;
  padding: 8px 0;
}

.advanced summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 800;
  font-size: 1rem;
}

.code-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.code-inputs {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.code-inputs input {
  min-height: 44px;
  padding: 8px;
  font-size: 0.95rem;
  text-align: center;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.main-action {
  font-size: 1.3rem;
  height: 64px;
  width: 100% !important;
}

.button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 20px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  font-weight: 800;
  font-size: 1.1rem;
}

.button:hover:not(:disabled) {
  border-color: var(--green);
  color: var(--green-dark);
}

.button.primary {
  border-color: var(--green);
  color: #fff;
  background: var(--green);
}

.button.primary:hover:not(:disabled) {
  border-color: var(--green-dark);
  color: #fff;
  background: var(--green-dark);
}

.button.compact {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 290px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.12);
}

.suggestion {
  display: grid;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid #eef2f6;
  border-radius: 0;
  padding: 9px 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  cursor: pointer;
}

.suggestion:hover,
.suggestion:focus {
  background: var(--panel-soft);
}

.suggestion strong {
  font-size: 0.95rem;
}

.suggestion small {
  color: var(--muted);
}

.recent-block {
  margin-top: 18px;
}

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

.text-button {
  min-height: 28px;
  border: 0;
  padding: 2px 0;
  color: var(--blue);
  background: transparent;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 800;
}

.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.recent-list {
  display: grid;
  gap: 10px;
  max-height: 320px;
  overflow: auto;
}

.recent-group {
  display: grid;
  gap: 8px;
}

.recent-group-title {
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

.recent-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  cursor: pointer;
  max-width: 100%;
  text-align: left;
}

.recent-card:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.recent-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.recent-info-wrapper {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.recent-main-large {
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--ink);
  word-break: keep-all;
}

.recent-sub-meta {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.recent-btn-wrapper-new {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.quick-search-button-large {
  background-color: var(--green);
  color: white;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1.15rem;
  font-weight: 900;
  white-space: nowrap;
  min-height: 48px;
  box-shadow: 0 4px 6px rgba(24, 121, 78, 0.2);
}

.quick-search-button-large:active {
  background-color: var(--green-dark);
  transform: translateY(2px);
  box-shadow: none;
}

.quick-search-badge-small {
  background-color: var(--green);
  color: white;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 1.05rem;
  font-weight: 850;
  min-height: 44px;
  box-shadow: 0 2px 4px rgba(24, 121, 78, 0.15);
}

.history-group-container {
  display: grid;
  gap: 2px;
  background: #eee;
  border-radius: 12px;
  overflow: hidden;
}

.grouped-main {
  border-radius: 0 !important;
  border: 0 !important;
}

.history-text-toggle {
  background: transparent;
  color: var(--blue);
  border: 0;
  padding: 2px 4px;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}

.history-children {
  background: #f8f9fa;
  border-top: 1px solid #ddd;
  display: grid;
}

.history-child-item {
  padding: 6px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.history-child-item:last-child {
  border-bottom: 0;
}

.history-child-item:hover {
  background: #edf2f7;
}

.child-date {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
}

.child-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.recent-right-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.favorite-toggle-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.favorite-toggle-new img {
  width: 24px;
  height: 24px;
}

.favorite-toggle-new.active {
  border-color: #d95f00;
  background: #fff9f5;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.summary-container {
  background-color: #fff9e6; /* 연한 노랑 */
  border-radius: 12px;
  border: 1px solid #ffeeba;
  margin-bottom: 16px;
  padding: 12px;
}

.summary-grid {
  display: grid;
  gap: 10px;
}

.main-summary {
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px dashed #ffeeba;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

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

.metric {
  min-height: 54px;
  padding: 4px;
  text-align: center;
}

.metric span {
  display: block;
  color: #856404;
  font-size: 0.85rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 2px;
  font-size: 1.3rem;
  line-height: 1.15;
  color: #856404;
}

.filter-status-alert {
  margin-top: 8px;
  padding: 10px;
  background-color: #d1ecf1;
  border: 1px solid #bee5eb;
  border-radius: 8px;
  color: #0c5460;
  font-size: 1.1rem;
  font-weight: 900;
  text-align: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.senior-accordion {
  margin-bottom: 20px;
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.accordion-summary {
  display: block;
  padding: 16px;
  cursor: pointer;
  background: #e2e8f0;
  border-bottom: 1px solid var(--line);
  list-style: none; /* Hide default arrow */
}

.accordion-summary::-webkit-details-marker {
  display: none;
}

.accordion-summary:active {
  background: #cbd5e1;
}

.trend-panel {
  padding: 16px;
}

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

.trend-title {
  margin-bottom: 0 !important;
}

.trend-title::before {
  content: "📈";
}

.trend-controls-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  width: 100%;
}

.senior-select-group {
  display: flex;
  align-items: center;
  flex: 1;
  background: #ffffff;
  border: 2px solid var(--blue);
  border-radius: 12px;
  padding: 0 12px;
  min-height: 48px;
}

.trend-select-large {
  border: 0;
  background: transparent;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--blue);
  height: 44px;
  cursor: pointer;
  outline: none;
  min-width: 100px;
}

.primary-action-btn {
  min-width: 80px;
  height: 48px;
  background: var(--blue);
  color: #fff;
  border: 0;
  font-size: 1.1rem;
}

.primary-action-btn:hover {
  background: #1e40af;
  color: #fff;
}

.unit-text {
  font-size: 0.95rem;
  color: var(--ink);
  white-space: nowrap;
}

.trend-detail-box {
  margin-top: 16px;
  padding: 14px;
  background-color: #ffffff;
  border: 2px solid var(--blue);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  animation: slideUp 0.3s ease-out;
}

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

.detail-date {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--blue);
  margin-bottom: 8px;
  text-align: center;
  border-bottom: 1px solid #eee;
  padding-bottom: 6px;
}

.detail-values {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.val-item {
  display: grid;
  text-align: center;
  gap: 4px;
}

.val-item span {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--muted);
}

.val-item strong {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--ink);
}

.chart-container {
  position: relative;
  height: 240px;
  width: 100%;
}

.chart-label {
  font-size: 0.95rem;
  font-weight: 850;
  color: var(--muted);
  margin-top: 16px;
  margin-bottom: 8px;
  text-align: center;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}

.compact-chart {
  height: 160px; /* 건수 차트는 조금 더 낮게 배치 */
}

.result-meta {
  min-height: 24px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background-color: #f0fdf4; /* 연한 초록: 필터 */
  border-radius: 12px;
  border: 1px solid #bdf3d4;
}

.filter-bar .field span {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--green-dark);
  margin-bottom: 6px;
}

.filter-bar select {
  font-size: 1.1rem;
  font-weight: 700;
  min-height: 48px;
}

.input-with-button {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.list-btn {
  flex-shrink: 0;
  width: fit-content;
  min-width: unset;
  min-height: 38px;
  padding: 0 8px;
  font-size: 0.85rem;
  background-color: #f0f7ff;
  border-color: var(--blue);
  color: var(--blue);
  border-radius: 8px;
  align-self: center;
  white-space: nowrap;
}

.list-btn:hover {
  background-color: var(--blue);
  color: #fff;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 20px;
}

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

.modal-content {
  background: #fff;
  width: min(600px, 100%);
  max-height: 80vh;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.modal-header h2 {
  font-size: 1.2rem;
  color: var(--blue);
}

.close-modal {
  background: transparent;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
}

.modal-search {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-search input {
  min-height: 44px;
  font-size: 1rem;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.list-item {
  width: 100%;
  text-align: left;
  padding: 12px 20px;
  border: 0;
  background: transparent;
  border-bottom: 1px solid #f0f4f8;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-item:hover {
  background-color: #f0f7ff;
}

.list-item strong {
  font-size: 1.1rem;
  color: var(--ink);
}

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

@media (max-width: 640px) {
  .modal-content {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }
}

.mobile-sort {
  display: none;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #eef2f6;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #475467;
  background: #f8fafc;
  font-size: 0.84rem;
}

.sort-button {
  display: inline-flex;
  width: 100%;
  min-height: 28px;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 6px;
  padding: 3px 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  text-align: left;
}

.sort-button:hover,
.sort-button.active {
  color: var(--green-dark);
}

.sort-button.number {
  justify-content: flex-end;
  text-align: right;
}

.sort-indicator {
  display: inline-block;
  min-width: 12px;
  color: var(--green);
  font-size: 0.72rem;
}

td {
  font-size: 0.92rem;
}

tbody tr:hover {
  background: #f8faf9;
}

.number {
  text-align: right;
}

.mobile-results {
  display: none;
}

.result-row {
  border-bottom: 1px solid var(--line);
  padding: 16px 8px;
  display: grid;
  gap: 8px;
  background: #fff;
}

.result-row:last-child {
  border-bottom: 0;
}

.result-row-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.result-row-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.2;
}

.result-row-price {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--green-dark);
  white-space: nowrap;
}

.result-row-sub {
  font-size: 1.05rem;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.result-row:hover {
  background: var(--panel-soft);
}

.muted {
  color: var(--muted);
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
}

.empty-state[hidden],
.table-wrap[hidden],
.mobile-sort[hidden],
.mobile-results[hidden],
.suggestions[hidden] {
  display: none;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 14px;
}

#pageLabel {
  min-width: 88px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 16px;
  }

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

  .query-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .topbar,
  .result-header,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid.compact-grid,
  .summary-grid,
  .filter-bar,
  .code-grid {
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .list-btn {
    width: auto;
  }

  .status-pill {
    width: fit-content;
  }

  .metric strong {
    font-size: 1.15rem;
  }

  .mobile-sort {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 12px;
  }

  .mobile-sort .button {
    width: auto;
    white-space: nowrap;
  }

  .table-wrap {
    display: none;
  }

  .mobile-results {
    display: grid;
    gap: 10px;
  }

  .pager {
    justify-content: stretch;
  }

  #pageLabel {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
  }
}

@media (max-width: 420px) {
  .mobile-sort {
    grid-template-columns: 1fr;
  }
}
