/* ── Tokens ──────────────────────────────────────────────────────────────────── */
:root {
  --bg:         #F5F0E8;
  --header-bg:  #FFFFFF;
  --card:       #FFFFFF;
  --input:      #EDE8DF;
  --text:       #1A1A2E;
  --subtext:    #888888;
  --border:     #E8E3DA;
  --teal:       #0F9B8E;
  --teal-d:     #0b7d72;
  --teal-light: rgba(15,155,142,0.12);
  --shadow:     0 2px 12px rgba(26,26,46,0.08);
  --tab-h:      56px;
  --header-h:   60px;
  --banner-h:   0px;
}

[data-theme="dark"] {
  --bg:         #111318;
  --header-bg:  #1C1F28;
  --card:       #1C1F28;
  --input:      #252836;
  --text:       #F0EDE6;
  --subtext:    #8A8A9A;
  --border:     #2A2D3A;
  --shadow:     0 2px 12px rgba(0,0,0,0.3);
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 1px 0 var(--border);
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.header-logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

.header-logo span {
  font-family: 'Oswald', sans-serif;
  font-size: 20px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.3px;
}

.theme-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 6px;
  border-radius: 8px;
  line-height: 1;
  transition: background 0.15s;
}

.theme-btn:hover { background: var(--input); }

/* ── App Banner ──────────────────────────────────────────────────────────────── */
.app-banner {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  background: var(--teal);
  z-index: 98;
  box-shadow: 0 2px 8px rgba(15,155,142,0.3);
}

.app-banner-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-banner-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.app-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.app-banner-title {
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-banner-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.75);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-banner-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  background: none;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.8);
  border-radius: 20px;
  font-family: 'Lato', sans-serif;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.app-banner-btn:hover { background: rgba(255,255,255,0.15); border-color: #fff; }

.app-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  padding: 4px 6px;
  flex-shrink: 0;
  line-height: 1;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.app-banner-close:hover { color: #fff; background: rgba(255,255,255,0.15); }

/* ── Tab Nav ─────────────────────────────────────────────────────────────────── */
.tab-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 99;
  box-shadow: 0 -1px 0 var(--border);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--subtext);
  font-family: 'Lato', sans-serif;
  font-size: 10px;
  font-weight: 700;
  padding: 6px 4px;
  border-top: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--teal);
  border-top-color: var(--teal);
}

.tab-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.tab-label { font-size: 10px; }

/* ── Main ────────────────────────────────────────────────────────────────────── */
.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--header-h) + var(--banner-h) + 24px) 16px calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

.tab-section { display: none; }
.tab-section.active { display: block; }

/* ── Section Header ──────────────────────────────────────────────────────────── */
.section-header { margin-bottom: 16px; }

.section-header h2 {
  font-family: 'Oswald', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.section-sub {
  font-size: 13px;
  color: var(--subtext);
  font-weight: 500;
  line-height: 1.5;
}

/* ── Card ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ── Field Group ─────────────────────────────────────────────────────────────── */
.field-group { margin-bottom: 16px; }
.field-group:last-of-type { margin-bottom: 0; }

.field-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--subtext);
  margin-bottom: 8px;
}

.field-select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--input);
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-family: 'Lato', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  transition: border-color 0.15s;
}

.field-select:focus { border-color: var(--teal); }

.field-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  background: var(--input);
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-family: 'Lato', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.field-input:focus { border-color: var(--teal); }
.field-input::placeholder { color: var(--subtext); }

/* ── Time Row ────────────────────────────────────────────────────────────────── */
.time-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-input {
  flex: 1;
  height: 48px;
  background: var(--input);
  border: 1.5px solid transparent;
  border-radius: 12px;
  font-family: 'Lato', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
  -moz-appearance: textfield;
}

.time-input::-webkit-outer-spin-button,
.time-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.time-input:focus { border-color: var(--teal); }
.time-input::placeholder { color: var(--subtext); font-size: 14px; font-weight: 600; }

.time-sep {
  font-size: 20px;
  font-weight: 800;
  color: var(--subtext);
  flex-shrink: 0;
}

/* ── Inline Toggle ───────────────────────────────────────────────────────────── */
.inline-toggle {
  display: inline-flex;
  background: var(--input);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
  margin-left: auto;
}

.unit-pill {
  padding: 3px 10px;
  border: none;
  border-radius: 16px;
  font-family: 'Lato', sans-serif;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  background: none;
  color: var(--subtext);
  transition: background 0.15s, color 0.15s;
}

.unit-pill.active {
  background: var(--teal);
  color: #fff;
}

/* ── Pill Row ────────────────────────────────────────────────────────────────── */
.pill-row {
  display: inline-flex;
  background: var(--input);
  border-radius: 24px;
  padding: 4px;
  gap: 3px;
  margin-bottom: 16px;
}

.pill-btn {
  padding: 7px 18px;
  border: none;
  border-radius: 20px;
  font-family: 'Lato', sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  background: none;
  color: var(--subtext);
  transition: background 0.15s, color 0.15s;
}

.pill-btn.active {
  background: var(--teal);
  color: #fff;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 25px;
  font-family: 'Lato', sans-serif;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover  { background: var(--teal-d); }
.btn-primary:active { transform: scale(0.98); }

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  background: none;
  color: var(--teal);
  border: 1.5px solid var(--teal);
  border-radius: 25px;
  font-family: 'Lato', sans-serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-outline:hover { background: var(--teal-light); }

.btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  background: none;
  color: var(--subtext);
  border: none;
  border-radius: 25px;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
}

.btn-ghost:hover { color: var(--text); }

.btn-ghost-sm {
  padding: 6px 14px;
  background: var(--input);
  color: var(--subtext);
  border: none;
  border-radius: 20px;
  font-family: 'Lato', sans-serif;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-ghost-sm:hover { background: var(--border); }

.full-width { width: 100%; }
.mt-4  { margin-top: 4px;  }
.mt-8  { margin-top: 8px;  }
.mt-16 { margin-top: 16px; }

/* ── Pace Table ──────────────────────────────────────────────────────────────── */
.table-card { padding: 0; overflow: hidden; }

.pace-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pace-table thead tr {
  background: var(--text);
}

.pace-table th {
  padding: 10px 8px;
  color: rgba(255,255,255,0.85);
  font-weight: 700;
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.3px;
}

.pace-table td {
  padding: 9px 8px;
  text-align: center;
  color: var(--text);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.pace-table tbody tr:last-child td { border-bottom: none; }
.pace-table tbody tr:nth-child(even) td { background: var(--input); }

.pace-cell {
  color: var(--teal) !important;
  font-weight: 800 !important;
}

/* ── Results ─────────────────────────────────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.results-label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--subtext);
}

.result-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.result-card.highlight {
  border-color: var(--teal);
  background: var(--teal-light);
}

.result-dist {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
}

.result-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  background: var(--teal-light);
  color: var(--teal);
  border-radius: 10px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.result-right { text-align: right; }

.result-time {
  font-family: 'Oswald', sans-serif;
  font-size: 22px;
  font-weight: 900;
  color: var(--teal);
  line-height: 1;
}

.result-pace-text {
  font-size: 11px;
  color: var(--subtext);
  font-weight: 600;
  margin-top: 2px;
}

/* ── Zone Cards ──────────────────────────────────────────────────────────────── */
.zone-card {
  display: flex;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.zone-bar {
  width: 5px;
  flex-shrink: 0;
}

.zone-body {
  padding: 12px 14px;
  flex: 1;
}

.zone-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
}

.zone-range {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}

.zone-desc {
  font-size: 11px;
  color: var(--subtext);
  font-weight: 500;
}

/* ── History ─────────────────────────────────────────────────────────────────── */
.history-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.history-card:hover { border-color: var(--teal); }
.history-card:active { transform: scale(0.98); }

.history-dist {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 2px;
}

.history-date {
  font-size: 11px;
  color: var(--subtext);
  font-weight: 600;
}

.history-right { text-align: right; }

.history-time {
  font-family: 'Oswald', sans-serif;
  font-size: 20px;
  font-weight: 900;
  color: var(--teal);
  line-height: 1;
  margin-bottom: 2px;
}

.history-pace {
  font-size: 11px;
  color: var(--subtext);
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--subtext);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.6;
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal-sheet {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 0 0 32px;
}

.modal-sm {
  border-radius: 20px;
  margin: 0 16px 32px;
  padding: 24px 20px;
  max-height: none;
}

.modal-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
}

.modal-title {
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 900;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--subtext);
  padding: 4px 8px;
}

.splits-body { padding: 0 20px; }

.splits-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.splits-total {
  font-family: 'Oswald', sans-serif;
  font-size: 28px;
  font-weight: 900;
  color: var(--text);
}

.splits-pace {
  font-size: 14px;
  font-weight: 700;
  color: var(--teal);
}

.splits-table { margin-top: 4px; }

.splits-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.splits-row:last-child { border-bottom: none; }

.splits-row.header {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--subtext);
  padding-top: 12px;
}

.splits-row span:last-child { text-align: right; }
.splits-row span:nth-child(2) { text-align: center; }

.error-msg {
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 16px;
  text-align: center;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .tab-label { font-size: 9px; }
  .tab-icon  { width: 18px; height: 18px; }
  .app-main  { padding-left: 12px; padding-right: 12px; }
  .section-header h2 { font-size: 22px; }
  .time-input { font-size: 16px; }
  .result-time { font-size: 18px; }
}
