/* components.css — frosted top bar, bottom tab bar, lists, buttons, fields,
   segmented control, chips, badges, toast. */

/* ---- top bar (frosted) ---- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--pad) 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 0.5px solid var(--separator);
}
.topbar-left { justify-self: start; display: flex; align-items: center; min-width: 0; }
.topbar-title { justify-self: center; text-align: center; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-action { justify-self: end; display: flex; align-items: center; }

/* ‹ Back and text actions in the nav bar */
.back-btn, .text-btn {
  border: 0; background: none; color: var(--primary);
  font-size: 17px; cursor: pointer; padding: 6px 2px; border-radius: 8px;
  white-space: nowrap;
}
.back-btn { font-weight: 400; }
.text-btn { font-weight: 600; }
.back-btn:active, .text-btn:active { opacity: 0.55; }

/* ---- bottom tab bar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid var(--separator);
}
.tab {
  flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); padding: 6px 0;
}
.tab-glyph { width: 25px; height: 25px; display: inline-flex; align-items: center; justify-content: center; }
.tab-glyph svg { width: 100%; height: 100%; }
.tab-label { font-size: 10px; font-weight: 600; letter-spacing: 0.01em; }
.tab[aria-current="page"] { color: var(--primary); }

/* ---- lists (grouped, inset) ---- */
.list {
  background: var(--bg-grouped); border-radius: var(--radius); overflow: hidden;
  border: 0.5px solid var(--separator);
}
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; min-height: 56px; cursor: pointer;
  border-bottom: 0.5px solid var(--separator);
}
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; font-weight: 600; }
.row-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.chevron { color: var(--muted); font-size: 20px; }

/* ---- badges / pills ---- */
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-owner { background: color-mix(in srgb, var(--blue) 16%, transparent); color: var(--blue); }
.badge-coach { background: var(--fill); color: var(--text-2); }

/* ---- buttons ---- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--fill); color: var(--blue);
  padding: 12px 16px; border-radius: 12px; font-size: 17px; font-weight: 600;
  transition: transform 0.08s ease, opacity 0.12s ease;
}
.btn:active { opacity: 0.85; transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-danger { color: var(--red); }
.btn-block { display: block; width: 100%; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-lg { padding: 16px; font-size: 18px; border-radius: 14px; }

/* ---- segmented control (iOS style) ---- */
.segmented { display: flex; gap: 2px; padding: 2px; background: var(--fill); border-radius: 9px; width: 100%; }
.segmented button {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--text);
  font-size: 14px; font-weight: 600; padding: 7px 10px; border-radius: 7px; cursor: pointer;
  transition: background 0.15s ease;
}
.segmented button[aria-selected="true"] { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,0.18); }
.btn-outline:active { background: color-mix(in srgb, var(--primary) 8%, transparent); }

/* ---- form fields ---- */
.field {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 0.5px solid var(--separator); background: var(--bg-elev); color: var(--text);
  outline: none;
}
.field:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 22%, transparent); }
.field-num { width: 100px; text-align: right; }
select.field { appearance: none; background-image: none; }

/* ---- league picker: two buttons, selected ringed in green ---- */
.league-pick { display: flex; gap: 10px; width: 100%; }
.league-btn {
  flex: 1; cursor: pointer; padding: 13px 10px; border-radius: 12px;
  border: 2px solid var(--separator); background: var(--bg-elev); color: var(--text);
  font-size: 16px; font-weight: 600;
}
.league-btn:active { opacity: 0.7; }
.league-btn-active {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green) inset;
  background: color-mix(in srgb, var(--green) 8%, var(--bg-elev));
}

/* ---- full-width select with a chevron ---- */
.select-wrap { position: relative; width: 100%; }
.select-wrap select.field { width: 100%; padding-right: 38px; }
.select-wrap::after {
  content: '▾'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--muted); font-size: 14px;
}

/* ---- chips (coach allowlist) ---- */
.chip-list { display: flex; flex-direction: column; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border-radius: 10px; padding: 8px 10px 8px 12px;
}
.chip-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chip-x {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 20px; width: 28px; height: 28px; border-radius: 50%;
}
.chip-x:active { background: rgba(0,0,0,0.08); }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 16px); z-index: 50;
  max-width: min(90vw, 420px); padding: 12px 16px; border-radius: 12px;
  background: #333; color: #fff; font-size: 14px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.22s, transform 0.22s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--red); }
.toast-info { background: #333; }

/* ---- offline indicator ---- */
.offline-bar {
  position: fixed; left: 0; right: 0; z-index: 40;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 7px 16px; text-align: center;
  background: var(--orange); color: #fff; font-size: 13px; font-weight: 600;
}
.offline-bar.syncing { background: var(--primary); }
.offline-bar[hidden] { display: none; }

/* rows for writes queued offline (not yet synced) */
.list-row.pending { opacity: 0.65; }

/* ---- loading spinner ---- */
.spinner-wrap { display: flex; justify-content: center; padding: 44px 0; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--fill); border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- slide-up sheet modal ---- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity 0.25s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg); color: var(--text);
  border-radius: 16px 16px 0 0; padding: 6px 16px calc(env(safe-area-inset-bottom) + 24px);
  max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
.sheet-backdrop.open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 5px; border-radius: 3px; background: var(--separator); margin: 8px auto 4px; }
.sheet-title { text-align: center; font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.sheet-section { margin-top: 16px; }
.sheet-submit { margin-top: 28px; }
.sheet .form-row .field[type="text"] { max-width: 60%; }

/* ---- iOS toggle switch ---- */
.switch {
  width: 51px; height: 31px; border-radius: 16px; border: 0; cursor: pointer; flex-shrink: 0;
  background: var(--fill); position: relative; transition: background 0.2s;
}
.switch.on { background: var(--green); }
.switch-knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.2s;
}
.switch.on .switch-knob { transform: translateX(20px); }

/* ---- selectable tags (multi-select attributes) ---- */
.tag-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.tag {
  border: 1px solid var(--separator); background: var(--bg-elev); color: var(--text);
  padding: 7px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.tag-on { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag:active { opacity: 0.7; }
.tag-mini {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 6px;
  background: var(--fill); color: var(--muted); font-size: 11px; font-weight: 600; vertical-align: middle;
}
.flag-warn {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 6px;
  background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange);
  font-size: 11px; font-weight: 700; vertical-align: middle; white-space: nowrap;
}

/* ---- availability status (roster) ---- */
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; align-self: center; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-orange { background: var(--orange); }
.dot-none { background: transparent; } /* keeps rows aligned for non-pitchers */
.row-sub.status-green { color: var(--green); }
.row-sub.status-red { color: var(--red); }
.row-sub.status-orange { color: var(--orange); }

/* ---- drag-to-reorder (SortableJS) ---- */
.drag-handle {
  color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 6px;
  cursor: grab; touch-action: none; /* let SortableJS own the gesture on touch */
}
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { background: var(--fill); }
.sortable-drag { box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
