:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #eef3f8;
  --text: #172033;
  --muted: #65748b;
  --line: #d7e0ea;
  --primary: #1769aa;
  --primary-dark: #0f4d7d;
  --success: #1f8a5b;
  --danger: #b42318;
  --warning: #b76e00;
  --warning-bg: #fff8eb;
  --shadow: 0 18px 42px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, #eaf1f8 0%, var(--bg) 42%),
    var(--bg);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 48px));
  margin: 0 auto;
  padding: 48px 0;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

h2 {
  font-size: 1.35rem;
}

.description {
  max-width: 690px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 104px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.06);
}

.status-pill.warning {
  border-color: rgba(183, 110, 0, 0.26);
  background: var(--warning-bg);
  color: var(--warning);
}

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

.upload-panel {
  padding: 28px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.upload-card {
  position: relative;
  display: flex;
  min-height: 220px;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 28px;
  border: 1px dashed #9fb3c8;
  border-radius: 8px;
  background: var(--surface-muted);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.upload-card:hover,
.upload-card:focus-within,
.upload-card.drag-over {
  border-color: var(--primary);
  background: #f7fbff;
  transform: translateY(-1px);
}

.upload-card.has-file {
  border-style: solid;
  border-color: rgba(31, 138, 91, 0.34);
  background: #f8fcfa;
}

.upload-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.upload-label {
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.upload-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.upload-hint {
  color: var(--muted);
  font-size: 0.95rem;
}

.file-name {
  min-width: 0;
  max-width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  margin-top: 8px;
}

.file-name-row .file-name {
  margin-top: 0;
}

.file-remove-button {
  display: inline-flex;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.file-remove-button:hover:not(:disabled),
.file-remove-button:focus-visible {
  border-color: var(--danger);
  background: #fff7f6;
  color: var(--danger);
}

.file-remove-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.privacy-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.error-panel {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid rgba(180, 35, 24, 0.24);
  border-radius: 8px;
  background: #fff7f6;
  color: var(--danger);
}

.error-panel strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.error-panel p {
  margin: 0;
  color: #7a271a;
  white-space: pre-line;
}

.error-panel.info {
  border-color: rgba(23, 105, 170, 0.22);
  background: #f3f8fd;
  color: var(--primary-dark);
}

.error-panel.info p {
  color: var(--primary-dark);
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
  transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.primary-button {
  padding: 0 22px;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(23, 105, 170, 0.22);
}

.primary-button:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #9fb3c8;
  box-shadow: none;
  opacity: 0.75;
}

.secondary-button {
  padding: 0 18px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--primary-dark);
}

.secondary-button:hover {
  background: #f4f8fc;
}

.secondary-button:disabled {
  cursor: not-allowed;
  background: #f4f7fb;
  color: var(--muted);
  opacity: 0.72;
}

.results {
  display: none;
  margin-top: 24px;
  padding: 28px;
}

.results.visible {
  display: block;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.attention-copy {
  margin: 8px 0 0;
  color: var(--warning);
  font-size: 1rem;
  font-weight: 700;
}

.no-match-copy,
.table-count {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.result-card {
  min-height: 132px;
  padding: 20px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.result-card span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.result-card strong {
  display: block;
  margin-top: 20px;
  font-size: 2rem;
}

.result-card.warning {
  border-top-color: var(--warning);
}

.result-card.danger {
  border-top-color: var(--danger);
}

.result-card.neutral {
  border-top-color: #64748b;
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.diagnostic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.diagnostic-item.warning {
  border-color: rgba(183, 110, 0, 0.22);
  background: var(--warning-bg);
}

.diagnostic-item span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.diagnostic-item strong {
  font-size: 1.15rem;
}

.diagnostic-help {
  max-width: 220px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.text-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(23, 105, 170, 0.28);
  border-radius: 6px;
  background: #ffffff;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
}

.text-button:hover {
  background: #f4f8fc;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 16px;
  margin-top: 18px;
}

.result-block {
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.section-grid .result-block {
  margin-top: 0;
}

h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  line-height: 1.3;
}

.summary-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.summary-table th,
.summary-table td,
.data-table th,
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.summary-table th,
.data-table th {
  background: #f6f9fc;
  color: #334155;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-table td:last-child,
.summary-table th:last-child {
  text-align: right;
}

.total-row {
  color: var(--text);
  font-weight: 700;
}

.breakdown-list {
  margin: 0;
}

.breakdown-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.breakdown-list div:first-child {
  padding-top: 0;
}

.breakdown-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.breakdown-list dt {
  color: var(--muted);
  font-weight: 700;
}

.breakdown-list dd {
  margin: 0;
  font-weight: 700;
}

.table-block {
  padding-bottom: 16px;
}

.table-block h3 {
  margin-bottom: 4px;
}

.table-scroll {
  margin-top: 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.data-table {
  min-width: 1080px;
}

.data-table th,
.data-table td {
  white-space: nowrap;
}

.data-table td {
  font-size: 0.92rem;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(183, 110, 0, 0.24);
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 0.82rem;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-panel {
  width: min(1080px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}

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

body.modal-open {
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
}

.icon-button:hover {
  background: #f4f8fc;
}

.modal-content {
  max-height: calc(min(760px, 100vh - 48px) - 89px);
  overflow: auto;
  padding: 20px 24px 24px;
}

.duplicate-summary {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
}

.duplicate-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.duplicate-group + .duplicate-group {
  margin-top: 12px;
}

.duplicate-group summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
}

.duplicate-group summary span {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duplicate-records {
  padding: 0 16px 16px;
}

.duplicate-records h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 0.98rem;
}

.duplicate-records .table-scroll {
  margin-top: 0;
}

.duplicate-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.duplicate-table th,
.duplicate-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.duplicate-table th {
  background: #f6f9fc;
  color: #334155;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100% - 32px, 760px);
    padding: 32px 0;
  }

  .header,
  .results-header {
    flex-direction: column;
    align-items: stretch;
  }

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

  .upload-grid,
  .result-grid,
  .diagnostic-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
    justify-content: stretch;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

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

  .modal-backdrop {
    padding: 12px;
  }

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

@media (min-width: 881px) and (max-width: 1180px) {
  .result-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
