/* ========== RESET STYLES ========== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100dvh;
  margin: 0;
  overflow: hidden; /* Prevent background scroll */
}

body {
  font-family: 'Inter', sans-serif;
  background-color: #f5f5f5;
  display: flex; /* Make body a flex container */
  flex-direction: column; /* Stack children (header, container, nav) vertically */
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh; /* Ensure body takes full viewport height */
}

/* ========== MAIN CONTAINER ========== */
.container {
  width: 100%;
  flex: 1; /* Allows container to take all available vertical space within body */
  max-width: 430px;
  background-color: white;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  margin: 0 auto; /* Ensures container is centered horizontally within the body */
}

/* ========== SCREEN SECTION ========== */
.screen {
  flex: 1; /* Allows screen to grow and be the scrollable area within .container */
  display: flex;
  flex-direction: column;
  padding-bottom: 130px;
  overflow-y: auto; /* Primary scroll area */
  -webkit-overflow-scrolling: touch; /* For smoother scrolling on iOS */
}

/* ========== FIXED HEADER ========== */
.header {
  background-color: #052c49;
  color: white;
  padding: 1.2rem;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  position: fixed;
  top: 0; /* Aligns to the very top */
  /* Centering for fixed elements with max-width */
  left: 0;
  right: 0;
  margin: auto;
  width: 100%; /* Takes full width up to max-width */
  max-width: 430px;
  z-index: 1000;   /* Ensures header is always on top of other content */
}

.header-spacer {
  height: 65px;
  flex-shrink: 0;
}

.nav-spacer {
  height: 100px; /* Equal to or a bit more than your .nav height */
  flex-shrink: 0;
}

/* ========== CONTENT WRAPPER ========== */
.content {
  padding: 20px;
  text-align: center;
  /* Add flex properties to allow dynamic content sections to stack */
  display: flex;
  flex-direction: column;
  align-items: center; /* Center horizontally */
}

/* ========== RECORD STATE SECTIONS ========== */
.record-state-section {
  display: flex; /* Make it a flex container */
  flex-direction: column; /* Stack children (label & toggle) vertically */
  align-items: center; /* Center content horizontally */
  /* Define a fixed height for this section to prevent layout shifts */
  height: 60px;
  justify-content: flex-start; /* Align content to the top within its fixed height */
  width: 100%;
}


.state-label-wrapper {
  position: relative;
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.label {
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  text-align: center;
  font-weight: bold;
  font-size: 18px;
  line-height: 1.2; /* Ensure consistent line spacing for wrapped text */
}

/* ========== TOGGLE SWITCH ========== */
.toggle-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 10px; /* Add some space above the toggle group */
  margin-bottom: 10px; /* Push the button-wrapper down */
}

.toggle-labels {
  display: flex;
  align-items: center;
  gap: 12px;
}

.label {
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  text-align: center;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  transition: .3s;
  border-radius: 34px;
}

.slider:before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #116A6F;
}

input:checked + .slider:before {
  transform: translateX(24px);
}

/* ========== BUTTON SECTION ========== */
.button-wrapper {
  background-color: #e6f0ef;
  padding: 30px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 100px;
  margin-bottom: 0;
  width: 100%;
}

.button-container {
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.button-container button {
  background-color: #216e68;
  color: white;
  font-size: 24px;
  padding: 22px 52px;
  border: none;
  border-radius: 14px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.25);
  width: 200px;
}

/* ========== END BUTTON ========== */
.end-button-wrapper {
  display: flex;
  justify-content: flex-end;
  padding-right: 24px;
  margin-top: 40px;
  margin-bottom: 0;
  height: 40px;
}

.end-button-wrapper button {
  background-color: #216e68;
  color: white;
  font-size: 18px;
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.25);
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.invisible {
  visibility: hidden;
}

.visible {
  visibility: visible;
}

/* ========== FIXED NAVIGATION BAR ========== */
.nav {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 70px;
  background-color: #052c49;
  color: white;
  border-top: 1px solid #ccc;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 430px; /* Matches .container's max-width */
  margin: auto; /* Centers the fixed nav on larger screens */
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 1000; /* Ensure it's above other scrolling content */
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.75rem;
  text-decoration: none;
  color: white;
}

.nav-item img {
  width: 32px;
  height: 32px;
  margin-bottom: 4px;
  filter: brightness(0) invert(1);
}

/* ========== HELP PAGE ========== */
.help-content {
  padding: 24px;
  font-size: 12px;
  line-height: 1.4;
  color: #222;
  flex-grow: 1; /* Allows content to grow within .screen */
}

.help-content strong {
  font-weight: 600;
  display: block;
  margin-top: 20px;
}

.help-content ol {
  margin-left: 20px;
  margin-bottom: 10px;
}

.help-content li {
  margin-bottom: 2px;
  line-height: 1.3;
}

.help-content .disclaimer {
  font-size: 13px;
  color: #666;
  margin-top: 24px;
}

/* ========== SEGMENT PAGE ========== */
.segment-content {
  margin-top: -20px;
  padding: 10px;
  font-size: 14px;
  color: #222;
  text-align: center;
  flex-grow: 1; /* Allows content to grow within .screen */
}

.segment-content input[type="file"] {
  margin: 12px 0;
}

.segment-content .file-label {
  margin-top: 8px;
  font-size: 13px;
  color: #555;
}

#gpxFilename {
  margin-top: -8px;
}

.segment-content .process-button,
.segment-content .download-button {
  background-color: #216e68;
  color: white;
  padding: 10px 20px;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2);
  margin: 16px 6px;
}

/* Process Button specific font size */
#processBtn {
  font-size: 20px;
}

.segment-content .process-button {
  margin-top: 30px;
  margin-bottom: 10px;
}

.segment-content .upload-txt-button {
  background-color: #216e68;
  color: white;
  padding: 6px 14px;
  font-size: 13px;
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  margin-top: -5px;
  margin-bottom: -10px;
}

.upload-txt-wrapper {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.upload-section,
#recordingSection {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: -5px;
}

.segment-map-preview {
  width: 100%;
  height: 200px;
  background-color: #ddd;
  border-radius: 12px;
}

.download-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  align-items: center;
}

.download-button {
  background-color: #216e68;
  color: white;
  padding: 6px 10px;
  font-size: 10px;
  border: none;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
  width: auto;
  min-width: 90px;
  display: flex;
  justify-content: center; /* Horizontally center text within the button */
  align-items: center;
}