:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eceff2;
  --text: #182027;
  --muted: #5d6a75;
  --line: #d7dee5;
  --accent: #a6a6a6;
  --accent-dark: #737373;
  --warn: #a3551f;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(24, 32, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.login-view {
  align-items: center;
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-card {
  max-width: 420px;
  width: 100%;
}

.login-card h1 {
  color: var(--text);
  margin-bottom: 10px;
}

.hint {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0;
}

.topbar {
  align-items: center;
  background: #182027;
  color: #fff;
  display: flex;
  justify-content: space-between;
  min-height: 86px;
  padding: 18px clamp(16px, 4vw, 48px);
}

.brand {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
  display: block;
  flex: 0 0 auto;
  height: 58px;
  object-fit: cover;
  width: 58px;
}

.top-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.eyebrow {
  color: #c9ced3;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(1.55rem, 3vw, 2.4rem);
}

.version-label {
  color: #c9ced3;
  font-size: 0.85rem;
  font-weight: 700;
  margin: 5px 0 0;
}

h2 {
  font-size: 1rem;
}

main {
  margin: 0 auto;
  max-width: 1280px;
  padding: 22px clamp(16px, 4vw, 48px) 48px;
}

.status {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #eaf6f3;
  font-size: 0.9rem;
  padding: 8px 12px;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 20px;
}

.summary-grid article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
}

.summary-grid span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.summary-grid strong {
  display: block;
  font-size: 1.35rem;
  min-height: 32px;
}

.tabs {
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab {
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 12px 14px;
}

.tab.active {
  border-color: var(--accent);
  color: var(--text);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.form-panel {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-bottom: 20px;
}

form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.82rem;
  font-weight: 700;
  gap: 6px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #c9d2da;
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 40px;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  min-height: 76px;
  resize: vertical;
}

button.primary {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #182027;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
}

.ghost {
  align-items: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  text-decoration: none;
}

.restore-form {
  background: transparent;
  border: 0;
  display: inline-flex;
  padding: 0;
}

.file-button input {
  display: none;
}

button.primary:hover {
  background: var(--accent-dark);
  color: #fff;
}

button.secondary {
  background: #eef0f2;
  border: 1px solid #c7ccd1;
  border-radius: 6px;
  color: var(--accent-dark);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 42px;
  padding: 0 16px;
}

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

.admin-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 420px));
  margin-bottom: 20px;
}

.view-switch {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: inline-flex;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
}

.view-button {
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 36px;
  padding: 0 14px;
}

.view-button.active {
  background: var(--accent);
  color: var(--text);
}

.matrix-toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  gap: 16px;
  justify-content: flex-end;
  margin-bottom: 12px;
  padding: 12px;
}

.matrix-toolbar label {
  max-width: 140px;
}

.checkbox-label {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  max-width: none !important;
}

.checkbox-label input {
  min-height: auto;
  width: auto;
}

#routeMatrixView {
  margin-left: calc(50% - 50vw + 16px);
  width: calc(100vw - 32px);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 820px;
  width: 100%;
}

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

th {
  background: #a6a6a6;
  color: #182027;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.matrix-wrap {
  max-height: 68vh;
  overflow: auto;
}

.matrix-table {
  min-width: 1540px;
}

.matrix-table th,
.matrix-table td {
  padding: 8px 10px;
}

.matrix-table th[rowspan],
.matrix-table td:nth-child(-n + 5) {
  min-width: 108px;
}

.matrix-table .month-group {
  text-align: center;
}

.matrix-table thead th {
  position: sticky;
  z-index: 2;
}

.matrix-table thead tr:first-child th {
  top: 0;
}

.matrix-table thead tr:nth-child(2) th {
  top: 33px;
}

.matrix-region-row td {
  background: #eceff1;
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  padding: 0;
}

.matrix-region-toggle {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  color: #182027;
  cursor: pointer;
  display: flex;
  font-weight: 700;
  gap: 10px;
  justify-content: flex-start;
  min-height: 38px;
  padding: 8px 12px;
  text-align: left;
  width: 100%;
}

.matrix-region-toggle:hover {
  background: #dde3e7;
}

.matrix-region-icon {
  align-items: center;
  background: #a6a6a6;
  border-radius: 4px;
  display: inline-flex;
  height: 20px;
  justify-content: center;
  line-height: 1;
  width: 20px;
}

.matrix-region-count {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.date-cell {
  min-width: 116px;
  padding: 6px;
}

.matrix-acquired,
.matrix-date {
  font-size: 0.9rem;
  min-height: 34px;
  padding: 6px;
  text-align: center;
  width: 96px;
}

.month-cell {
  min-width: 50px;
  padding: 5px;
}

.matrix-day {
  font-size: 0.9rem;
  min-height: 34px;
  padding: 5px;
  text-align: center;
  width: 40px;
}

.map-toolbar {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 14px 16px;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.map-legend {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 12px;
}

.map-filter {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 0.86rem;
  font-weight: 700;
  gap: 5px;
  min-height: 30px;
  padding: 5px 8px;
}

.map-filter input {
  accent-color: var(--accent-dark);
  height: 10px;
  margin: 0;
  width: 10px;
}

.map-filter:has(input:not(:checked)) {
  opacity: 0.48;
}

.legend-swatch {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 22px;
}

.legend-swatch.valid {
  background: #2f8f46;
}

.legend-swatch.warning {
  background: #d8a21b;
}

.legend-swatch.expired {
  background: #c0392b;
}

.legend-swatch.unknown {
  background: #8f989f;
}

.route-map-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 520px;
  overflow: hidden;
  position: relative;
}

.route-map {
  display: block;
  height: min(70vh, 720px);
  min-height: 520px;
  width: 100%;
}

.map-city-label {
  pointer-events: none;
}

.map-city-label circle {
  fill: #182027;
  stroke: #ffffff;
  stroke-width: 1.8;
}

.map-city-text {
  fill: #182027;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.map-city-halo {
  fill: none;
  stroke: #ffffff;
  stroke-linejoin: round;
  stroke-width: 4;
}

.map-empty {
  color: var(--muted);
  font-weight: 700;
  left: 50%;
  position: absolute;
  text-align: center;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
}

.section-toolbar {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 0 12px;
  padding: 14px 16px;
}

.isr-review,
.stock-suggestions {
  margin-bottom: 20px;
}

.isr-review-wrap {
  max-height: 520px;
  overflow: auto;
}

.isr-review-table {
  min-width: 1180px;
}

.isr-review-table th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.status-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 800;
  justify-content: center;
  min-width: 104px;
  padding: 5px 9px;
}

.status-badge.matched {
  background: #dfeee4;
  color: #1f6f36;
}

.status-badge.open {
  background: #f4e4df;
  color: #8c2f24;
}

.status-badge.accepted {
  background: #dfeee4;
  color: #1f6f36;
}

.status-badge.rejected {
  background: #eceff2;
  color: #5d6a75;
}

.status-badge.parent {
  background: #eceff2;
  color: #5d6a75;
}

.status-badge.ignored {
  background: #eceff2;
  color: #5d6a75;
}

.isr-row.isr-open td {
  background: #fffaf8;
}

@media (min-width: 1980px) {
  #routeMatrixView {
    margin-left: -302px;
    width: 1884px;
  }
}

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

.empty {
  color: var(--muted);
  padding: 18px;
}

.note {
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  background: #182027;
  border-radius: 999px;
  bottom: 18px;
  box-shadow: 0 10px 28px rgba(24, 32, 39, 0.18);
  color: #fff;
  font-size: 0.9rem;
  left: 50%;
  max-width: min(560px, calc(100vw - 32px));
  overflow: hidden;
  padding: 10px 14px;
  position: fixed;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 10;
}

.toast.error {
  background: #8c2f24;
}

@media (max-width: 880px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .brand-logo {
    height: 50px;
    width: 50px;
  }

  .summary-grid,
  .form-panel,
  .admin-grid,
  .field-grid,
  .field-grid.two {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
