/* ── Sports list view ────────────────────────────────────────────────────── */
.sports-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 0.5rem);
}

.btn-sm {
  padding: 0.48rem 0.82rem;
  font-size: 0.82rem;
}

.sport-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  backdrop-filter: blur(6px);
  animation: rise 420ms ease both;
  border-left: 4px solid var(--sport-color, var(--primary));
}

.sport-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.72rem 0.85rem;
  border-bottom: 1px solid rgba(165, 202, 214, 0.12);
}

.sport-card__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.sport-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}

.sport-card__title h3 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sport-card__count {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  flex-shrink: 0;
  line-height: 1.3;
}

.sport-card__actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* ── Template rows ───────────────────────────────────────────────────────── */
.templates-list {
  padding: 0.5rem 0.65rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.template-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 0.55rem;
  border-radius: 11px;
  background: rgba(7, 22, 30, 0.42);
  border: 1px solid rgba(165, 202, 214, 0.1);
  transition: border-color 150ms;
}

.template-row:hover {
  border-color: rgba(165, 202, 214, 0.25);
}

.template-row__info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

.template-row__name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-row__meta {
  font-size: 0.72rem;
  color: var(--text-soft);
  white-space: nowrap;
  flex-shrink: 0;
}

.template-row__actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

.sport-no-templates {
  margin: 0;
  padding: 0.35rem 0;
  font-size: 0.82rem;
  color: var(--text-soft);
  font-style: italic;
}

/* ── Icon buttons ────────────────────────────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  border: 1px solid rgba(170, 198, 209, 0.2);
  background: rgba(170, 198, 209, 0.06);
  color: var(--text-soft);
  cursor: pointer;
  transition: color 160ms, background-color 160ms, border-color 160ms;
  flex-shrink: 0;
  padding: 0;
}

.icon-btn:hover {
  color: var(--text-main);
  background: rgba(170, 198, 209, 0.15);
}

.danger-icon-btn {
  border-color: rgba(218, 65, 65, 0.25);
  color: rgba(218, 65, 65, 0.65);
}

.danger-icon-btn:hover {
  background: rgba(218, 65, 65, 0.16);
  color: var(--danger);
  border-color: rgba(218, 65, 65, 0.5);
}

/* ── Add sport dialog — compact row ──────────────────────────────────────── */
.add-sport-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.add-sport-icon {
  width: 56px;
  text-align: center;
  font-size: 1.35rem;
  padding: 0.45rem;
  flex-shrink: 0;
}

.add-sport-name {
  flex: 1;
  min-width: 0;
}

/* ── Emoji & color grids in add sport dialog ─────────────────────────────── */
.sport-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sport-form__section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sport-form__label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-soft);
  font-weight: 600;
}

.sport-form__emoji-custom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.sport-form__emoji-input {
  width: 3rem;
  text-align: center;
  font-size: 1.2rem;
  padding: 0.35rem;
}

.sport-form__emoji-hint {
  font-size: 0.76rem;
  color: var(--text-soft);
}

.sport-form__emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.sport-form__emoji-btn {
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
  border: 2px solid transparent;
  border-radius: 10px;
  background: rgba(170, 198, 209, 0.06);
  cursor: pointer;
  transition: border-color 120ms, transform 80ms;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}
.sport-form__emoji-btn:hover { background: rgba(170, 198, 209, 0.12); }
.sport-form__emoji-btn.is-selected {
  border-color: var(--primary);
  background: rgba(24, 191, 125, 0.1);
  transform: scale(1.08);
}

.sport-form__color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sport-form__color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 120ms, transform 80ms;
  padding: 0;
}
.sport-form__color-swatch:hover { transform: scale(1.12); }
.sport-form__color-swatch.is-selected {
  border-color: #fff;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px var(--primary);
}

.sport-form__custom-color {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.sport-form__custom-color label {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.sport-form__custom-color input[type="color"] {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: transparent;
}

/* ═══════════════════════════════════════════════════════════════════════════ */
/* ── TEMPLATE EDITOR DIALOG ─────────────────────────────────────────────── */
/* ═══════════════════════════════════════════════════════════════════════════ */

.tpl-editor-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text-main);
  max-width: 100vw;
  max-height: 100dvh;
  width: 100vw;
  height: 100dvh;
}

.tpl-editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}

/* On desktop, center card */
@media (min-width: 640px) {
  .tpl-editor-dialog {
    width: min(560px, calc(100vw - 2rem));
    height: auto;
    max-height: calc(100dvh - 2rem);
    border-radius: var(--radius-lg);
    background: #0c1d24;
    border: 1px solid var(--line);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  }
}

.tpl-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #0c1d24;
}

@media (min-width: 640px) {
  .tpl-editor {
    max-height: calc(100dvh - 2rem);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }
}

/* ── Header (fixed top) ── */
.tpl-editor__head {
  flex-shrink: 0;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tpl-editor__head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.tpl-editor__head-row h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.tpl-editor__sport {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tpl-editor__name {
  width: 100%;
  font-size: 0.92rem;
  padding: 0.55rem 0.65rem;
}

/* ── Blocks header (fixed) ── */
.tpl-editor__blocks-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid rgba(165, 202, 214, 0.08);
}

.tpl-editor__blocks-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-soft);
  font-weight: 600;
}

.tpl-editor__blocks-count {
  font-size: 0.74rem;
  color: var(--accent);
  font-weight: 600;
}

.tpl-editor__add-block {
  margin-left: auto;
}

/* ── Error ── */
.tpl-editor__error {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--danger);
  margin: 0;
  padding: 0.3rem 1rem 0;
}

/* ── Blocks list (SCROLLABLE ZONE) ── */
.tpl-editor__blocks {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tpl-no-blocks {
  margin: 0;
  padding: 1.5rem 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/* ── Block row ── */
.tpl-block-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: rgba(7, 22, 30, 0.55);
  border: 1px solid rgba(165, 202, 214, 0.1);
  border-radius: 10px;
  transition: border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.tpl-block-row.is-dragging {
  opacity: 0.6;
  border-color: rgba(24, 191, 125, 0.5);
}

.tpl-block-row.is-drop-target {
  border-color: rgba(24, 191, 125, 0.6);
  box-shadow: 0 0 0 1px rgba(24, 191, 125, 0.2) inset;
}

.tpl-block-num {
  font-size: 0.7rem;
  color: var(--text-soft);
  width: 16px;
  text-align: center;
  flex-shrink: 0;
  font-weight: 600;
}

.input-field {
  background: rgba(7, 22, 30, 0.65);
  border: 1px solid rgba(165, 202, 214, 0.2);
  border-radius: 8px;
  color: var(--text-main);
  padding: 0.45rem 0.55rem;
  font-size: 0.86rem;
  font-family: inherit;
  transition: border-color 160ms;
}

.input-field:focus {
  outline: none;
  border-color: rgba(24, 191, 125, 0.5);
}

.tpl-block-name {
  flex: 1;
  min-width: 0;
}

.tpl-block-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.4rem;
}

.tpl-block-goal {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.goal-toggle-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 82px;
  height: 32px;
  padding: 0 0.7rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.goal-toggle-chip--time {
  background: rgba(24, 191, 125, 0.12);
  border-color: rgba(24, 191, 125, 0.18);
  color: var(--primary);
}

.goal-toggle-chip--distance {
  background: rgba(247, 147, 30, 0.12);
  border-color: rgba(247, 147, 30, 0.18);
  color: #ffb15b;
}

.goal-toggle-chip--interactive {
  cursor: pointer;
  transition: transform 120ms, border-color 160ms, background 160ms, color 160ms;
}

.goal-toggle-chip--interactive:hover {
  transform: translateY(-1px);
}

.goal-toggle-chip--interactive:focus-visible {
  outline: none;
  border-color: rgba(165, 202, 214, 0.38);
  box-shadow: 0 0 0 2px rgba(165, 202, 214, 0.1);
}

.goal-toggle-chip__label {
  line-height: 1;
}

.goal-toggle-chip__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: rgba(7, 22, 30, 0.16);
}

.tpl-duration-wrap {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}

.tpl-distance-wrap {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1;
  min-width: 0;
}

.tpl-distance-input {
  flex: 1;
  min-width: 0;
}

.tpl-unit-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 34px;
  padding: 0 0.65rem;
  border-radius: 10px;
  background: rgba(247, 147, 30, 0.12);
  color: #ffb15b;
  font-size: 0.76rem;
  font-weight: 700;
}

.input-num {
  width: 40px;
  text-align: center;
  padding: 0.45rem 0.2rem;
  -moz-appearance: textfield;
}

.input-num::-webkit-inner-spin-button,
.input-num::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.tpl-colon {
  font-size: 0.85rem;
  color: var(--text-soft);
  padding: 0 1px;
}

.tpl-rm-btn {
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.tpl-block-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.tpl-drag-handle {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  cursor: grab;
  padding: 0;
}

.tpl-drag-handle:active {
  cursor: grabbing;
}

.tpl-move-btn {
  width: 26px;
  height: 20px;
  flex-shrink: 0;
  padding: 0;
}

.tpl-move-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Footer (fixed bottom) ── */
.tpl-editor__foot {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  padding-bottom: calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.tpl-editor__foot .secondary-btn {
  flex: 0 0 auto;
}

.tpl-editor__foot .primary-btn {
  flex: 1;
}

/* ── Mobile compact tweaks ───────────────────────────────────────────────── */
@media (max-width: 639px) {
  .tpl-editor__head {
    padding: 0.7rem 0.75rem;
    gap: 0.45rem;
  }

  .tpl-editor__head-row h2 {
    font-size: 1.05rem;
  }

  .tpl-editor__blocks-head {
    padding: 0.5rem 0.75rem;
  }

  .tpl-editor__blocks {
    padding: 0.45rem 0.55rem;
    gap: 0.35rem;
  }

  .tpl-block-row {
    gap: 0.3rem;
    padding: 0.35rem 0.4rem;
  }

  .tpl-block-main {
    gap: 0.35rem;
  }

  .tpl-block-goal {
    align-items: flex-start;
  }

  .tpl-block-name {
    font-size: 0.82rem;
    padding: 0.38rem 0.45rem;
  }

  .input-num {
    width: 36px;
    padding: 0.38rem 0.15rem;
    font-size: 0.82rem;
  }

  .tpl-editor__foot {
    padding: 0.6rem 0.75rem;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
  }
}

/* ── Small screen extra compact ─────────────────────────────────────────── */
@media (max-width: 389px) {
  .tpl-block-name {
    font-size: 0.78rem;
  }

  .input-num {
    width: 33px;
    font-size: 0.78rem;
  }
}
