/* --- Global Styles & Modern Font --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    'Inter',
    -apple-system,
    sans-serif;
  background: #f1f5f9; /* High-contrast clean background */
  color: #1e293b;
  line-height: 1.5;
}

/* --- Refined Header --- */
header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #0f172a;
  color: white;
  padding: 24px 20px;
  border-bottom: 4px solid #2563eb; /* Visual accent line */
}

header h1 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 800;
}

header p {
  margin: 0;
  color: #94a3b8;
  font-weight: 500;
}

.container {
  width: min(1240px, 94%);
  margin: 0 auto;
}

main.container {
  margin: 22px auto 32px;
}

.header-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.15fr);
  gap: 32px;
  align-items: center;
}

.brand-block {
  min-width: 0;
}

.header-summary {
  min-width: 0;
}

.header-summary h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: #ffffff;
}

.header-summary p {
  font-size: 14px;
  line-height: 1.45;
}

/* --- Dashboard Grid & Floating Cards --- */
.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
}

.card {
  background: #ffffff;
  border-radius: 8px;
  padding: 22px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.05),
    0 2px 4px -2px rgba(0, 0, 0, 0.05);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.card:hover {
  box-shadow:
    0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.card h2,
.card h3 {
  font-weight: 700;
  color: #0f172a;
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 1.2rem;
}

.card p {
  margin: 0 0 12px;
}

.form-section {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
}

.form-section + .form-section {
  margin-top: 16px;
}

.form-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 1.05rem;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.form-section > summary::-webkit-details-marker {
  display: none;
}

.form-section > summary::after {
  content: '+';
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #e2e8f0;
  color: #2563eb;
  font-size: 18px;
  line-height: 1;
}

.form-section[open] > summary {
  border-bottom: 1px solid #e2e8f0;
  border-radius: 8px 8px 0 0;
}

.form-section[open] > summary::after {
  content: '-';
}

.form-section > .row,
.form-section > label,
.form-section > select,
.form-section > .subject-options,
.form-section > .helper,
.form-section > .feature-grid,
.form-section > p {
  margin-left: 16px;
  margin-right: 16px;
}

.form-section > .row:first-of-type,
.form-section > label:first-of-type,
.form-section > p {
  margin-top: 14px;
}

.form-section > .helper,
.form-section > .feature-grid {
  margin-bottom: 16px;
}

.subject-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.subject-choice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 42px;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #ffffff;
  color: #1e293b;
  cursor: pointer;
  line-height: 1.25;
}

.subject-choice input {
  appearance: auto;
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  padding: 0;
  accent-color: #2563eb;
  flex: 0 0 auto;
}

.subject-choice:has(input:checked) {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}

.subject-choice:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.55;
}

.subject-loading {
  color: #64748b;
  font-size: 14px;
}

.results-actions {
  display: flex;
  justify-content: flex-end;
  margin: 16px 16px 0;
}

.results-actions .secondary {
  max-width: 160px;
}

.admin-summary-btn {
  margin-left: 8px;
}

.filter-panel {
  margin: 16px;
  padding: 16px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.filter-panel h3 {
  margin-top: 0;
}

.filter-panel #resultsMeta {
  margin-top: 12px;
}

.results-section #swopChains,
.results-section #results {
  margin-left: 16px;
  margin-right: 16px;
}

/* --- SaaS Stats --- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.stat {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.stat strong {
  font-size: 24px;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 4px;
}

.stat span {
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* --- High-Quality Inputs --- */
label {
  display: block;
  margin: 16px 0 8px;
  font-weight: 600;
  font-size: 13px;
  color: #475569;
}

select,
input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 15px;
  background-color: #f8fafc;
  transition: all 0.2s ease;
}

select:focus,
input:focus {
  outline: none;
  border-color: #2563eb;
  background-color: #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* --- Buttons & Branding --- */
button {
  border: none;
  border-radius: 8px;
  padding: 14px 20px;
  cursor: pointer;
  font-weight: 700;
  font-size: 15px;
  transition: all 0.2s ease;
}

.primary {
  background: #2563eb;
  color: white;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.primary:hover {
  background: #1d4ed8;
  box-shadow: 0 6px 15px rgba(37, 99, 235, 0.3);
}

.secondary {
  background: #ffffff;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.secondary:hover {
  background: #f1f5f9;
  color: #1e293b;
}

/* --- Listing Cards --- */
.listing {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  background: #ffffff;
  border-left: 5px solid #2563eb; /* Active accent */
}

.listing h4 {
  margin: 0 0 12px;
  font-size: 1.15rem;
  color: #1e293b;
}

.tag {
  display: inline-block;
  padding: 5px 10px;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 8px; /* Modern squircle instead of pill */
  font-size: 12px;
  font-weight: 700;
  margin: 3px 4px 0 0;
}

.match-badge.no-match,
.no-direct-match {
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

.no-direct-match {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.no-match-actions {
  display: grid;
  gap: 10px;
  align-items: start;
  max-width: 320px;
}

.no-match-actions label {
  margin: 0;
}

.no-match-actions select {
  margin-top: 6px;
  border-color: #fecaca;
}

.listing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.listing-actions button {
  width: auto;
  padding: 9px 12px;
  font-size: 13px;
}

/* --- Feature Grid (Station Conditions) --- */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  background: #f8fafc;
  padding: 16px;
  border-radius: 8px;
  margin-top: 12px;
}

/* --- Empty States & Footer --- */
.empty {
  padding: 40px;
  text-align: center;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  color: #64748b;
  font-weight: 500;
}

footer {
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
  margin: 60px 0 30px;
}

@media (max-width: 860px) {
  .header-layout,
  .hero,
  .main-grid,
  .row,
  .stats,
  .feature-grid,
  .subject-options {
    grid-template-columns: 1fr;
  }

  .header-layout {
    gap: 18px;
  }
}

@media (max-width: 980px), (max-height: 760px) {
  header {
    padding: 10px 14px;
  }

  header h1 {
    margin-bottom: 2px;
    font-size: 22px;
  }

  header p {
    font-size: 13px;
  }

  .header-layout {
    grid-template-columns: minmax(220px, 0.8fr) minmax(360px, 1.2fr);
    gap: 18px;
  }

  .header-summary h2 {
    margin-bottom: 4px;
    font-size: 0.95rem;
  }

  .header-summary p {
    display: none;
  }

  .stats {
    gap: 8px;
    margin-top: 0;
  }

  .stat {
    padding: 8px 10px;
  }

  .stat strong {
    font-size: 18px;
    margin-bottom: 0;
  }

  .stat span {
    font-size: 9px;
  }
}

@media (max-width: 680px) {
  .header-layout {
    grid-template-columns: 1fr;
  }

  .brand-block p {
    display: none;
  }
}
