:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2024;
  --muted: #6b7280;
  --accent: #1f5eff;
  --warn-bg: #fff8e6;
  --warn-border: #f0d089;
  --warn-text: #7a5b12;
  --error-bg: #fdecec;
  --error-border: #f0b3b3;
  --error-text: #98221f;
  --ok-bg: #e8f2ea;
  --ok-text: #2c6b3f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  line-height: 1.6;
}

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.header h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0 0 24px;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.card h3 {
  margin: 18px 0 6px;
  font-size: 0.95rem;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 16px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone.is-active {
  border-color: var(--accent);
  background: #f2f6ff;
}

.dropzone input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone-title {
  font-weight: 600;
}

.dropzone-hint,
.muted {
  color: var(--muted);
  font-size: 0.86rem;
}

.file-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.file-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.file-size {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.link {
  border: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 0.86rem;
}

.notice,
.privacy {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 14px 0 0;
}

.privacy {
  background: #f2f4f7;
  border-radius: 8px;
  padding: 10px 12px;
}

.primary {
  margin-top: 16px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.55;
  cursor: progress;
}

.status,
.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.status {
  background: #eef2ff;
  color: #33418c;
}

.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 8px 0 0;
  font-size: 0.86rem;
}

.total {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin: 0;
}

.total-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.total-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.info-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  margin: 14px 0 0;
  font-size: 0.9rem;
}

.info-grid dt {
  color: var(--muted);
}

.info-grid dd {
  margin: 0;
}

.bullets,
.issues,
.report-list,
.warn-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.bullets li,
.warn-list li {
  margin-bottom: 4px;
}

.issues,
.report-list {
  list-style: none;
  padding-left: 0;
}

.issues li,
.report-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.issues li:last-child,
.report-list li:last-child {
  border-bottom: 0;
}

.issue-item {
  font-weight: 600;
  margin-right: 8px;
}

.issue-issue {
  color: var(--warn-text);
  font-size: 0.9rem;
}

.table-scroll {
  overflow-x: auto;
}

.amounts {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 560px;
}

.amounts th,
.amounts td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
}

.amounts th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.amounts .cat {
  font-weight: 600;
  white-space: nowrap;
}

.amounts .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.amounts .src {
  color: var(--muted);
  font-size: 0.8rem;
}

.glossary {
  margin: 8px 0 0;
}

.glossary dt {
  font-weight: 600;
  margin-top: 10px;
}

.glossary dd {
  margin: 2px 0 0;
  color: var(--muted);
}

.report-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-fail {
  background: var(--error-bg);
  color: var(--error-text);
}

.footer {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

/* --- Save / share controls ------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.action {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
}

.action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.actions-feedback {
  color: var(--ok-text);
  font-size: 0.85rem;
}

.print-only {
  display: none;
}

/* --- Printing / "save as PDF" ---------------------------------------- */

@media print {
  /* Only the analysis is worth keeping. The upload card, the page chrome and
     the on-screen buttons have no meaning on paper. */
  .header,
  .footer,
  .no-print,
  #upload-card {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  body {
    background: #fff;
    font-size: 11pt;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .card {
    border: 0;
    border-top: 1px solid #ccc;
    border-radius: 0;
    padding: 10px 0 0;
    margin-bottom: 10px;
    /* Keep a section on one page where it fits. */
    break-inside: avoid;
  }

  .print-header {
    border: 0;
    margin-bottom: 4px;
  }

  .print-header h2 {
    margin: 0;
    font-size: 15pt;
  }

  .amounts {
    min-width: 0;
    font-size: 9.5pt;
  }

  .amounts thead {
    /* Repeat the column headers when the table spans pages. */
    display: table-header-group;
  }

  .amounts tr,
  .issues li,
  .report-list li {
    break-inside: avoid;
  }

  .table-scroll {
    overflow: visible;
  }

  .privacy,
  .notice {
    display: none;
  }

  .warn {
    border: 1px solid #999;
    background: #fff;
  }

  .disclaimer {
    margin-top: 14px;
    padding-top: 8px;
    border-top: 1px solid #ccc;
    font-size: 9pt;
    color: #444;
  }
}

.privacy summary {
  cursor: pointer;
}

.privacy ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.privacy li {
  margin-bottom: 6px;
}

.privacy strong {
  color: var(--text);
}

/* --- Waiting view ----------------------------------------------------- */

.waiting {
  margin-top: 14px;
}

.waiting .status {
  margin: 0 0 8px;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: #e5e9f2;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.35s ease;
}

/*
 * The model reports no progress, so rather than animate a fake percentage the
 * bar switches to a moving stripe: "working, length unknown".
 */
.bar-fill.is-indeterminate {
  width: 100%;
  background: repeating-linear-gradient(
    115deg,
    var(--accent) 0 12px,
    #7ea2ff 12px 24px
  );
  animation: bar-drift 1s linear infinite;
}

@keyframes bar-drift {
  from { background-position: 0 0; }
  to { background-position: 52px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill.is-indeterminate { animation: none; }
  .bar-fill { transition: none; }
}

#status-detail {
  margin: 6px 0 0;
  min-height: 1.2em;
}

/* --- Phones ----------------------------------------------------------- */

@media (max-width: 640px) {
  body {
    /* The default 14px is small for a document full of figures. */
    font-size: 15px;
  }

  .page {
    padding: 20px 14px 48px;
  }

  .card {
    padding: 16px 14px;
    border-radius: 10px;
  }

  .header h1 {
    font-size: 1.45rem;
  }

  /*
   * The five-column amounts table is the reason this page needed a phone
   * layout: at 560px minimum it made the most important content scroll
   * sideways. Each row becomes its own block instead, labelled from the
   * data-label attributes so no header row is needed.
   */
  .amounts {
    min-width: 0;
    font-size: 0.95rem;
    display: block;
  }

  .amounts thead {
    /* Visually hidden; the per-cell labels carry the same information. */
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .amounts tbody,
  .amounts tr,
  .amounts td {
    display: block;
    width: auto;
  }

  .amounts tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }

  .amounts tr:last-child {
    border-bottom: 0;
  }

  /*
   * Specificity matters here: the desktop `.amounts .num` and `.amounts .cat`
   * rules set `nowrap`, and a plain `.amounts td` loses to them. Without
   * matching them class-for-class a long value cannot wrap and pushes the
   * whole page sideways.
   */
  .amounts td,
  .amounts td.num,
  .amounts td.cat,
  .amounts td.src {
    border: 0;
    padding: 1px 0;
    white-space: normal;
    text-align: left;
    /* Last resort: never let one long token widen the page. */
    overflow-wrap: anywhere;
  }

  /* Trade name and amount lead the card; the rest is supporting detail. */
  .amounts td.cat {
    font-size: 1rem;
    font-weight: 700;
  }

  .amounts td.amount {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
  }

  .amounts td.num[data-label='수량']::before,
  .amounts td.src::before {
    content: attr(data-label) ' ';
    color: var(--muted);
    font-size: 0.8rem;
  }

  .amounts td.num[data-label='수량'],
  .amounts td.src {
    color: var(--muted);
    font-size: 0.85rem;
  }

  /* An empty cell would otherwise leave a stray label behind. */
  .amounts td.is-empty {
    display: none;
  }

  .table-scroll {
    overflow-x: visible;
  }

  .total-value {
    font-size: 1.6rem;
  }

  /* Long Korean labels were squeezing the values into a narrow column. */
  .info-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .info-grid dt {
    margin-top: 8px;
    font-size: 0.82rem;
  }

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

  .action {
    padding: 11px 8px;
    font-size: 0.9rem;
  }

  .actions-feedback {
    grid-column: 1 / -1;
  }

  .issue-item,
  .issue-issue {
    display: block;
  }

  .issue-item {
    margin-right: 0;
  }

  .file-list li {
    flex-wrap: wrap;
  }
}

/* --- Vendor groups on the upload screen -------------------------------- */

.vendor + .vendor {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.vendor-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.vendor-name {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}

.vendor-name:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.add-vendor {
  display: block;
  margin-top: 14px;
  font-size: 0.9rem;
}

/* --- Comparison result -------------------------------------------------- */

.vendor-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.vendor-total {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.vendor-total-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.vendor-vat {
  margin-top: 2px;
  font-size: 0.82rem;
  color: var(--warn-text);
}

.only-amount {
  margin-left: 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* A trade the quotation never mentioned. Muted so it does not read as zero. */
.amounts td.is-absent {
  color: var(--muted);
  font-weight: 400;
}

.amounts tr.observation td {
  padding-top: 0;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 640px) {
  .vendor-totals {
    grid-template-columns: 1fr;
  }

  /* Each comparison row stacks the same way the single-vendor table does. */
  .amounts.compare tr.observation td::before {
    content: '';
  }
}

/* --- "What we compare" — the page's answer to a search visitor ---------- */

.compare-list {
  margin: 0;
}

.compare-list dt {
  margin-top: 14px;
  font-weight: 600;
}

.compare-list dt:first-child {
  margin-top: 0;
}

.compare-list dd {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

@media print {
  /* Explanatory copy for new visitors; not part of a saved analysis. */
  #what-we-compare {
    display: none !important;
  }
}
