:root {
  color-scheme: light;
  --ink: #17212b;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #d8e0e7;
  --line-strong: #c5d0da;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --canvas: #edf2f4;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e5f5f2;
  --blue: #2457a6;
  --green: #157a55;
  --amber: #a15c07;
  --rose: #b4233a;
  --shadow: 0 18px 45px rgba(23, 33, 43, 0.11);
  --shadow-soft: 0 8px 24px rgba(23, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f7faf9 0%, var(--canvas) 42%, #e8eef1 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

input {
  font-size: 16px;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  gap: 18px;
  width: min(1220px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.workspace,
.results {
  min-width: 0;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(216, 224, 231, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.workspace {
  position: sticky;
  top: 18px;
  align-self: start;
  padding: 20px;
}

.results {
  min-height: calc(100vh - 40px);
  padding: 22px;
  scroll-margin-top: 16px;
}

.topbar,
.summary-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 25px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 23px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.status-pill {
  flex: 0 0 auto;
  max-width: 154px;
  min-height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 11px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill.is-working {
  border-color: rgba(15, 118, 110, 0.32);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.is-error {
  border-color: rgba(180, 35, 58, 0.32);
  background: #fff1f3;
  color: var(--rose);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-top: 20px;
  padding: 4px;
  border: 1px solid #e4ebf0;
  border-radius: 8px;
  background: #edf3f2;
}

.mode-tab {
  min-width: 0;
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  touch-action: manipulation;
}

.mode-tab.is-active {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: var(--shadow-soft);
}

.input-panel {
  margin-top: 16px;
}

.is-hidden {
  display: none !important;
}

.file-target {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  min-height: 104px;
  border: 1px dashed #a9b8c4;
  border-radius: 8px;
  padding: 17px;
  cursor: pointer;
  background: var(--surface-soft);
}

.file-target:hover {
  border-color: var(--accent);
  background: #f3faf8;
}

.file-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.file-target span:last-child {
  min-width: 0;
}

.file-target strong,
.file-target small {
  display: block;
}

.file-target strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-target small {
  margin-top: 5px;
  color: var(--muted);
}

#imageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.image-preview {
  display: none;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.image-preview.has-image {
  display: block;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.field span {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
}

.field input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--surface-soft);
  appearance: none;
}

.field input:focus {
  outline: 3px solid rgba(36, 87, 166, 0.13);
  border-color: var(--blue);
  background: #ffffff;
}

.store-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 18px;
  padding-top: 2px;
}

.store-panel::before {
  content: "검색 업체";
  grid-column: 1 / -1;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 850;
}

.store-chip {
  min-width: 0;
}

.store-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.store-chip span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  background: #ffffff;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
  line-height: 1.2;
  overflow-wrap: anywhere;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.store-chip input:checked + span {
  border-color: rgba(15, 118, 110, 0.36);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.1);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  min-width: 0;
}

.primary-button,
.secondary-button,
.raw-toggle {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 850;
  touch-action: manipulation;
}

.primary-button {
  flex: 1;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.24);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: progress;
  opacity: 0.65;
  transform: none;
}

.secondary-button,
.raw-toggle {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink-soft);
}

.secondary-button {
  flex: 0 0 auto;
}

.secondary-button:hover,
.raw-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: calc(100vh - 92px);
  color: var(--muted);
  text-align: center;
}

.empty-mark {
  width: 42px;
  height: 42px;
  border: 10px solid var(--accent-soft);
  border-top-color: #dbe7ef;
  border-radius: 999px;
}

.empty-state strong {
  display: block;
  color: var(--ink);
  font-size: 24px;
  font-weight: 850;
}

.empty-state span:last-child {
  margin-top: -2px;
}

.result-content {
  display: grid;
  gap: 18px;
}

.summary-row {
  padding-bottom: 17px;
  border-bottom: 1px solid var(--line);
}

.summary-row p:last-child {
  max-width: 760px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.saving-box {
  flex: 0 0 auto;
  min-width: 136px;
  max-width: 220px;
  border: 1px solid rgba(21, 122, 85, 0.16);
  border-radius: 8px;
  padding: 13px 14px;
  background: #eefaf4;
  color: var(--green);
  font-size: 20px;
  font-weight: 900;
  text-align: right;
  overflow-wrap: anywhere;
}

.saving-box.is-empty {
  border-color: rgba(161, 92, 7, 0.18);
  background: #fff7ed;
  color: var(--amber);
}

.candidate-grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(110px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.candidate-grid div {
  min-width: 0;
  padding: 13px;
  background: #ffffff;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-weight: 850;
}

.raw-text-wrap {
  display: grid;
  justify-items: start;
  gap: 10px;
}

.raw-text {
  width: 100%;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 13px;
  border: 1px solid #263241;
  border-radius: 8px;
  background: #101823;
  color: #f8fafc;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.offer-list {
  display: grid;
  gap: 10px;
}

.offer-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 13px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #ffffff;
  color: inherit;
  text-decoration: none;
  min-width: 0;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.offer-row-link:hover {
  border-color: rgba(15, 118, 110, 0.38);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.offer-thumb {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.offer-thumb-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.offer-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  min-width: 0;
}

.offer-store {
  color: var(--accent-strong);
  font-weight: 900;
}

.offer-name {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.offer-price {
  color: var(--ink);
  font-size: 20px;
  font-weight: 950;
  white-space: nowrap;
}

.empty-offers {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
}

@media (max-width: 900px) {
  body {
    background: var(--canvas);
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .workspace {
    position: static;
  }

  .results {
    min-height: 260px;
  }

  .empty-state {
    min-height: 220px;
  }
}

@media (max-width: 560px) {
  body {
    background: var(--surface);
  }

  .app-shell {
    width: 100%;
    min-height: auto;
    padding: env(safe-area-inset-top) 0 0;
  }

  .workspace,
  .results {
    border: 0;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
  }

  .workspace {
    padding: 16px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
  }

  .results {
    padding: 16px max(14px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    border-top: 8px solid var(--canvas);
    scroll-margin-top: 0;
  }

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

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 20px;
  }

  .eyebrow {
    margin-bottom: 4px;
  }

  .status-pill,
  .saving-box {
    justify-self: start;
    text-align: left;
  }

  .status-pill {
    max-width: 100%;
    min-height: 30px;
    white-space: normal;
  }

  .mode-tabs {
    margin-top: 16px;
  }

  .mode-tab,
  .primary-button,
  .secondary-button,
  .raw-toggle {
    min-height: 44px;
  }

  .file-target {
    min-height: 86px;
    padding: 14px;
  }

  .file-target strong {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .file-icon {
    width: 34px;
    height: 34px;
  }

  .image-preview {
    max-height: min(42vh, 260px);
  }

  .store-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 16px;
  }

  .store-panel::before {
    grid-column: 1 / -1;
  }

  .store-chip {
    min-width: 0;
  }

  .store-chip span {
    min-height: 36px;
    padding: 0 10px;
  }

  .actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin: 16px calc(max(14px, env(safe-area-inset-right)) * -1) -14px calc(max(14px, env(safe-area-inset-left)) * -1);
    padding: 10px max(14px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 28px rgba(23, 33, 43, 0.08);
  }

  .primary-button,
  .secondary-button {
    min-width: 0;
  }

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

  .candidate-grid div:first-child {
    grid-column: 1 / -1;
  }

  .candidate-grid div:last-child {
    grid-column: 1 / -1;
  }

  .summary-row {
    padding-bottom: 14px;
  }

  .saving-box {
    width: 100%;
    min-width: 0;
    font-size: 18px;
  }

  .offer-row {
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }

  .offer-main {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .offer-thumb {
    width: 62px;
    height: 62px;
  }

  .offer-price {
    font-size: 18px;
    white-space: normal;
  }
}

@media (max-width: 360px) {
  .workspace {
    padding-top: 14px;
  }

  .topbar {
    gap: 8px;
  }

  .actions {
    gap: 8px;
  }

  .primary-button,
  .secondary-button {
    padding: 0 12px;
  }

  .store-panel {
    gap: 7px;
  }

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

  .offer-row {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .offer-thumb {
    width: 54px;
    height: 54px;
  }
}
