:root {
  color-scheme: dark;
  --bg: #111821;
  --panel: #151d28;
  --line: #2b3546;
  --text: #dcecff;
  --muted: #8fa2bd;
  --accent: #8d5cf6;
  --accent-strong: #a16dff;
  --button-muted: #727b98;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 "Segoe UI", system-ui, sans-serif;
}

button,
input,
.button {
  font: inherit;
}

.shell {
  width: min(1900px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

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

h1 {
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
}

h2 {
  font-size: 20px;
}

.source {
  max-width: 560px;
  color: var(--muted);
  text-align: right;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 16px;
  align-items: end;
  padding: 18px;
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121a24;
}

label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

input {
  width: 100%;
  height: 44px;
  border: 1px solid #344057;
  border-radius: 8px;
  background: #101720;
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(141 92 246 / 18%);
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 24px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

button.secondary,
.button.secondary {
  background: var(--button-muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  white-space: nowrap;
}

button.small {
  min-height: 36px;
  padding: 0 14px;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

.results {
  border-top: 1px solid var(--line);
}

.review {
  margin-top: 44px;
}

.station-search {
  margin-bottom: 44px;
}

.search-help,
.empty-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #121a24;
  padding: 22px;
  color: var(--muted);
}

.search-help h2,
.empty-card h3 {
  color: var(--text);
  margin: 0 0 8px;
}

.search-help p,
.empty-card p {
  margin: 0;
}

.admin-shell {
  max-width: 1180px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .8fr);
  gap: 18px;
  margin-bottom: 32px;
}

.admin-card,
.notice {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #121a24;
  padding: 22px;
}

.admin-card h2 {
  margin-bottom: 8px;
}

.admin-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.admin-form {
  display: grid;
  gap: 16px;
}

.admin-list {
  margin: 16px 0 0;
  padding-left: 20px;
  color: var(--muted);
}

.admin-list li + li {
  margin-top: 10px;
}

.tool-status {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.tool-status div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.tool-status dt {
  color: var(--muted);
  font-weight: 700;
}

.tool-status dd {
  margin: 0;
  color: var(--text);
  font-weight: 800;
}

.notice {
  margin-bottom: 18px;
  font-weight: 700;
}

.notice.success {
  border-color: #237a55;
  background: #11251f;
  color: #b7f7d5;
}

.notice.error {
  border-color: #9c3d3d;
  background: #28181d;
  color: #ffd0d0;
}

.admin-results {
  margin-top: 32px;
}

.image-results {
  border-top: 1px solid var(--line);
}

.diagram-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 18px;
}

.diagram-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #121a24;
}

.diagram-card__header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.diagram-card__header h3 {
  margin: 0;
  font-size: 18px;
}

.diagram-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.diagram-meta div {
  padding: 12px 16px;
  border-right: 1px solid var(--line);
}

.diagram-meta div:last-child {
  border-right: 0;
}

.diagram-meta dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.diagram-meta dd {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.diagram-card img {
  display: block;
  width: 100%;
  height: auto;
  background: white;
}

[hidden] {
  display: none !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 0 10px;
}

#resultCount,
#stationResultCount,
#suggestionCount {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  background: #121a24;
}

td {
  color: #cfe5ff;
  font-size: 14px;
}

tbody tr:hover {
  background: rgb(255 255 255 / 3%);
}

td:first-child {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
}

dialog {
  width: min(96vw, 1400px);
  max-height: 94vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgb(0 0 0 / 70%);
}

.viewer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

#viewerMeta {
  color: var(--muted);
  margin-left: 8px;
}

#viewerImage {
  display: block;
  width: 100%;
  height: auto;
  background: white;
}

@media (max-width: 1050px) {
  .topbar,
  .section-title {
    display: block;
  }

  .source {
    text-align: left;
    margin-top: 12px;
  }

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

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

  table {
    display: block;
    overflow-x: auto;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 28px, 1900px);
    padding-top: 18px;
  }

  .filters {
    grid-template-columns: 1fr;
    padding-bottom: 34px;
  }

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

  .diagram-meta {
    grid-template-columns: 1fr 1fr;
  }

  th,
  td {
    padding: 18px 22px;
  }
}
