﻿:root {
  --bg: #f2f7f7;
  --bg-2: #dce9e8;
  --card: rgba(255, 255, 255, 0.86);
  --line: rgba(11, 46, 51, 0.12);
  --text: #0f2428;
  --muted: #4f6669;
  --accent: #2f9659;
  --accent-2: #d03535;
  --good: #1f9344;
  --shadow: 0 20px 40px rgba(18, 59, 64, 0.14);
  --radius: 20px;
  --page-bg: linear-gradient(135deg, #f8fafb 0%, #f8fafb 28%, #2f9e58 64%, #cc2f38 100%);
  --grid-line: rgba(17, 71, 77, 0.03);
  --hero-bg: linear-gradient(120deg, rgba(255, 255, 255, 0.96), rgba(47, 158, 88, 0.16), rgba(204, 47, 56, 0.14));
  --input-bg: rgba(255, 255, 255, 0.92);
  --drop-bg: linear-gradient(130deg, rgba(255, 255, 255, 0.9), rgba(240, 248, 242, 0.9), rgba(252, 238, 238, 0.84));
  --soft-surface: rgba(255, 255, 255, 0.76);
  --subtle-surface: rgba(255, 255, 255, 0.64);
  --btn-secondary-bg: rgba(29, 127, 119, 0.08);
  --btn-secondary-bg-hover: rgba(29, 127, 119, 0.15);
  --btn-secondary-text: #185d56;
  --canvas-bg: linear-gradient(180deg, rgba(239, 248, 247, 0.8), rgba(255, 255, 255, 0.85));
  --chart-grid: rgba(15, 36, 40, 0.26);
  --chart-axis: #1f3134;
  --chart-elev-fill-top: rgba(29, 127, 119, 0.38);
  --chart-elev-fill-bottom: rgba(29, 127, 119, 0.08);
  --chart-elev-line: rgba(21, 108, 99, 0.88);
  --chart-pace-line: rgba(240, 137, 75, 0.96);
  --chart-legend-elev: #0f3b36;
  --chart-legend-pace: #a84f1f;
  --chart-hover-line: rgba(13, 39, 43, 0.45);
  --chart-marker-elev: #156b63;
  --chart-marker-pace: #d6692d;
  --chart-tooltip-bg: rgba(245, 251, 250, 0.95);
  --chart-tooltip-border: rgba(15, 36, 40, 0.25);
  --chart-tooltip-text: #0f2428;
  --accent-soft: rgba(29, 127, 119, 0.18);
  --accent-soft-hover: rgba(29, 127, 119, 0.12);
  --accent-focus: rgba(29, 127, 119, 0.18);
  --accent-border: rgba(28, 128, 118, 0.58);
  --drop-border: rgba(28, 128, 118, 0.5);
  --btn-primary-end: #c7353e;
  --sidebar-bg: linear-gradient(170deg, rgba(255, 255, 255, 0.96), rgba(241, 249, 243, 0.94), rgba(252, 238, 238, 0.9));
  --sidebar-border: rgba(11, 46, 51, 0.12);
  --kpi-card-bg: #ffffff;
  --kpi-card-line: rgba(11, 46, 51, 0.1);
  --kpi-card-label: #66748d;
  --kpi-card-text: #162239;
  --map-panel-bg: var(--card);
}

body[data-theme="dark"] {
  --card: rgba(14, 23, 45, 0.78);
  --line: rgba(157, 178, 225, 0.2);
  --text: #dbe5ff;
  --muted: #95a6cc;
  --accent: #4fb871;
  --accent-2: #e86a74;
  --good: #7bd09e;
  --shadow: 0 20px 44px rgba(2, 8, 26, 0.58);
  --page-bg: linear-gradient(135deg, #141b26 0%, #0f2a1b 54%, #3e1218 100%);
  --grid-line: rgba(127, 149, 202, 0.08);
  --hero-bg: linear-gradient(120deg, rgba(23, 33, 50, 0.94), rgba(23, 52, 34, 0.9), rgba(72, 24, 30, 0.84));
  --input-bg: rgba(53, 70, 105, 0.65);
  --drop-bg: linear-gradient(130deg, rgba(41, 53, 72, 0.9), rgba(28, 62, 40, 0.86), rgba(68, 27, 34, 0.82));
  --soft-surface: rgba(24, 39, 69, 0.9);
  --subtle-surface: rgba(20, 32, 62, 0.85);
  --btn-secondary-bg: rgba(76, 139, 255, 0.16);
  --btn-secondary-bg-hover: rgba(76, 139, 255, 0.28);
  --btn-secondary-text: #c6d8ff;
  --canvas-bg: linear-gradient(180deg, rgba(23, 38, 69, 0.88), rgba(14, 26, 54, 0.92));
  --chart-grid: rgba(174, 196, 244, 0.16);
  --chart-axis: #bad0ff;
  --chart-elev-fill-top: rgba(71, 154, 255, 0.3);
  --chart-elev-fill-bottom: rgba(71, 154, 255, 0.06);
  --chart-elev-line: rgba(116, 186, 255, 0.9);
  --chart-pace-line: rgba(255, 169, 109, 0.95);
  --chart-legend-elev: #86beff;
  --chart-legend-pace: #ffc191;
  --chart-hover-line: rgba(224, 233, 255, 0.42);
  --chart-marker-elev: #8bc5ff;
  --chart-marker-pace: #ffbf8f;
  --chart-tooltip-bg: rgba(16, 28, 56, 0.96);
  --chart-tooltip-border: rgba(172, 194, 240, 0.22);
  --chart-tooltip-text: #e6eeff;
  --accent-soft: rgba(77, 139, 255, 0.24);
  --accent-soft-hover: rgba(77, 139, 255, 0.18);
  --accent-focus: rgba(77, 139, 255, 0.24);
  --accent-border: rgba(110, 162, 255, 0.62);
  --drop-border: rgba(133, 171, 244, 0.42);
  --btn-primary-end: #cf4b55;
  --sidebar-bg: linear-gradient(170deg, rgba(33, 44, 60, 0.94), rgba(21, 50, 33, 0.92), rgba(66, 22, 29, 0.9));
  --sidebar-border: rgba(153, 179, 234, 0.28);
  --kpi-card-bg: rgba(22, 35, 59, 0.9);
  --kpi-card-line: rgba(128, 161, 220, 0.36);
  --kpi-card-label: #9eb7e5;
  --kpi-card-text: #e7efff;
  --map-panel-bg: rgba(15, 26, 50, 0.82);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  font-family: "Exo 2", sans-serif;
  color: var(--text);
  line-height: 1.4;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at 40% 30%, #000 45%, transparent 85%);
  z-index: 0;
}

.app-shell {
  width: min(1560px, 98vw);
  margin: 22px auto 42px;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  grid-template-areas:
    "hero hero"
    "controls kpi"
    "controls map"
    "controls charts"
    "controls table";
  align-items: start;
  gap: 18px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.hero {
  grid-area: hero;
  padding: 20px 24px;
  background: var(--hero-bg);
}

.hero-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  line-height: 1.1;
}

.lede {
  margin: 10px 0 0;
  max-width: 72ch;
  color: var(--muted);
}

.top-toggles {
  margin-left: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.toggle-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--input-bg);
  color: var(--muted);
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
  min-width: 48px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.top-link-btn {
  text-decoration: none;
  justify-content: center;
  min-width: fit-content;
  width: fit-content;
  flex: 0 0 auto;
}

.toggle-btn.is-active {
  background: var(--accent-soft);
  color: var(--text);
}

.toggle-btn:hover {
  background: var(--accent-soft-hover);
}

.compact-toggle {
  min-width: 72px;
}

#languageToggleBtn {
  min-width: fit-content;
  width: fit-content;
  flex: 0 0 auto;
  justify-content: center;
  gap: 0;
  padding-inline: 9px;
}

.controls {
  grid-area: controls;
  padding: 22px;
  display: grid;
  gap: 18px;
  position: static;
  max-height: none;
  overflow: visible;
  background: var(--sidebar-bg);
  border-color: var(--sidebar-border);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-width: 0;
}

.control-group {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 700;
  overflow-wrap: anywhere;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--input-bg);
  color: var(--text);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

input:focus,
select:focus,
.drop-zone:focus-within,
.drop-zone.drag {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-focus);
}

.drop-zone {
  border: 1px dashed var(--drop-border);
  border-radius: 14px;
  min-height: 150px;
  padding: 18px;
  background: var(--drop-bg);
  text-align: center;
  position: relative;
  cursor: pointer;
  display: grid;
  place-content: center;
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-main {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.drop-sub,
.file-name {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.file-name {
  font-family: "JetBrains Mono", monospace;
}

.btn-primary {
  width: fit-content;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: linear-gradient(120deg, var(--accent), var(--btn-primary-end));
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
  box-shadow: 0 8px 20px rgba(24, 40, 82, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
}

.btn-secondary {
  align-self: start;
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  padding: 11px 16px;
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary:hover {
  background: var(--btn-secondary-bg-hover);
}

.status {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.error {
  color: #b13c3c;
}

.status.ok {
  color: var(--good);
}

.algo-note {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--soft-surface);
}

.algo-label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.algo-value {
  margin: 4px 0 0;
  font-weight: 800;
}

.waypoint-builder {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--subtle-surface);
  display: grid;
  gap: 12px;
  min-width: 0;
}

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

[lang="bg"] .field-hint,
[lang="bg"] .waypoint-head p,
[lang="bg"] .charts-head p,
[lang="bg"] .map-head p,
[lang="bg"] .table-head p,
[lang="bg"] .lede {
  line-height: 1.35;
}

[lang="bg"] .field-hint,
[lang="bg"] .waypoint-head p {
  font-size: 0.78rem;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.slider-row output {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.84rem;
  color: var(--text);
  min-width: 44px;
  text-align: right;
}

.waypoint-head h2 {
  margin: 0;
  font-size: 1rem;
}

.waypoint-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.waypoint-inputs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-width: 0;
}

.waypoint-inputs .btn-secondary {
  width: 100%;
}

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

.kpi {
  padding: 16px;
  background: var(--kpi-card-bg);
  border-color: var(--kpi-card-line);
  box-shadow: none;
  color: var(--kpi-card-text);
  min-width: 0;
}

.kpi-label {
  margin: 0;
  color: var(--kpi-card-label);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  margin: 8px 0 0;
  font-size: clamp(1rem, 1.25vw + 0.3rem, 1.7rem);
  font-weight: 800;
  color: var(--kpi-card-text);
  line-height: 1.18;
  letter-spacing: -0.01em;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.charts,
.map-wrap,
.table-wrap {
  padding: 18px;
  min-width: 0;
}

.map-wrap {
  grid-area: map;
  background: var(--map-panel-bg);
}

.map-wrap.is-hidden {
  display: none;
}

.charts {
  grid-area: charts;
}

.table-wrap {
  grid-area: table;
  overflow: hidden;
}

.charts-head,
.map-head,
.table-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.charts-head h2,
.map-head h2,
.table-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.charts-head p,
.map-head p,
.table-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

canvas {
  margin-top: 14px;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--canvas-bg);
  cursor: crosshair;
}

.route-map {
  margin-top: 14px;
  width: 100%;
  height: 560px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.route-map.is-hidden {
  display: none;
}

.route-map .leaflet-control-attribution {
  font-size: 0.72rem;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin-top: 14px;
  border-radius: 12px;
}

.table-scroll table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.88rem;
}

.table-scroll th,
.table-scroll td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  vertical-align: top;
}

.table-scroll th {
  word-break: normal;
  overflow-wrap: normal;
}

.table-scroll th:nth-child(1),
.table-scroll td:nth-child(1),
.table-scroll th:nth-child(2),
.table-scroll td:nth-child(2) {
  width: 10.5%;
}

.table-scroll th:nth-child(3),
.table-scroll td:nth-child(3) {
  width: 8%;
}

.table-scroll th:nth-child(8),
.table-scroll td:nth-child(8),
.table-scroll th:nth-child(9),
.table-scroll td:nth-child(9) {
  width: 7%;
}

.table-scroll th:nth-child(4),
.table-scroll td:nth-child(4),
.table-scroll th:nth-child(5),
.table-scroll td:nth-child(5),
.table-scroll th:nth-child(6),
.table-scroll td:nth-child(6),
.table-scroll th:nth-child(7),
.table-scroll td:nth-child(7) {
  width: 11%;
}

.table-scroll th:nth-child(10),
.table-scroll td:nth-child(10) {
  width: 10%;
  text-align: center;
}

.table-scroll td:nth-child(10) .btn-secondary {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  line-height: 1.15;
}

.segment-row.has-stop td {
  border-bottom: 0;
}

.segment-stop-row td {
  padding: 9px 10px 11px;
  color: var(--muted);
  font-size: 0.82rem;
  background: var(--soft-surface);
  border-bottom: 1px solid var(--line);
}

.segment-stop-label-cell {
  text-align: left;
}

.segment-stop-empty {
  color: transparent;
}

.segment-stop-summary {
  display: inline-block;
  font-weight: 600;
}

.table-scroll thead th {
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

[lang="bg"] .table-scroll thead th {
  font-size: 0.69rem;
  line-height: 1.15;
  text-transform: none;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

[lang="bg"] .table-wrap {
  padding: 16px;
}

[lang="bg"] .table-head h2 {
  font-size: 1rem;
}

[lang="bg"] .table-head p {
  font-size: 0.8rem;
}

[lang="bg"] .table-scroll table {
  min-width: 1160px;
  table-layout: auto;
  font-size: 0.82rem;
}

[lang="bg"] .table-scroll th,
[lang="bg"] .table-scroll td {
  padding: 7px 5px;
}

[lang="bg"] .table-scroll th:nth-child(1),
[lang="bg"] .table-scroll td:nth-child(1),
[lang="bg"] .table-scroll th:nth-child(2),
[lang="bg"] .table-scroll td:nth-child(2) {
  width: 96px;
  min-width: 96px;
}

[lang="bg"] .table-scroll th:nth-child(3),
[lang="bg"] .table-scroll td:nth-child(3) {
  width: 84px;
  min-width: 84px;
}

[lang="bg"] .table-scroll th:nth-child(4),
[lang="bg"] .table-scroll td:nth-child(4),
[lang="bg"] .table-scroll th:nth-child(5),
[lang="bg"] .table-scroll td:nth-child(5) {
  width: 102px;
  min-width: 102px;
}

[lang="bg"] .table-scroll th:nth-child(6),
[lang="bg"] .table-scroll td:nth-child(6) {
  width: 110px;
  min-width: 110px;
}

[lang="bg"] .table-scroll th:nth-child(7),
[lang="bg"] .table-scroll td:nth-child(7) {
  width: 132px;
  min-width: 132px;
}

[lang="bg"] .table-scroll th:nth-child(8),
[lang="bg"] .table-scroll td:nth-child(8) {
  width: 116px;
  min-width: 116px;
}

[lang="bg"] .table-scroll th:nth-child(9),
[lang="bg"] .table-scroll td:nth-child(9) {
  width: 92px;
  min-width: 92px;
}

[lang="bg"] .table-scroll th:nth-child(10),
[lang="bg"] .table-scroll td:nth-child(10) {
  width: 94px;
  min-width: 94px;
}

[lang="bg"] .table-scroll thead th:nth-child(9),
[lang="bg"] .table-scroll thead th:nth-child(10) {
  font-size: 0.68rem;
}

[lang="bg"] .table-scroll thead th:nth-child(9) {
  padding-left: 3px;
  padding-right: 3px;
}

[lang="bg"] .table-scroll thead th:nth-child(10) {
  padding-left: 6px;
}

[lang="bg"] .table-scroll td:nth-child(10) .btn-secondary {
  font-size: 0.74rem;
  padding: 6px;
}

table.segments-table {
  min-width: 1080px;
}

table.segments-table th,
table.segments-table td {
  width: auto;
}

html[lang="bg"] .table-wrap {
  padding: 14px;
}

html[lang="bg"] .table-head h2 {
  font-size: 0.98rem;
}

html[lang="bg"] .table-head p {
  font-size: 0.74rem;
}

html[lang="bg"] table.segments-table {
  width: 100%;
  min-width: 1080px;
  table-layout: fixed;
  font-size: 0.82rem;
}

html[lang="bg"] table.segments-table th,
html[lang="bg"] table.segments-table td {
  padding: 6px 4px;
  width: auto !important;
  min-width: 0 !important;
}

html[lang="bg"] table.segments-table thead th {
  font-size: 0.69rem !important;
  line-height: 1.14;
  text-transform: none !important;
  letter-spacing: 0 !important;
  white-space: pre-line;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: manual;
}

html[lang="bg"] table.segments-table col.segment-col-from,
html[lang="bg"] table.segments-table col.segment-col-to {
  width: 72px;
}

html[lang="bg"] table.segments-table col.segment-col-segment-km {
  width: 82px;
}

html[lang="bg"] table.segments-table col.segment-col-segment-time {
  width: 108px;
}

html[lang="bg"] table.segments-table col.segment-col-required-pace {
  width: 98px;
}

html[lang="bg"] table.segments-table col.segment-col-avg-pace {
  width: 126px;
}

html[lang="bg"] table.segments-table col.segment-col-cumulative-time {
  width: 106px;
}

html[lang="bg"] table.segments-table col.segment-col-uphill,
html[lang="bg"] table.segments-table col.segment-col-downhill {
  width: 80px;
}

html[lang="bg"] table.segments-table col.segment-col-action {
  width: 84px;
}

html[lang="bg"] table.segments-table td:nth-child(10) .btn-secondary {
  width: auto;
  min-width: 72px;
  font-size: 0.74rem;
  padding: 5px 8px;
  white-space: nowrap;
}

html[lang="bg"] .segment-stop-row td {
  font-size: 0.8rem;
  line-height: 1.25;
}

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

@media (max-width: 1180px) {
  .app-shell {
    width: min(1100px, 96vw);
    grid-template-columns: 1fr;
    grid-template-areas:
      "hero"
      "controls"
      "kpi"
      "map"
      "charts"
      "table";
  }

  .controls {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .route-map {
    height: 460px;
  }
}

@media (max-width: 920px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(1100px, 96vw);
    margin-top: 16px;
    gap: 12px;
  }

  .hero,
  .controls,
  .charts,
  .map-wrap,
  .table-wrap {
    padding: 14px;
  }

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

  .hero-head {
    flex-direction: column;
  }

  .top-toggles {
    margin-left: 0;
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }

  .btn-primary {
    width: 100%;
  }

  .route-map {
    height: 320px;
  }
}
