:root {
  --brand-green: #0f8b6f;
  --brand-green-hover: #0c7a61;
  --brand-green-soft: #e6f4ef;
  --bg: #f3f7f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --surface-3: #eef2f0;
  --border: #e2e8e4;
  --border-strong: #c9d3cd;
  --text: #16211d;
  --text-2: #4a554f;
  --text-3: #7a847f;
  --shadow-sm: 0 1px 2px rgba(22, 33, 29, 0.06);
  --shadow-md: 0 2px 8px rgba(22, 33, 29, 0.08), 0 1px 2px rgba(22, 33, 29, 0.06);
  --shadow-lg: 0 8px 24px rgba(22, 33, 29, 0.12), 0 2px 6px rgba(22, 33, 29, 0.06);
  --font-sans: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body.pill-detail-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.pill-app-topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  min-height: 60px;
  padding: max(12px, env(safe-area-inset-top)) 18px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.pill-app-brand,
.pill-app-nav {
  align-items: center;
  display: flex;
  gap: 9px;
}

.pill-app-brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
  text-decoration: none;
}

.pill-app-mark {
  align-items: center;
  background: var(--brand-green);
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 16px;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.pill-app-nav a,
.pill-app-nav button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 800;
  padding: 8px 11px;
  text-decoration: none;
}

.pill-app-nav button {
  color: var(--brand-green);
}

.pill-app-shell {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  margin: 0 auto;
  max-width: 1180px;
  min-height: calc(100vh - 60px);
  padding: 22px 18px 28px;
}

.pill-capture-panel,
.pill-results-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.pill-capture-panel {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  position: sticky;
  top: 82px;
}

.pill-capture-copy p,
.pill-results-heading p {
  color: var(--brand-green);
  font-size: 12px;
  font-weight: 900;
  margin: 0 0 5px;
}

.pill-capture-copy h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 0;
}

.pill-preview {
  align-items: center;
  background: linear-gradient(180deg, #f8fbfa 0%, #eef4f1 100%);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  gap: 9px;
  justify-content: center;
  min-height: 260px;
  overflow: hidden;
  position: relative;
}

.pill-preview img {
  height: 100%;
  object-fit: contain;
  width: 100%;
}

.pill-preview strong {
  color: var(--text-2);
  font-size: 14px;
}

.pill-preview-icon {
  border: 2px solid var(--border-strong);
  border-radius: 999px;
  display: block;
  height: 58px;
  position: relative;
  width: 96px;
}

.pill-preview-icon::before {
  background: var(--border-strong);
  content: "";
  height: 2px;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) rotate(-18deg);
  width: 62px;
}

.pill-capture-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr auto;
}

.pill-upload-button,
.pill-secondary-button,
.pill-identify-button {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  font-size: 14px;
  font-weight: 900;
  justify-content: center;
  min-height: 42px;
  white-space: nowrap;
}

.pill-upload-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 0 12px;
}

.pill-upload-button input {
  display: none;
}

.pill-secondary-button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 0 12px;
}

.pill-fields {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1.5fr) minmax(86px, 0.75fr) minmax(86px, 0.75fr);
}

.pill-fields input,
.pill-fields select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  min-height: 44px;
  min-width: 0;
  outline: 0;
  padding: 0 12px;
}

.pill-fields input:focus,
.pill-fields select:focus,
.pill-upload-button:focus-within,
.pill-secondary-button:focus-visible,
.pill-identify-button:focus-visible {
  border-color: var(--brand-green);
  box-shadow: 0 0 0 3px rgba(15, 139, 111, 0.14);
  outline: 0;
}

.pill-identify-button {
  background: #16211d;
  border: 0;
  color: #fff;
  min-height: 48px;
  padding: 0 14px;
}

.pill-identify-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.pill-app-disclaimer {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.45;
  margin: -4px 0 0;
}

.pill-results-panel {
  min-height: 560px;
  padding: 18px;
}

.pill-results-heading {
  align-items: flex-start;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.pill-results-heading strong {
  color: var(--text-2);
  font-size: 13px;
  font-weight: 900;
}

.pill-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pill-results:empty::before {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-3);
  content: "사진이나 식별정보를 넣고 알약 찾기를 눌러주세요.";
  display: block;
  font-size: 14px;
  line-height: 1.55;
  padding: 18px;
}

.pill-status,
.pill-answer {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 13px;
  white-space: pre-wrap;
}

.pill-status {
  color: var(--text-2);
}

.pill-progress-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
}

.pill-progress-head {
  align-items: center;
  color: var(--text);
  display: flex;
  font-size: 14px;
  font-weight: 900;
  justify-content: space-between;
  line-height: 1.2;
}

.pill-progress-head span {
  color: #0f8b6f;
  font-size: 13px;
  font-weight: 900;
}

.pill-progress-track {
  background: rgba(15, 139, 111, 0.12);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.pill-progress-fill {
  background: linear-gradient(90deg, #0f8b6f 0%, #3eb489 100%);
  border-radius: inherit;
  height: 100%;
  transition: width 0.22s ease;
}

.pill-progress-copy,
.pill-progress-meta {
  margin: 0;
}

.pill-progress-copy {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.6;
}

.pill-progress-meta {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.5;
}

.pill-vision-chips,
.pill-match-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill-vision-chips {
  margin-bottom: 2px;
}

.pill-vision-chips span,
.pill-match-reasons span {
  background: rgba(39, 174, 96, 0.12);
  border: 1px solid rgba(39, 174, 96, 0.22);
  border-radius: 999px;
  color: #1e7d48;
  display: inline-flex;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.2;
  padding: 4px 7px;
}

.pill-candidates {
  display: grid;
  gap: 10px;
}

.pill-candidate {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 12px;
  grid-template-columns: 118px minmax(0, 1fr);
  padding: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.pill-candidate.top-candidate {
  border-color: rgba(15, 139, 111, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 139, 111, 0.08);
}

.pill-candidate:hover,
.pill-candidate:focus-visible {
  border-color: var(--brand-green);
  box-shadow: var(--shadow-md);
  outline: none;
  transform: translateY(-1px);
}

.pill-candidate img {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
  height: 86px;
  object-fit: contain;
  width: 118px;
}

.pill-candidate-placeholder {
  align-items: center;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--text-3);
  display: flex;
  font-size: 12px;
  height: 86px;
  justify-content: center;
  width: 118px;
}

.pill-candidate strong {
  display: block;
  font-size: 16px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pill-candidate span {
  color: var(--text-2);
  display: block;
  font-size: 13px;
  line-height: 1.45;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.pill-candidate span b {
  color: var(--text);
  font-weight: 900;
}

.pill-rank {
  color: var(--brand-green);
  display: block;
  font-size: 11px;
  font-weight: 900;
  margin-bottom: 5px;
}

.pill-detail-backdrop {
  align-items: center;
  background: rgba(10, 18, 15, 0.48);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 1000;
}

.pill-detail-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  display: block;
  height: min(760px, calc(100vh - 36px));
  height: min(760px, calc(100dvh - 36px));
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px);
  max-width: 760px;
  min-height: 0;
  overflow: hidden;
  position: relative;
  width: min(760px, calc(100vw - 36px));
}

.pill-detail-close {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 22px;
  height: 34px;
  justify-content: center;
  line-height: 1;
  position: absolute;
  right: 12px;
  top: 12px;
  width: 34px;
  z-index: 1;
}

.pill-detail-close:hover,
.pill-detail-close:focus-visible {
  border-color: var(--brand-green);
  outline: none;
}

.pill-detail-body {
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 24px 24px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.pill-detail-kicker {
  color: var(--brand-green);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 6px;
}

.pill-detail-body h2 {
  font-size: 22px;
  line-height: 1.28;
  margin: 0;
  padding-right: 36px;
}

.pill-detail-summary {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
  margin: 8px 0 0;
}

.pill-detail-reasons {
  margin: 12px 0 0;
}

.pill-detail-image {
  align-items: center;
  background: linear-gradient(180deg, #f7faf8 0%, #edf3ef 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  justify-content: center;
  margin: 16px 0 0;
  min-height: 180px;
  overflow: hidden;
  padding: 12px;
}

.pill-detail-image img {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
  height: auto;
  max-height: 300px;
  max-width: 100%;
  object-fit: contain;
  width: auto;
}

.pill-detail-image-empty {
  align-items: center;
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  color: var(--text-3);
  display: flex;
  font-size: 13px;
  height: 220px;
  justify-content: center;
  width: 100%;
}

.pill-detail-grid {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0;
  margin: 16px 0 0;
}

.pill-detail-row {
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 12px;
  grid-template-columns: 96px 1fr;
  padding: 9px 0;
}

.pill-detail-row dt {
  color: var(--text-3);
  font-size: 12px;
  font-weight: 800;
}

.pill-detail-row dd {
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  margin: 0;
  overflow-wrap: anywhere;
}

.pill-detail-sections {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.pill-detail-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 11px;
}

.pill-detail-section h3 {
  font-size: 12px;
  margin: 0 0 5px;
}

.pill-detail-section p {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.55;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  .pill-app-topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .pill-app-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: auto;
    padding: 12px 10px 22px;
  }

  .pill-capture-panel {
    padding: 14px;
    position: static;
  }

  .pill-capture-copy h1 {
    font-size: 24px;
  }

  .pill-preview {
    min-height: 220px;
  }

  .pill-capture-actions {
    grid-template-columns: 1fr 1fr;
  }

  .pill-secondary-button {
    grid-column: 1 / -1;
  }

  .pill-fields {
    grid-template-columns: 1fr 1fr;
  }

  .pill-fields input {
    grid-column: 1 / -1;
  }

  .pill-results-panel {
    min-height: 360px;
    padding: 14px;
  }

  .pill-candidate {
    grid-template-columns: 96px minmax(0, 1fr);
    padding: 9px;
  }

  .pill-candidate img,
  .pill-candidate-placeholder {
    height: 76px;
    width: 96px;
  }

  .pill-candidate strong {
    font-size: 14px;
  }

  .pill-candidate span {
    font-size: 12px;
  }

  .pill-detail-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .pill-detail-modal {
    height: calc(100vh - 20px);
    height: calc(100dvh - 20px);
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    width: calc(100vw - 20px);
  }

  .pill-detail-body {
    padding: 20px 16px 18px;
  }

  .pill-detail-body h2 {
    font-size: 18px;
  }

  .pill-detail-image {
    min-height: 150px;
    padding: 10px;
  }

  .pill-detail-image img {
    max-height: 210px;
  }

  .pill-detail-row {
    grid-template-columns: 84px 1fr;
  }
}

@media (max-width: 420px) {
  .pill-app-nav a,
  .pill-app-nav button {
    font-size: 12px;
    padding: 7px 9px;
  }

  .pill-app-brand {
    font-size: 16px;
  }

  .pill-candidate {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .pill-candidate img,
  .pill-candidate-placeholder {
    height: 68px;
    width: 84px;
  }
}
