:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-quiet: #eef3ed;
  --text: #142018;
  --muted: #667268;
  --line: #dce3dc;
  --accent: #147a54;
  --accent-soft: #dff0e8;
  --warn: #b42318;
  --shadow: 0 18px 40px rgba(30, 46, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(247, 248, 245, 0.96)),
    repeating-linear-gradient(90deg, rgba(20, 122, 84, 0.05) 0, rgba(20, 122, 84, 0.05) 1px, transparent 1px, transparent 72px);
}

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

button {
  border: 0;
}

.shell,
.admin-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  text-decoration: none;
}

.date-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 122, 84, 0.14);
}

textarea {
  min-height: 92px;
  padding-top: 10px;
  resize: vertical;
}

.search-band {
  padding: 28px 0 26px;
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(280px, 1fr);
  gap: 22px;
  align-items: end;
  position: relative;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 560px;
  margin-bottom: 0;
  font-size: 42px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 22px;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.muted {
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
}

.search-row input {
  height: 56px;
  font-size: 18px;
}

.icon-btn,
.text-btn,
.primary-action {
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn {
  display: grid;
  place-items: center;
  color: var(--surface);
  background: var(--accent);
}

.mic-icon {
  width: 23px;
  height: 23px;
  fill: currentColor;
}

.icon-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.voice-status {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.text-btn {
  padding: 0 14px;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 800;
}

.primary-action {
  padding: 0 16px;
  color: var(--surface);
  background: var(--accent);
  font-weight: 800;
}

.primary-action:disabled {
  opacity: 0.5;
  cursor: default;
}

.search-results {
  position: absolute;
  right: 0;
  bottom: -172px;
  z-index: 4;
  width: min(560px, 100%);
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-results button {
  width: 100%;
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: 220px minmax(260px, 340px) 1fr;
  gap: 14px;
  align-items: start;
}

.route-panel,
.stop-panel,
.timetable-panel,
.admin-section {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.route-panel,
.stop-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.timetable-panel {
  min-height: 520px;
  padding: 18px;
}

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

.panel-head h2 {
  margin: 0;
}

.route-list,
.stop-list {
  display: grid;
  gap: 2px;
  padding: 8px;
}

.route-item,
.stop-item,
.version-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.route-item strong {
  font-size: 22px;
}

.route-item span,
.stop-item small,
.version-item span,
.version-item small {
  color: var(--muted);
  font-size: 13px;
}

.route-item.active,
.stop-item.active,
.version-item:hover,
.route-item:hover,
.stop-item:hover {
  background: var(--accent-soft);
}

.stop-search {
  width: calc(100% - 16px);
  margin: 8px;
}

.variant-field {
  display: grid;
  gap: 6px;
  margin: 8px;
  color: var(--muted);
  font-size: 13px;
}

.variant-field select {
  width: 100%;
}

.route-notices {
  display: grid;
  gap: 8px;
  margin: 8px;
}

.route-notice {
  padding: 12px;
  border: 1px solid #f0b8b8;
  border-radius: 8px;
  color: #7c1d1d;
  background: #fff5f5;
}

.route-notice strong {
  display: block;
  margin-bottom: 5px;
  color: #9b1c1c;
}

.route-notice p {
  margin-bottom: 6px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.route-notice small {
  color: #8f4a4a;
}

.selected-stop-bar {
  display: none;
}

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

.empty-state {
  display: grid;
  align-content: center;
  min-height: 260px;
}

.empty-state.error {
  color: var(--warn);
}

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

.next-block,
.full-day {
  padding-top: 18px;
}

.dest-filter {
  padding: 14px 0 2px;
  border-bottom: 1px solid var(--line);
}

.dest-filter > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.dest-filter-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dest-filter-chip {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  font-weight: 900;
  cursor: pointer;
}

.dest-filter-chip.active {
  color: var(--surface);
  background: var(--accent);
  border-color: var(--accent);
}

.line-status-legend {
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1px solid #f0b8b8;
  border-radius: 10px;
  color: #7c1d1d;
  background: #fff5f5;
  font-size: 14px;
  line-height: 1.35;
}

.line-status-legend strong {
  color: #c62828;
}

.upcoming-row {
  display: grid;
  grid-template-columns: 96px minmax(86px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.next-day-note {
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-quiet);
}

.upcoming-row strong {
  color: var(--accent);
  font-size: 32px;
  line-height: 1;
}

.upcoming-row.unavailable strong,
.day-time-row.unavailable strong {
  color: #c62828;
}

.upcoming-row.unavailable,
.day-time-row.unavailable {
  background: linear-gradient(90deg, rgba(198, 40, 40, 0.08), rgba(198, 40, 40, 0));
}

.upcoming-row.unavailable span {
  color: #8f1d1d;
  font-weight: 800;
}

.day-time-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
}

.day-time-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.day-time-row strong {
  color: var(--accent);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.dest-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.day-time-row .dest-tags {
  justify-content: flex-start;
}

.dest-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 10px 5px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  background: var(--surface-quiet);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.dest-tag::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7);
}

.dest-tag.cherem {
  color: #0d5f45;
  background: #dff4e9;
  border-color: #99d8bd;
}

.dest-tag.station {
  color: #1551a3;
  background: #e3eefc;
  border-color: #a9c8f4;
}

.dest-tag.utyat {
  color: #8a4d00;
  background: #fff0cc;
  border-color: #f2cb76;
}

.dest-tag.other {
  color: #4b5563;
  background: #eef1f3;
  border-color: #d4d9de;
}

.path-tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid #c7d6ca;
  border-radius: 999px;
  color: #31533d;
  background: #edf7ef;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.admin-badge {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 800;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 14px;
}

.admin-section {
  padding: 16px;
}

.admin-section .panel-head {
  padding: 0 0 12px;
  margin-bottom: 12px;
}

.admin-section.wide {
  grid-column: 1 / -1;
}

.import-form,
.version-filter-form,
.override-form,
.notice-form,
.smart-form,
.smart-upload-form,
.export-form,
.period-form,
.compare-form {
  display: grid;
  gap: 12px;
}

.import-form label,
.version-filter-form label,
.notice-form label,
.smart-form label,
.smart-upload-form label,
.export-form label,
.period-form label,
.compare-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.version-filter-form {
  grid-template-columns: minmax(150px, 1fr) auto auto;
  align-items: end;
  margin-bottom: 12px;
}

.notice-form {
  grid-template-columns: 140px minmax(220px, 1fr) 160px 160px minmax(150px, auto) auto;
  align-items: end;
}

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

.smart-form {
  grid-template-columns: 160px 180px minmax(220px, 1fr) auto;
  align-items: end;
}

.export-form {
  grid-template-columns: 180px minmax(220px, 1fr) 220px minmax(260px, 1.1fr);
  align-items: end;
}

.export-form .wide-field {
  min-width: 0;
}

.period-form {
  grid-template-columns: 180px 180px auto;
  align-items: end;
  margin: 0 0 14px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line);
}

.compare-form {
  grid-template-columns: 180px minmax(220px, 1fr) auto;
  align-items: end;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.smart-upload-form {
  grid-template-columns: 180px auto auto;
  align-items: end;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.checkbox-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px !important;
}

.checkbox-row input {
  min-height: 20px;
  width: 20px;
}

.smart-result {
  margin-top: 14px;
}

.smart-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.smart-summary span,
.smart-summary strong {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.upload-progress {
  display: grid;
  gap: 10px;
}

.upload-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 800;
}

.progress-bar {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f6;
}

.progress-bar span {
  display: block;
  height: 100%;
  min-width: 2px;
  background: var(--accent);
  transition: width 0.2s ease;
}

.error-text {
  color: #9b1c1c;
  border-color: #f0b8b8 !important;
  background: #fff5f5 !important;
}

.versions-list {
  display: grid;
  gap: 6px;
}

.notices-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.notice-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.notice-item p {
  margin: 4px 0 6px;
  color: var(--text);
  line-height: 1.35;
  white-space: pre-wrap;
}

.notice-item small {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
}

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

.mapping-table th,
.mapping-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.mapping-table input[type="checkbox"] {
  min-height: 20px;
  width: 20px;
}

.mapping-table input:not([type="checkbox"]) {
  min-height: 38px;
  width: 90px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 920px) {
  .shell,
  .admin-shell {
    width: min(100% - 20px, 720px);
    padding-top: 10px;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    background: rgba(247, 248, 245, 0.92);
    backdrop-filter: blur(10px);
  }

  .search-band {
    grid-template-columns: 1fr;
    padding: 18px 0;
  }

  h1 {
    font-size: 31px;
  }

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

  .smart-form,
  .export-form,
  .notice-form,
  .period-form,
  .version-filter-form,
  .smart-upload-form,
  .compare-form {
    grid-template-columns: 1fr;
  }

  .shell.selection-mode .search-band,
  .shell.selection-mode .route-panel,
  .shell.selection-mode .stop-panel .panel-head,
  .shell.selection-mode .variant-field,
  .shell.selection-mode .stop-search,
  .shell.selection-mode .stop-list {
    display: none;
  }

  .route-panel,
  .stop-panel {
    position: static;
    max-height: none;
  }

  .shell.selection-mode .stop-panel {
    position: sticky;
    top: 64px;
    z-index: 2;
    display: block;
  }

  .shell.selection-mode .selected-stop-bar {
    display: grid;
    gap: 12px;
    padding: 14px;
  }

  .selected-stop-bar span,
  .selected-stop-bar small {
    display: block;
    color: var(--muted);
    font-size: 13px;
  }

  .selected-stop-bar strong {
    display: block;
    margin: 3px 0 2px;
    font-size: 20px;
    line-height: 1.15;
  }

  .selected-stop-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .selected-stop-actions .text-btn {
    min-height: 42px;
    padding: 0 10px;
  }

  .shell.selection-mode .timetable-panel {
    scroll-margin-top: 128px;
  }

  .route-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .route-item {
    min-height: 76px;
  }

  .route-item span {
    display: none;
  }

  .timetable-panel {
    min-height: 360px;
  }

  .timetable-head {
    display: grid;
  }

  .upcoming-row strong {
    font-size: 28px;
  }

  .upcoming-row {
    grid-template-columns: 82px 1fr;
  }

  .upcoming-row .dest-tags {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .dest-filter {
    margin: 0 -4px;
    padding-top: 12px;
  }

  .dest-filter-scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 4px 10px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .dest-filter-chip {
    flex: 0 0 auto;
    min-height: 46px;
    padding: 0 16px;
    font-size: 15px;
    scroll-snap-align: start;
  }
}

@media (max-width: 520px) {
  .topbar {
    align-items: start;
  }

  .date-switch {
    display: grid;
    gap: 4px;
  }

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

  .day-time-row {
    grid-template-columns: 82px 1fr;
    align-items: start;
    gap: 10px;
    min-height: 56px;
    padding: 11px 0;
  }

  .day-time-row strong {
    font-size: 25px;
    padding-top: 2px;
  }

  .dest-tag {
    white-space: normal;
    font-size: 12px;
    line-height: 1.1;
  }
}
