:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #62707f;
  --line: #d9e0e6;
  --blue: #1f5f8b;
  --blue-dark: #17496d;
  --green: #0d7a5f;
  --amber: #ad6b00;
  --red: #b63d36;
  --teal-soft: #e8f5f1;
  --amber-soft: #fff5df;
  --red-soft: #fff0ee;
  --gray-soft: #eef2f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 32px 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 27px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  padding: 8px 13px;
  font-size: 13px;
  white-space: nowrap;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.control-panel,
.status-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.control-panel {
  padding: 20px;
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  padding: 18px 20px;
}

.results-panel {
  min-width: 0;
  padding: 20px 20px 16px;
}

.section-head,
.table-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-head .muted {
  margin: 4px 0 0;
}

.type-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  align-items: end;
  gap: 16px;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-wide {
  grid-column: 1 / -1;
}

.field-wide:first-child {
  grid-column: 1 / -1;
}

.field span,
.station-field legend,
.toggle span {
  color: #334353;
  font-size: 13px;
  font-weight: 700;
}

textarea,
select,
input[type="number"],
input[type="text"] {
  width: 100%;
  border: 1px solid #c7d1da;
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 82px;
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.5;
}

input[type="number"] {
  height: 42px;
  padding: 0 10px;
}

input[type="text"],
select {
  height: 42px;
  padding: 0 10px;
}

textarea:focus,
select:focus,
input[type="number"]:focus,
input[type="text"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.14);
}

.unit-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.unit-input span {
  min-width: 28px;
  color: var(--muted);
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.station-field {
  grid-column: span 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  min-height: 42px;
  margin: 0;
  padding: 0;
  border: 0;
}

.station-field legend {
  width: 100%;
  margin-bottom: -4px;
}

.station-field label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #334353;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #ffffff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:hover {
  background: var(--blue-dark);
}

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

button.secondary {
  background: #ffffff;
  color: var(--blue);
}

button.secondary:hover {
  background: #edf5fb;
}

.notice,
.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.notice {
  margin: 16px 0 0;
}

#result-meta {
  margin: 5px 0 0;
}

.count-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.count-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.message-area {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.message {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.message.error {
  background: var(--red-soft);
  color: #7c251f;
  border: 1px solid #f0c4c0;
}

.message.warning {
  background: var(--amber-soft);
  color: #704500;
  border: 1px solid #ecd39d;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  line-height: 1.45;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f6;
  color: #2f4050;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

td a {
  color: var(--blue);
  font-weight: 700;
}

.verdict {
  display: inline-flex;
  align-items: center;
  min-width: 86px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.verdict.match {
  background: var(--teal-soft);
  color: var(--green);
}

.verdict.excluded {
  background: var(--gray-soft);
  color: #53616f;
}

.verdict.bus {
  background: var(--amber-soft);
  color: var(--amber);
}

.verdict.review {
  background: var(--red-soft);
  color: var(--red);
}

.empty-cell {
  height: 160px;
  color: var(--muted);
  text-align: center;
  vertical-align: middle;
}

@media (max-width: 920px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 22px 18px 16px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
  }

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

  .section-head,
  .table-section-head,
  .status-panel {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .count-strip {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .station-field {
    grid-column: 1;
  }

  .actions button {
    width: 100%;
  }
}
