:root {
  --bg: #020617;
  --panel: rgba(15, 23, 42, 0.94);
  --panel-strong: #0f172a;
  --panel-soft: rgba(30, 41, 59, 0.78);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: rgba(148, 163, 184, 0.45);
  --orange: #f97316;
  --orange-dark: #ea580c;
  --cyan: #38bdf8;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #facc15;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
}

body {
  min-width: 320px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

button,
.file-button {
  touch-action: manipulation;
}

header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 1000;
  color: var(--text);
  background: rgba(2, 6, 23, 0.97);
  border-bottom: 1px solid #1e293b;
  backdrop-filter: blur(12px);
}

.nav-inner {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
}

.logo {
  flex: 0 0 auto;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.nav-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1.1rem;
}

.nav-links a {
  position: relative;
  padding-bottom: 2px;
  white-space: nowrap;
}

.nav-links a::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 2px;
  background: var(--orange);
  transition: width 0.2s ease;
}

.nav-links a:hover::after,
.nav-links a[aria-current="page"]::after {
  width: 100%;
}

.tools-page,
.track-page {
  min-height: 100vh;
  padding-top: 60px;
  background:
    radial-gradient(circle at 12% 18%, rgba(249, 115, 22, 0.15), transparent 42%),
    radial-gradient(circle at 88% 82%, rgba(56, 189, 248, 0.13), transparent 42%),
    linear-gradient(to bottom, #020617, #0b1120);
}

.tools-hero {
  padding: 3rem 1.5rem 4rem;
}

.tools-inner {
  width: min(1120px, 100%);
  margin: 0 auto;
}

.tools-intro-card,
.control-panel,
.map-panel,
.data-section,
.analysis-section {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.tools-intro-card {
  padding: 2rem;
}

.tools-kicker {
  margin-bottom: 0.4rem;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.tools-intro-card h1,
.track-titlebar h1 {
  color: var(--orange);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.1;
}

.tools-intro-card > p:not(.tools-kicker),
.track-titlebar p:not(.tools-kicker) {
  max-width: 850px;
  margin-top: 0.85rem;
  color: #cbd5e1;
}

.privacy-note,
.method-note {
  margin-top: 1.2rem;
  padding: 0.9rem 1rem;
  border-left: 4px solid var(--cyan);
  border-radius: 10px;
  color: #dbeafe;
  background: rgba(14, 116, 144, 0.16);
}

.tool-catalog {
  margin-top: 2rem;
}

.tool-catalog > h2 {
  margin-bottom: 0.9rem;
  font-size: 1.15rem;
}

.tool-card {
  padding: 1.35rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.96);
}

.tool-card + .tool-card {
  margin-top: 1rem;
}

.tool-card-featured {
  border-color: rgba(249, 115, 22, 0.65);
}

.tool-card-muted {
  opacity: 0.78;
}

.tool-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.tool-icon {
  display: inline-grid;
  width: 2.6rem;
  height: 2.6rem;
  place-items: center;
  border-radius: 50%;
  color: #fff7ed;
  background: rgba(249, 115, 22, 0.2);
  font-size: 1.45rem;
}

.tool-status,
.version-badge,
.counter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.8rem;
  padding: 0.2rem 0.65rem;
  border: 1px solid rgba(34, 197, 94, 0.55);
  border-radius: 999px;
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.13);
  font-size: 0.78rem;
  font-weight: 700;
}

.tool-status.pending {
  border-color: rgba(148, 163, 184, 0.5);
  color: #cbd5e1;
  background: rgba(100, 116, 139, 0.16);
}

.tool-card h3 {
  margin-top: 0.8rem;
  color: #f8fafc;
  font-size: 1.3rem;
}

.tool-card p {
  margin-top: 0.45rem;
  color: #cbd5e1;
}

.tool-features {
  margin: 0.9rem 0 1.1rem;
  padding-left: 1.15rem;
}

.tool-features li {
  margin-bottom: 0.35rem;
  list-style: disc;
}

.primary-action,
.secondary-action,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.file-button,
.row-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-weight: 650;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.primary-action,
.primary-button {
  color: #fff;
  background: var(--orange);
}

.primary-action:hover,
.primary-button:hover {
  background: var(--orange-dark);
}

.secondary-action,
.secondary-button,
.ghost-button,
.file-button,
.row-button {
  color: var(--text);
  border-color: rgba(148, 163, 184, 0.55);
  background: #111827;
}

.secondary-action:hover,
.secondary-button:hover,
.ghost-button:hover,
.file-button:hover,
.row-button:hover {
  border-color: var(--orange);
  color: #ffedd5;
}

.danger-button {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.55);
  background: rgba(127, 29, 29, 0.4);
}

.danger-button:hover {
  background: rgba(153, 27, 27, 0.65);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.drop-zone:focus-visible {
  outline: 3px solid rgba(56, 189, 248, 0.45);
  outline-offset: 2px;
}

.whatsapp-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  color: #fff;
  background: #22c55e;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  font-weight: 650;
}

.whatsapp-btn:hover {
  background: #16a34a;
}

.track-page {
  padding: 84px 1.25rem 4rem;
}

.track-titlebar {
  width: min(1500px, 100%);
  margin: 0 auto 1rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.track-titlebar h1 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.version-badge {
  min-height: 1.55rem;
  border-color: rgba(56, 189, 248, 0.5);
  color: #bae6fd;
  background: rgba(14, 116, 144, 0.16);
  font-size: 0.7rem;
}

.track-workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, 0.82fr) minmax(500px, 1.5fr);
  gap: 1rem;
  align-items: start;
}

.track-controls {
  display: grid;
  gap: 1rem;
}

.control-panel,
.map-panel,
.data-section,
.analysis-section {
  padding: 1.1rem;
}

.section-heading,
.map-heading,
.data-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading > div:first-child,
.map-heading > div:first-child {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.section-number {
  display: inline-grid;
  width: 1.9rem;
  height: 1.9rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #fff7ed;
  background: rgba(249, 115, 22, 0.24);
  font-size: 0.82rem;
  font-weight: 800;
}

.section-heading h2,
.map-heading h2 {
  font-size: 1.05rem;
}

.counter-badge {
  border-color: rgba(249, 115, 22, 0.5);
  color: #fed7aa;
  background: rgba(249, 115, 22, 0.12);
}

.input-tabs {
  margin-top: 1rem;
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.tab-button {
  margin-bottom: -1px;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.tab-button.active {
  color: #fff7ed;
  border-color: var(--border);
  border-bottom-color: var(--panel-strong);
  background: var(--panel-strong);
}

.tab-panel {
  padding-top: 0.9rem;
}

.tab-panel label,
.manual-grid label,
.threshold-field {
  display: block;
  color: #e2e8f0;
  font-size: 0.88rem;
  font-weight: 650;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.62rem 0.7rem;
  border: 1px solid #475569;
  border-radius: 10px;
  color: var(--text);
  background: #020617;
}

textarea {
  resize: vertical;
}

.native-date-wrap {
  display: flex;
  width: 100%;
  min-width: 0;
  margin-top: 0.3rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid #475569;
  border-radius: 10px;
  background: #020617;
}

.native-date-wrap input {
  display: block;
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  color: var(--text);
  background: transparent;
}

.field-help,
.map-help,
.privacy-footnote {
  color: var(--muted);
  font-size: 0.8rem;
}

.field-help {
  margin-top: 0.4rem;
}

.button-row {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.compact-actions {
  margin-top: 0;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.drop-zone {
  margin-top: 0.8rem;
  padding: 0.8rem;
  border: 1px dashed rgba(148, 163, 184, 0.65);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  background: rgba(2, 6, 23, 0.45);
}

.drop-zone.drag-over {
  border-color: var(--cyan);
  color: #bae6fd;
  background: rgba(14, 116, 144, 0.16);
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.manual-comment {
  grid-column: 1 / -1;
}

.status-message {
  min-height: 1.4rem;
  margin-top: 0.65rem;
  color: #bae6fd;
  font-size: 0.84rem;
}

.status-message.error {
  color: #fecaca;
}

.status-message.success {
  color: #bbf7d0;
}

.option-grid {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  color: #dbeafe;
  font-size: 0.86rem;
}

.check-row input {
  margin-top: 0.2rem;
  accent-color: var(--orange);
}

.threshold-field {
  margin-top: 0.9rem;
}

.threshold-field > span {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.threshold-field input {
  width: 110px;
  margin-top: 0;
}

.map-panel {
  min-width: 0;
}

.map-help {
  text-align: right;
}

#map {
  position: relative;
  height: 690px;
  margin-top: 0.8rem;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 16px;
  background: #0f172a;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.privacy-footnote {
  margin-top: 0.55rem;
}

.data-section,
.analysis-section {
  width: min(1500px, 100%);
  margin: 1rem auto 0;
}

.table-scroll {
  margin-top: 0.85rem;
  overflow-x: auto;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
}

.records-table,
.segments-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.records-table {
  min-width: 1320px;
}

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

.records-table th,
.records-table td,
.segments-table th,
.segments-table td {
  padding: 0.55rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
  text-align: left;
  vertical-align: top;
}

.records-table th,
.segments-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #e2e8f0;
  background: #111827;
  white-space: nowrap;
}

.records-table tbody tr:hover,
.records-table tbody tr.selected {
  background: rgba(56, 189, 248, 0.08);
}

.records-table tbody tr.invalid-row {
  background: rgba(127, 29, 29, 0.2);
}

.records-table input[type="text"],
.records-table input[type="number"],
.records-table select,
.records-table textarea {
  min-width: 105px;
  margin: 0;
  padding: 0.42rem 0.48rem;
  border-radius: 7px;
  font-size: 0.8rem;
}

.records-table textarea {
  min-width: 190px;
  min-height: 58px;
}

.records-table .name-input {
  min-width: 150px;
}

.records-table .date-input,
.records-table .time-input {
  min-width: 115px;
}

.route-check {
  width: 18px;
  height: 18px;
  accent-color: var(--orange);
}

.row-actions {
  display: flex;
  gap: 0.35rem;
}

.row-button {
  min-height: 32px;
  padding: 0.35rem 0.65rem;
  font-size: 0.76rem;
}

.row-button.delete {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.4);
}

.empty-row td {
  padding: 1.2rem;
  color: var(--muted);
  text-align: center;
}

.metrics-grid {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.7rem;
}

.metric-card {
  padding: 0.8rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.55);
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.metric-card strong {
  display: block;
  margin-top: 0.25rem;
  color: #f8fafc;
  font-size: 1.15rem;
}

.findings-box {
  margin-top: 0.85rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  color: #dbeafe;
  background: rgba(2, 6, 23, 0.5);
}

.findings-box ul {
  padding-left: 1.15rem;
}

.findings-box li {
  margin-bottom: 0.35rem;
  list-style: disc;
}

.findings-box .warning {
  color: #fde68a;
}

.method-note {
  margin-top: 0.9rem;
  font-size: 0.86rem;
}

.notice {
  width: min(1500px, 100%);
  margin: 0 auto 1rem;
  padding: 0.8rem 1rem;
  border-radius: 10px;
}

.notice-error {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.5);
}

.track-marker {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 15%;
  color: #fff;
  background: #f97316;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  transform: rotate(-45deg);
  font-size: 15px;
  font-weight: 800;
}

.track-marker > span {
  transform: rotate(45deg);
}

.track-marker.symbol-cross,
.track-marker.symbol-error,
.track-marker.symbol-impact {
  background: #dc2626;
}

.track-marker.symbol-start {
  background: #16a34a;
}

.track-marker.symbol-end {
  background: #7c3aed;
}

.track-marker.symbol-stop,
.track-marker.symbol-warning {
  background: #ca8a04;
}

.track-marker.symbol-car {
  background: #2563eb;
}

.track-marker.symbol-camera {
  background: #0f766e;
}

.direction-arrow {
  color: #0f172a;
  filter: drop-shadow(0 0 2px #fff);
  font-size: 23px;
  font-weight: 900;
  line-height: 1;
  transform-origin: center;
}

.leaflet-tooltip.track-tooltip {
  border: 1px solid rgba(15, 23, 42, 0.45);
  color: #0f172a;
  background: rgba(255, 255, 255, 0.92);
  font-weight: 700;
}

.popup-content {
  min-width: 190px;
  color: #0f172a;
}

.popup-content h3 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
}

.popup-content dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.5rem;
  font-size: 0.82rem;
}

.popup-content dt {
  font-weight: 700;
}

.popup-content dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .track-workspace {
    grid-template-columns: 1fr;
  }

  #map {
    height: 560px;
  }

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

@media (max-width: 800px) {
  .nav-links {
    display: none;
  }

  .track-page {
    padding-inline: 0.75rem;
  }

  .track-titlebar,
  .data-heading,
  .map-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-help {
    text-align: left;
  }

  .manual-grid,
  .option-grid,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  #map {
    height: 460px;
  }

  .whatsapp-btn {
    right: 16px;
    bottom: 16px;
  }
}

@media print {
  header,
  .track-controls,
  .button-row,
  .secondary-action,
  .privacy-footnote,
  .whatsapp-btn,
  .mobile-menu-btn,
  .mobile-menu-panel {
    display: none !important;
  }

  body,
  .track-page {
    color: #111827;
    background: #fff;
  }

  .track-page {
    padding: 0;
  }

  .track-titlebar,
  .track-workspace,
  .data-section,
  .analysis-section {
    width: 100%;
    max-width: none;
  }

  .track-workspace {
    display: block;
  }

  .map-panel,
  .data-section,
  .analysis-section {
    margin: 0 0 1rem;
    border: 1px solid #cbd5e1;
    box-shadow: none;
    background: #fff;
    break-inside: avoid;
  }

  #map {
    height: 480px;
  }

  .table-scroll {
    overflow: visible;
  }

  .records-table,
  .segments-table {
    min-width: 0;
    font-size: 7pt;
  }

  .route-check,
  .row-actions {
    display: none;
  }

  .records-table input,
  .records-table select,
  .records-table textarea {
    border: 0;
    color: #111827;
    background: transparent;
  }
}
