/* App-specific styles for Pacemaker.
   Design tokens and reusable components live in design-system.css. */


/* ── Base ────────────────────────────────────────────────────────────────── */

html, body {
  margin: 0;
  width: 100%;
  overflow-x: clip;
}

body {
  display: grid;
  justify-items: center;
  padding: 16px;
  background: var(--color-bg);
}

/* Labels are italic by default; override per component as needed */
label {
  font-style: italic;
  text-align: center;
}

label.btn-outline {
  font-style: normal;
}

input::placeholder {
  color: var(--black);
  opacity: 0.4;
}

input:focus {
  outline: none;
  color: var(--highlight);
}

input[disabled] {
  color: var(--black);
  opacity: 0.5;
  background: transparent;
}

input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}


/* ── App shell ───────────────────────────────────────────────────────────── */

.app-shell {
  width: min(1440px, 100%);
}


/* ── Header ──────────────────────────────────────────────────────────────── */

.app-header {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  position: relative;
}

.app-header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 24px;
}

.app-header h1 {
  text-align: left;
}

.app-header-subtitle {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin: 0;
}

/* Position the share/settings icons at the far right of the header */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}


/* ── Layout ──────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 370px) minmax(320px, 1fr);
  gap: 32px;
  align-items: start;
  padding-top: 16px;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(400px, 100%);
  min-width: 0;
  justify-self: center;
  align-self: start;
  padding: 0;
}

.summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  padding: 8px 8px 8px 12px;
  flex-shrink: 0;
  background: var(--color-bg);
  color: var(--color-text);
  transition: background 0.15s ease, color 0.15s ease;
}

.summary-card.is-active {
  background: var(--black);
  color: var(--color-bg);
}

.summary-card.is-active .summary-item-label {
  color: var(--color-bg);
  opacity: 0.65;
}

.summary-card.is-active .btn-icon {
  color: var(--color-bg);
}

.summary-card.is-active .btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.summary-card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.summary-empty-text {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.summary-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.summary-item-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.summary-item-value {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.summary-card #reset-all-btn {
  flex-shrink: 0;
}

.empty-state-text {
  color: var(--color-text-muted);
  text-align: center;
  padding: 32px 12px;
  margin: 0;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Looks disabled but stays clickable, so it can explain why via tooltip */
.is-dimmed {
  opacity: 0.4;
}

.details-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

@media (min-width: 761px) {
  body {
    height: 100vh;
    overflow: hidden;
  }

  .app-shell {
    height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
  }

  .layout {
    flex: 1;
    min-height: 0;
    align-items: stretch;
  }

  .controls-panel {
    align-self: stretch;
    height: 100%;
    border-right: 1px solid var(--color-divider);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 16px;
    padding-bottom: 16px;
  }

  .details-panel {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-right: 8px;
  }

  .gpx-preview {
    max-height: 260px;
  }
}


/* ── App-specific input overrides ────────────────────────────────────────── */

/* Per-segment text alignment inside the split input boxes */
.input-box--split #time-hours   { text-align: right !important; }
.input-box--split #time-minutes { text-align: center !important; }
.input-box--split #time-seconds { text-align: left !important; }
.input-box--split #pace-minutes { text-align: right !important; }
.input-box--split #pace-seconds { text-align: left !important; }
#distance { text-align: center !important; }

/* The grade input column stretches its mini-wrap to full height */
.setting-col--auto .input-mini-wrap {
  flex: 1;
  align-items: center;
}

/* Split direction button group fills the column width */
.split-direction-group {
  flex: 1;
}


/* ── GPX file + stats container ──────────────────────────────────────────── */

.gpx-file-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  padding: 12px;
}

/* Larger upload button inside the dropzone */
.dropzone .btn-outline {
  padding: 10px 20px;
  font-size: 1rem;
}


/* ── GPX canvas preview ──────────────────────────────────────────────────── */

.gpx-preview {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 180px;
  border: 1px solid var(--color-border-strong);
  background:
    linear-gradient(var(--color-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--color-grid) 1px, transparent 1px);
  background-size: 24px 24px;
  overflow: hidden;
}

.gpx-preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.gpx-preview.is-3d     { cursor: grab; }
.gpx-preview.is-3d.dragging { cursor: grabbing; }

.preview-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}



/* ── Split distribution slider ───────────────────────────────────────────── */

.distribution-control {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.distribution-label {
  font-size: 0.95rem;
  font-weight: 600;
}

.split-controls {
  display: none;
  gap: 12px;
  align-items: center;
  margin-bottom: 4px;
}

.split-controls.visible {
  display: flex;
}

.split-label,
.distribution-label,
.split-even-label {
  color: var(--color-text-secondary);
}

.split-label {
  flex: 0 0 64px;
  color: var(--black);
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  opacity: 0.45;
}

.split-slider-wrap {
  flex: 1;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.split-slider {
  width: 100%;
  height: 24px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.split-slider:focus { outline: none; }

.split-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--black);
}

.split-slider::-webkit-slider-thumb {
  width: 8px;
  height: 24px;
  margin-top: -11px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--black);
  border: none;
  border-radius: 0;
}

.split-slider::-moz-range-track {
  height: 2px;
  background: var(--black);
}

.split-slider::-moz-range-thumb {
  width: 8px;
  height: 24px;
  background: var(--black);
  border: none;
  border-radius: 0;
}

.split-even-label {
  justify-self: center;
  color: var(--black);
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.45;
}


/* ── Splits table ────────────────────────────────────────────────────────── */

.table-section {
  min-width: 0;
}

.table-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.table-section-header .section-title {
  margin: 0;
}

.table-section-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.controls-panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--color-divider);
}

.panel-action-btn {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--color-border-strong);
  border-radius: 4px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.panel-action-btn:hover {
  background: var(--color-hover);
}

.panel-action-download {
  position: relative;
}

.panel-action-btn--download {
  width: 100%;
}

.panel-action-chevron {
  font-family: "Material Symbols Outlined";
  font-size: 18px;
  flex-shrink: 0;
}

.panel-download-menu {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.panel-download-option {
  display: block;
  width: 100%;
  padding: 13px 16px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.panel-download-option:hover {
  background: var(--color-hover);
}

.panel-download-option + .panel-download-option {
  border-top: 1px solid var(--color-border);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.splits-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--black);
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
  min-width: 0;
}

.splits-table.gpx-mode {
  min-width: 560px;
}

.splits-table.gpx-mode.track-mode {
  min-width: 0;
}

.splits-table th,
.splits-table td {
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border-strong);
  text-align: left;
}

.splits-table th {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.splits-table td {
  font-size: 1rem;
}

.splits-table.gpx-mode th,
.splits-table.gpx-mode td {
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border-strong);
  font-size: 0.9rem;
}

.splits-table.gpx-mode th {
  font-size: 0.78rem;
}

.splits-table.gpx-mode th:first-child,
.splits-table.gpx-mode td:first-child {
  width: 28px;
}

.splits-table.gpx-mode tbody tr {
  cursor: default;
}

.splits-table.gpx-mode tbody tr:hover,
.splits-table.gpx-mode tbody tr.highlighted {
  background: var(--color-hover);
}

.splits-table.gpx-mode.is-planned td:nth-child(3),
.splits-table.gpx-mode.is-planned td:nth-child(4),
.splits-table.gpx-mode.is-planned td:nth-child(5) {
  font-style: italic;
  color: var(--color-text-subtle);
}


/* ── Mobile layout ───────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  body {
    padding: 0;
    overflow-x: clip;
  }

  .app-shell {
    width: 100%;
    padding: 16px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  /* Unwrap controls-panel so its children (incl. the sticky summary card)
     become direct grid items of .layout — otherwise position:sticky is
     bounded by controls-panel's own box and can't stay stuck while
     scrolling past it into details-panel/the table below. */
  .controls-panel {
    display: contents;
  }

  .controls-panel .accordion-card:not(:last-child) {
    margin-bottom: -16px; /* collapse .layout's 28px gap down to the original 12px rhythm */
  }

  .details-panel {
    width: auto;
    max-width: 100%;
  }

  .distribution-control {
    width: auto;
    justify-content: flex-start;
    min-width: 0;
    flex-wrap: wrap;
    padding: 16px 0;
  }

  .split-controls {
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
  }

  .split-label {
    flex: none;
    width: 100%;
    text-align: left;
  }

  .split-slider-wrap {
    width: 100%;
    min-width: 0;
  }

  .table-section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .controls-panel-actions {
    display: none;
  }

  .table-section-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* 2-column stats on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .file-chip,
  .dropzone .btn-outline {
    width: 100%;
    justify-content: space-between;
    box-sizing: border-box;
  }

  .file-chip-name {
    max-width: none;
    flex: 1;
  }

  .table-wrap,
  .splits-table {
    min-width: 0;
    max-width: 100%;
  }

  .summary-card-sticky {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -16px -28px; /* horizontal bleed + cancel .layout's 28px gap entirely (the wrapper's own 12px bottom padding provides the visible gap) */
    padding: 12px 16px;
    background: color-mix(in srgb, var(--color-bg) 70%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: box-shadow 0.15s ease;
  }

  .summary-card-sticky .summary-card {
    cursor: pointer;
  }

  .summary-card-sticky.is-stuck {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 14px;
  }

  .split-controls {
    gap: 8px;
  }

  .split-label,
  .split-even-label {
    font-size: 0.72rem;
  }

  .splits-table th,
  .splits-table td {
    padding: 9px 0;
  }

  .splits-table th {
    font-size: 0.78rem;
  }

  .splits-table td {
    font-size: 0.9rem;
  }

  .details-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }
}


/* ── Mobile bottom bar ───────────────────────────────────────────────────── */

.mobile-bar {
  display: none;
}

@media (max-width: 760px) {
  .mobile-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--color-bg);
    border-top: 1px solid var(--color-divider);
    z-index: 100;
  }

  .mobile-bar-btn {
    padding: 11px 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: 4px;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    touch-action: manipulation;
  }

  .mobile-bar-btn:active {
    background: var(--color-hover);
  }

  .mobile-bar-download {
    position: relative;
  }

  .mobile-bar-btn--download {
    width: 100%;
  }

  .mobile-bar-chevron {
    font-family: "Material Symbols Outlined";
    font-size: 18px;
    flex-shrink: 0;
  }

  .mobile-download-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border-strong);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
  }

  .mobile-download-option {
    display: block;
    width: 100%;
    padding: 13px 16px;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
  }

  .mobile-download-option + .mobile-download-option {
    border-top: 1px solid var(--color-border);
  }

  .mobile-download-option:active {
    background: var(--color-hover);
  }

  #copy-table,
  #download-csv,
  #download-gpx {
    display: none;
  }

  .app-shell {
    padding-bottom: calc(60px + max(0px, env(safe-area-inset-bottom)));
  }
}
