/*
 * Version 3 -- shared system-import panel.
 *
 * One stylesheet for every system wired to `imports/systemImportController.js`,
 * because there is one panel: `v3-import-*` carries no vendor name and no
 * vendor-specific rule. `v3-perch-import.css` and
 * `v3-force-measurement-import.css` remain in place for the two systems that
 * kept their own controllers.
 *
 * Match status is a word in a badge, never a colour alone -- the badge tints
 * its border and the text inside it says "Matched", "Needs athlete matching",
 * or "Matches more than one athlete". A reader who sees no colour loses
 * nothing.
 *
 * Every table scrolls inside its own focusable wrapper, so a wide preview is
 * reachable by keyboard and the page body never scrolls sideways.
 */

.v3-import {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-3);
  margin-top: var(--v3-space-5);
  padding: var(--v3-space-4);
  border-radius: var(--v3-radius-md);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface);
}

/* ---- header ------------------------------------------------------------- */

.v3-import-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: var(--v3-space-2);
  border-bottom: 1px solid var(--v3-border);
}

.v3-import-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-import-subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--v3-text-muted);
}

/* ---- status and success ------------------------------------------------- */

.v3-import-status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--v3-text-muted);
}

.v3-import-success {
  margin: 0;
  padding: var(--v3-space-2) var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border-strong);
  background: var(--v3-surface-muted);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--v3-text);
}

/* ---- file field --------------------------------------------------------- */

.v3-import-field {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-1);
  min-width: 0;
}

.v3-import-field label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-import-field input[type="file"] {
  max-width: 100%;
  font-size: 0.85rem;
}

.v3-import-field input[type="file"]:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-import-hint {
  margin: 0;
  max-width: 78ch;
  font-size: 0.75rem;
  color: var(--v3-text-muted);
}

/* ---- errors ------------------------------------------------------------- */

.v3-import-file-errors {
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border-strong);
  background: var(--v3-surface-muted);
  font-size: 0.85rem;
}

.v3-import-file-errors ul,
.v3-import-validation-group ul {
  margin: 0;
  padding-left: var(--v3-space-4);
}

.v3-import-file-errors:focus-visible,
.v3-import-results:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

/* ---- results ------------------------------------------------------------ */

.v3-import-results {
  display: flex;
  flex-direction: column;
  gap: var(--v3-space-4);
}

.v3-import-section-heading {
  margin: 0 0 var(--v3-space-2);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-import-note {
  margin: 0;
  max-width: 78ch;
  font-size: 0.8rem;
  color: var(--v3-text-muted);
}

/* ---- summary tiles ------------------------------------------------------ */

.v3-import-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--v3-space-2);
  margin: 0;
}

.v3-import-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--v3-space-2) var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border);
  background: var(--v3-surface-muted);
  min-width: 0;
}

.v3-import-summary-item dt {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--v3-text-muted);
}

.v3-import-summary-item dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--v3-maroon);
  overflow-wrap: anywhere;
}

/* The file name is text, not a count, so it is not sized like one. */
.v3-import-summary-item:first-child dd {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--v3-text);
}

/* ---- preview table ------------------------------------------------------ */

.v3-import-table-wrap {
  overflow-x: auto;
  max-width: 100%;
  max-height: 320px;
  overflow-y: auto;
}

.v3-import-table-wrap:focus-visible {
  outline: 2px solid var(--v3-focus-ring);
  outline-offset: 2px;
}

.v3-import-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.v3-import-table th,
.v3-import-table td {
  padding: var(--v3-space-1) var(--v3-space-2);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--v3-border);
}

.v3-import-table thead th {
  position: sticky;
  top: 0;
  background: var(--v3-surface);
  color: var(--v3-text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.v3-import-table tbody th {
  font-weight: 600;
  color: var(--v3-text);
}

/* Tint only. The badge beside it carries the same information in words. */
.v3-import-row--unmatched,
.v3-import-row--ambiguous {
  background: var(--v3-surface-muted);
}

.v3-import-status-badge {
  display: inline-block;
  padding: 0 var(--v3-space-1);
  border-radius: var(--v3-radius-sm);
  border: 1px solid var(--v3-border-strong);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--v3-text-muted);
  white-space: nowrap;
}

.v3-import-status-badge--matched {
  border-color: var(--v3-maroon);
  color: var(--v3-maroon);
}

/* ---- validation --------------------------------------------------------- */

.v3-import-validation-group + .v3-import-validation-group {
  margin-top: var(--v3-space-3);
}

.v3-import-validation-group h5 {
  margin: 0 0 var(--v3-space-1);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--v3-text);
}

.v3-import-validation-group li {
  font-size: 0.8rem;
  color: var(--v3-text-muted);
  overflow-wrap: anywhere;
}

/* ---- unresolved identities ---------------------------------------------- */

.v3-import-unresolved {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--v3-space-2);
  padding: var(--v3-space-3);
  border-radius: var(--v3-radius-sm);
  border: 1px dashed var(--v3-border-strong);
  background: var(--v3-surface-muted);
}

.v3-import-unresolved p {
  margin: 0;
  max-width: 78ch;
  font-size: 0.82rem;
  color: var(--v3-text-muted);
}

/* ---- actions ------------------------------------------------------------ */

.v3-import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--v3-space-2);
  padding-top: var(--v3-space-2);
  border-top: 1px solid var(--v3-border);
}

/* ---- responsive --------------------------------------------------------- */

@media (max-width: 720px) {
  .v3-import-summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .v3-import-actions {
    flex-direction: column;
    align-items: stretch;
  }
}
