:root {
  color-scheme: light;
  --brand-red: #c21f17;
  --brand-gray: #706f6f;
  --canvas: #f2f0ec;
  --surface: #fffdf9;
  --surface-subtle: #f8f6f2;
  --text: #272421;
  --muted: var(--brand-gray);
  --line: #ded9d1;
  --line-strong: #c8c1b8;
  --accent: var(--brand-red);
  --accent-hover: #a71913;
  --accent-soft: #fdebea;
  --found: #2d6548;
  --found-soft: #eaf4ee;
  --unassigned: #7a5a16;
  --unassigned-soft: #f8f0d9;
  --review: #92501f;
  --review-soft: #faecdf;
  --not-found: #665f58;
  --not-found-soft: #efede9;
  --error: #9a3030;
  --error-soft: #f8e8e7;
  --focus: var(--brand-red);
  --shadow: 0 1px 2px rgba(39, 36, 33, 0.05), 0 12px 30px rgba(39, 36, 33, 0.035);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page {
  width: min(100% - 40px, 1400px);
  margin: 0 auto;
  padding: 18px 0 32px;
}

.app-header {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 2px 16px;
  border-bottom: 1px solid var(--line-strong);
}

.brand-lockup,
.header-actions,
.section-heading,
.search-toolbar,
.actions,
.admin-tools-body,
.upload-form,
.modal-header {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 17px;
}

.brand-logo {
  display: block;
  height: auto;
  object-fit: contain;
}

.app-brand-logo {
  width: 170px;
}

.app-identity {
  padding-left: 17px;
  border-left: 1px solid var(--line-strong);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.eyebrow,
.section-kicker {
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.header-actions {
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.header-actions form {
  margin: 0;
}

.user-email {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--found);
  font-weight: 650;
}

.service-status > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--found);
  box-shadow: 0 0 0 3px var(--found-soft);
}

.search-panel,
.results-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 18px 20px 16px;
}

.results-panel {
  overflow: hidden;
}

.section-heading {
  justify-content: space-between;
  gap: 28px;
}

.section-heading p:not(.section-kicker) {
  margin-bottom: 0;
  color: var(--muted);
}

.source-status {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(2, auto);
  gap: 20px;
  padding-left: 20px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.source-status span {
  display: grid;
  gap: 1px;
}

.source-status strong {
  color: var(--text);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.search-form {
  margin-top: 14px;
}

.search-form textarea {
  display: block;
  width: 100%;
  min-height: 112px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.search-form textarea::placeholder {
  color: #a49e96;
}

.search-form textarea:hover {
  border-color: #aaa299;
}

.search-form textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(194, 31, 23, 0.12);
}

.search-form[aria-busy="true"] textarea {
  background: var(--surface-subtle);
  color: var(--muted);
  cursor: wait;
}

.search-toolbar {
  justify-content: space-between;
  gap: 20px;
  margin-top: 10px;
}

.keyboard-help {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-subtle);
  color: #514c47;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.entry-count {
  padding-left: 14px;
  border-left: 1px solid var(--line);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.actions {
  gap: 8px;
}

.button,
.text-button {
  border: 0;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 7px;
}

.button.primary {
  min-width: 98px;
  background: var(--accent);
  color: #fff;
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--text);
}

.button.secondary:hover:not(:disabled) {
  border-color: #aba39a;
  background: var(--surface-subtle);
}

.button.compact {
  min-height: 30px;
  padding: 5px 9px;
  border-color: #d5b293;
  background: var(--review-soft);
  color: #784014;
  font-size: 12px;
}

.button:disabled,
.candidate-card:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.text-button {
  padding: 2px 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
}

.text-button:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.form-message {
  margin: 9px 0 0;
  color: var(--error);
  font-size: 12px;
  font-weight: 650;
}

.results-heading {
  min-height: 78px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.results-summary {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-subtle);
}

.summary-item {
  display: flex;
  min-width: 145px;
  align-items: baseline;
  gap: 7px;
  padding: 10px 18px 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.summary-item + .summary-item {
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.summary-item strong {
  color: var(--text);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.summary-item.unassigned strong {
  color: var(--unassigned);
}

.summary-item.review strong {
  color: var(--review);
}

.summary-item.service-error strong {
  color: var(--error);
}

.table-wrap {
  width: 100%;
  overflow: hidden;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
}

.results-table th,
.results-table td {
  overflow-wrap: anywhere;
  text-align: left;
  vertical-align: top;
}

.results-table th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-strong);
  background: #f5f2ed;
  color: #68625c;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.results-table td {
  padding: 12px;
  border-bottom: 1px solid #e9e5df;
  color: #3d3935;
  line-height: 1.35;
}

.results-table th:nth-child(1),
.results-table td:nth-child(1) { width: 13%; }
.results-table th:nth-child(2),
.results-table td:nth-child(2) { width: 14%; }
.results-table th:nth-child(3),
.results-table td:nth-child(3) { width: 22%; }
.results-table th:nth-child(4),
.results-table td:nth-child(4) { width: 20%; }
.results-table th:nth-child(5),
.results-table td:nth-child(5) { width: 19%; }
.results-table th:nth-child(6),
.results-table td:nth-child(6) { width: 12%; }

.results-table tbody tr.result-row:hover {
  background: #fbfaf7;
}

.results-table td > strong,
.results-table td > span {
  display: block;
}

.input-cell strong {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.secondary-value {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.status-cell {
  padding-left: 16px !important;
  border-left: 3px solid transparent;
}

.state-found .status-cell { border-left-color: var(--found); }
.state-unassigned .status-cell { border-left-color: #b1882d; }
.state-review .status-cell { border-left-color: var(--review); }
.state-not_found .status-cell { border-left-color: var(--not-found); }
.state-service_error .status-cell { border-left-color: var(--error); }

.status-badge {
  display: inline-flex !important;
  width: fit-content;
  padding: 4px 7px;
  border-radius: 5px;
  background: var(--not-found-soft);
  color: var(--not-found);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.state-found .status-badge { background: var(--found-soft); color: var(--found); }
.state-unassigned .status-badge { background: var(--unassigned-soft); color: var(--unassigned); }
.state-review .status-badge { background: var(--review-soft); color: var(--review); }
.state-service_error .status-badge { background: var(--error-soft); color: var(--error); }

.row-actions {
  white-space: nowrap;
}

.row-actions .button,
.row-actions .text-button {
  display: block;
  width: fit-content;
  white-space: nowrap;
}

.row-actions .button + .text-button {
  margin-top: 7px;
}

.result-context-menu {
  position: fixed;
  z-index: 50;
  display: grid;
  width: min(320px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 16px 42px rgba(28, 25, 23, 0.2);
}

.context-menu-action {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  text-align: left;
}

.context-menu-action:hover,
.context-menu-action:focus-visible {
  outline: none;
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.context-menu-preview {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-menu-separator {
  height: 1px;
  margin: 5px 6px;
  background: var(--line);
}

.copy-toast {
  position: fixed;
  z-index: 60;
  bottom: 22px;
  left: 50%;
  max-width: min(520px, calc(100vw - 32px));
  margin: 0;
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid #b8d3c3;
  border-radius: 8px;
  background: var(--found-soft);
  color: var(--found);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}

.copy-toast.is-error {
  border-color: #e5b8b5;
  background: var(--error-soft);
  color: var(--error);
}

.clipboard-fallback {
  position: fixed;
  left: -10000px;
  top: -10000px;
}

.detail-row td {
  padding: 0 !important;
  border-bottom: 1px solid var(--line-strong);
  background: #f8f5f0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 24px;
  padding: 18px 22px 20px;
  border-left: 3px solid var(--line-strong);
}

.detail-grid > div {
  min-width: 0;
}

.detail-grid span,
.detail-grid strong {
  display: block;
}

.detail-grid span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.detail-grid strong {
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 650;
}

.empty-state {
  display: flex;
  min-height: 160px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 15px;
}

.empty-state p {
  margin: 3px 0 0;
}

.empty-icon {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-subtle);
  color: var(--accent);
  font-size: 25px;
}

.admin-tools {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 249, 0.62);
}

.admin-tools summary {
  padding: 11px 14px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.admin-tools-body {
  justify-content: space-between;
  gap: 28px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.admin-tools-body p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.upload-form {
  flex: 0 0 auto;
  gap: 10px;
}

#padron-file-name {
  max-width: 230px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start center;
  padding: 7vh 24px 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 23, 0.54);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: min(100%, 860px);
  max-height: 86vh;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 30px 80px rgba(28, 25, 23, 0.25);
}

.modal-header {
  align-items: start;
  justify-content: space-between;
  gap: 24px;
}

.modal-header p:not(.section-kicker) {
  margin-bottom: 0;
  color: var(--muted);
}

.modal-status {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.modal-candidates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.candidate-card {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.candidate-card:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.candidate-card strong {
  margin-bottom: 3px;
}

.candidate-card span {
  color: var(--muted);
  font-size: 12px;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--canvas);
}

.login-card {
  width: min(100%, 430px);
  padding: 30px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  min-height: 96px;
  align-items: center;
  justify-content: center;
  margin: -6px 0 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.login-brand-logo {
  width: min(100%, 235px);
}

.login-card h1 {
  margin: 4px 0 8px;
  font-size: 25px;
}

.login-card > p:not(.eyebrow):not(.login-error) {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.login-form label {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: none;
  background: #fff;
  color: var(--text);
}

.login-form input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(194, 31, 23, 0.12);
}

.login-form .button {
  margin-top: 10px;
}

.login-error {
  padding: 9px 10px;
  border-left: 3px solid var(--error);
  background: var(--error-soft);
  color: #7d2525;
}

@media (max-width: 980px) {
  .page {
    width: min(100% - 24px, 1400px);
  }

  .source-status {
    display: none;
  }

  .results-table {
    min-width: 940px;
  }

  .table-wrap {
    overflow-x: auto;
  }

  .detail-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-header,
  .header-actions,
  .search-toolbar,
  .admin-tools-body,
  .upload-form {
    align-items: stretch;
    flex-direction: column;
  }

  .app-header {
    align-items: flex-start;
  }

  .app-brand-logo {
    width: 150px;
  }

  .header-actions,
  .keyboard-help {
    flex-wrap: wrap;
  }

  .results-summary {
    overflow-x: auto;
  }

  .modal-candidates,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
