/* ==========================================================================
   Cadence — Personal Workout & Routine Studio
   Mobile-First Design System (Vanilla CSS)
   ========================================================================== */

:root {
  /* Light Theme — Warm Tactile Editorial Palette */
  --bg-canvas: #f6f4f0;
  --bg-surface: #ffffff;
  --bg-surface-alt: #efece6;
  --bg-elevated: #ffffff;
  --bg-overlay: rgba(20, 18, 16, 0.56);

  --border-subtle: #e6e1d8;
  --border-strong: #d2cabd;

  --text-primary: #1c1a17;
  --text-secondary: #5c564e;
  --text-muted: #847d73;
  --text-on-accent: #ffffff;

  /* Default Accent: Terracotta */
  --accent: #c5532b;
  --accent-hover: #a8421f;
  --accent-soft: rgba(197, 83, 43, 0.11);
  --accent-soft-strong: rgba(197, 83, 43, 0.2);

  --success: #227a52;
  --success-soft: rgba(34, 122, 82, 0.12);
  --warning: #b56c12;
  --warning-soft: rgba(181, 108, 18, 0.14);
  --danger: #c4362c;
  --danger-soft: rgba(196, 54, 44, 0.12);

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radii & Shadows */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgba(28, 26, 23, 0.05);
  --shadow-sm: 0 2px 8px rgba(28, 26, 23, 0.06), 0 1px 2px rgba(28, 26, 23, 0.04);
  --shadow-md: 0 10px 28px rgba(28, 26, 23, 0.1), 0 2px 6px rgba(28, 26, 23, 0.05);
  --shadow-lg: 0 22px 48px rgba(28, 26, 23, 0.18);

  /* Layout Dimensions */
  --header-height: 60px;
  --bottom-nav-height: 68px;
  --sidebar-width: 248px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-med: 240ms var(--ease-out);
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-canvas: #141311;
  --bg-surface: #1d1b18;
  --bg-surface-alt: #26231f;
  --bg-elevated: #24211d;
  --bg-overlay: rgba(8, 7, 6, 0.72);

  --border-subtle: #2e2b26;
  --border-strong: #423d36;

  --text-primary: #f4f1ec;
  --text-secondary: #b5aea4;
  --text-muted: #847d73;

  --accent: #e0724a;
  --accent-hover: #ee845e;
  --accent-soft: rgba(224, 114, 74, 0.16);
  --accent-soft-strong: rgba(224, 114, 74, 0.28);

  --success: #3fb87f;
  --success-soft: rgba(63, 184, 127, 0.16);
  --warning: #e6a23c;
  --warning-soft: rgba(230, 162, 60, 0.18);
  --danger: #e55c52;
  --danger-soft: rgba(229, 92, 82, 0.16);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.6);
}

/* Accent Color Presets */
[data-accent="emerald"] {
  --accent: #1d7a56;
  --accent-hover: #156244;
  --accent-soft: rgba(29, 122, 86, 0.12);
  --accent-soft-strong: rgba(29, 122, 86, 0.22);
}
[data-theme="dark"][data-accent="emerald"] {
  --accent: #3cb886;
  --accent-hover: #53ca9a;
  --accent-soft: rgba(60, 184, 134, 0.16);
  --accent-soft-strong: rgba(60, 184, 134, 0.28);
}

[data-accent="ocean"] {
  --accent: #1b6b96;
  --accent-hover: #145578;
  --accent-soft: rgba(27, 107, 150, 0.12);
  --accent-soft-strong: rgba(27, 107, 150, 0.22);
}
[data-theme="dark"][data-accent="ocean"] {
  --accent: #4aa3d6;
  --accent-hover: #64b4e2;
  --accent-soft: rgba(74, 163, 214, 0.16);
  --accent-soft-strong: rgba(74, 163, 214, 0.28);
}

[data-accent="amber"] {
  --accent: #b56d10;
  --accent-hover: #94580b;
  --accent-soft: rgba(181, 109, 16, 0.13);
  --accent-soft-strong: rgba(181, 109, 16, 0.24);
}
[data-theme="dark"][data-accent="amber"] {
  --accent: #e5a03c;
  --accent-hover: #efb056;
  --accent-soft: rgba(229, 160, 60, 0.16);
  --accent-soft-strong: rgba(229, 160, 60, 0.28);
}

[data-accent="slate"] {
  --accent: #2c2a27;
  --accent-hover: #171614;
  --accent-soft: rgba(44, 42, 39, 0.1);
  --accent-soft-strong: rgba(44, 42, 39, 0.18);
}
[data-theme="dark"][data-accent="slate"] {
  --accent: #dedad3;
  --accent-hover: #ffffff;
  --text-on-accent: #171614;
  --accent-soft: rgba(222, 218, 211, 0.15);
  --accent-soft-strong: rgba(222, 218, 211, 0.26);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  touch-action: manipulation;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   App Shell Layout (Mobile-First -> Desktop Sidebar)
   ========================================================================== */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Top Bar (Mobile) */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--header-height) + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--text-on-accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.025em;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Desktop Sidebar (Hidden on Mobile) */
.desktop-sidebar {
  display: none;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px calc(var(--bottom-nav-height) + var(--safe-bottom) + 28px);
}

/* Mobile Bottom Nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  height: calc(var(--bottom-nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--transition-fast);
  position: relative;
}

.nav-item svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.9;
  transition: transform var(--transition-fast);
}

.nav-item.active {
  color: var(--accent);
}

.nav-item.active svg {
  transform: translateY(-1px);
  stroke-width: 2.2;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 28px;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: var(--accent);
}

/* Desktop Responsive Layout */
@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }

  .top-header,
  .bottom-nav {
    display: none;
  }

  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: 22px 14px 18px;
    gap: 20px;
  }

  .sidebar-brand {
    padding: 4px 10px 8px;
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
  }

  .sidebar-nav .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
  }

  .sidebar-nav .nav-item::before {
    display: none;
  }

  .sidebar-nav .nav-item:hover {
    background: var(--bg-surface-alt);
    color: var(--text-primary);
  }

  .sidebar-nav .nav-item.active {
    background: var(--accent-soft);
    color: var(--accent);
  }

  .sidebar-nav .nav-count {
    margin-left: auto;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    background: var(--bg-surface-alt);
    padding: 2px 7px;
    border-radius: var(--radius-full);
  }

  .sidebar-nav .nav-item.active .nav-count {
    background: var(--accent-soft-strong);
    color: var(--accent);
  }

  .sidebar-footer {
    border-top: 1px solid var(--border-subtle);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .main-content {
    padding: 28px 36px 56px;
  }
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), transform 100ms ease, box-shadow var(--transition-fast);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: var(--shadow-xs);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-surface-alt);
  border-color: var(--border-strong);
}

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-soft:hover {
  background: var(--accent-soft-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-surface-alt);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  filter: brightness(0.92);
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger-soft:hover {
  filter: brightness(0.95);
}

.btn-sm {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: 8px;
  gap: 6px;
}

.btn-sm svg {
  width: 15px;
  height: 15px;
}

.btn-lg {
  min-height: 50px;
  padding: 0 22px;
  font-size: 15px;
  border-radius: 12px;
}

.btn-icon {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-surface-alt);
  color: var(--text-primary);
}

.btn-icon.bordered {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.btn-icon.sm {
  width: 32px;
  height: 32px;
  min-height: 32px;
  border-radius: 8px;
}

.btn-icon svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.btn-icon.sm svg {
  width: 16px;
  height: 16px;
}

/* Form Controls */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  resize: vertical;
  min-height: 84px;
  line-height: 1.5;
}

.input-sm {
  padding: 7px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  min-height: 36px;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

/* ==========================================================================
   Page Header, Filters & Empty States
   ========================================================================== */
.view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.view-title {
  margin: 0;
  font-size: clamp(24px, 4vw, 30px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.view-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.search-box {
  position: relative;
  flex: 1;
}

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box .input {
  padding-left: 38px;
  padding-right: 34px;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
}

.tag-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.tag-bar::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  white-space: nowrap;
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge.youtube {
  background: rgba(214, 42, 42, 0.12);
  color: #c72c2c;
}

[data-theme="dark"] .badge.youtube {
  background: rgba(255, 88, 88, 0.18);
  color: #ff7e7e;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* ==========================================================================
   Cards & Grids
   ========================================================================== */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 640px) {
  .card-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .card-grid.cols-exercises {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1020px) {
  .card-grid.cols-exercises {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.card-desc {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: color-mix(in srgb, var(--bg-surface-alt) 42%, var(--bg-surface));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Exercise Media Card */
.exercise-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--bg-surface-alt);
  overflow: hidden;
  cursor: pointer;
}

.exercise-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 320ms var(--ease-out);
}

.card:hover .exercise-thumb img {
  transform: scale(1.03);
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  background: linear-gradient(135deg, var(--bg-surface-alt), color-mix(in srgb, var(--accent-soft) 60%, var(--bg-surface-alt)));
}

.thumb-monogram {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--accent);
  opacity: 0.75;
}

.thumb-overlay-badges {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
}

.yt-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: rgba(20, 18, 16, 0.76);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}

.yt-pill svg {
  width: 13px;
  height: 13px;
  color: #ff5555;
}

/* Program Schedule Rows */
.schedule-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.schedule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-alt);
  border: 1px solid transparent;
  transition: border-color var(--transition-fast);
}

.schedule-row:hover {
  border-color: var(--border-strong);
}

.schedule-info {
  min-width: 0;
  flex: 1;
}

.schedule-day {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.schedule-name {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schedule-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* Set / Routine Mini Preview List */
.mini-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--bg-surface-alt);
  font-size: 13px;
}

.mini-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.mini-thumb {
  width: 34px;
  height: 22px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-canvas);
}

.mini-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-item-metrics {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* History Stats Strip */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: var(--font-mono);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-state h3 {
  margin: 4px 0 0;
  font-size: 18px;
  font-weight: 700;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 400px;
}

/* ==========================================================================
   Modals & Mobile Bottom Sheets
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fadeIn 180ms ease;
}

.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 92dvh;
  background: var(--bg-elevated);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheetUp 240ms var(--ease-out);
}

.modal-sheet.narrow {
  max-width: 480px;
}

.modal-sheet.wide {
  max-width: 780px;
}

@media (min-width: 680px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .modal-sheet {
    border-radius: var(--radius-lg);
    max-height: 88dvh;
    animation: modalPop 200ms var(--ease-out);
  }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 14px 20px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

@media (min-width: 680px) {
  .modal-footer {
    padding-bottom: 14px;
  }
}

/* Builder Item List (Sets in Routine, Exercises in Set, Routines in Program) */
.builder-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.builder-item {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.builder-item.dragging {
  opacity: 0.55;
  border-color: var(--accent);
}

.builder-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drag-handle {
  color: var(--text-muted);
  cursor: grab;
  padding: 4px;
  display: inline-flex;
  align-items: center;
}

.builder-item-title {
  font-weight: 700;
  font-size: 14.5px;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.builder-item-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}

.add-row-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-row-bar .select {
  flex: 1;
  min-width: 180px;
}

/* Image Upload & Preview Box */
.image-editor-preview {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
}

.image-editor-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Key-Value Custom Fields */
.kv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kv-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

/* Segmented Tabs inside Modals */
.seg-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  background: var(--bg-surface-alt);
  padding: 4px;
  border-radius: var(--radius-sm);
  gap: 4px;
}

.seg-tab {
  min-height: 36px;
  border-radius: 7px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.seg-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

/* YouTube Embed Container */
.video-frame-wrap {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  aspect-ratio: 16 / 9;
  background: #0d0d0d;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.video-frame-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Accent Swatches */
.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: 13px;
  font-weight: 600;
}

.swatch-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.swatch-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

/* Storage Usage Meter */
.meter-track {
  height: 8px;
  width: 100%;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 300ms var(--ease-out);
}

/* ==========================================================================
   Active Workout Player (Full-Screen Focus Mode)
   ========================================================================== */
.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg-canvas);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: fadeIn 200ms ease;
}

.player-header {
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.player-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.player-title-wrap {
  min-width: 0;
  flex: 1;
}

.player-routine-name {
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-meta-line {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-progress-track {
  height: 5px;
  width: 100%;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.player-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 300ms var(--ease-out);
}

.player-stage {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 24px;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.player-context-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
}

.player-media {
  position: relative;
  width: 100%;
  flex-shrink: 0;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.player-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-media-actions {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
}

.player-exercise-name {
  margin: 0;
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.player-prescription {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rx-pill {
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
}

.rx-pill.primary {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
  color: var(--accent);
}

/* Integrated Hold/Work/Rest Timer Card */
.timer-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-xs);
}

.timer-card.rest-mode {
  background: color-mix(in srgb, var(--success-soft) 50%, var(--bg-surface));
  border-color: color-mix(in srgb, var(--success) 35%, var(--border-subtle));
}

.timer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timer-label {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.timer-readout {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(42px, 11vw, 56px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  text-align: center;
  padding: 4px 0;
}

.timer-bar {
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 120ms linear;
}

.timer-card.rest-mode .timer-bar-fill {
  background: var(--success);
}

.timer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.side-switcher {
  display: inline-flex;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 3px;
}

.side-btn {
  padding: 4px 11px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.side-btn.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.player-cues {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.player-cues summary {
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.player-cues summary::-webkit-details-marker {
  display: none;
}

.player-cues p {
  margin: 10px 0 0;
  white-space: pre-line;
}

.player-log-strip {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.player-footer {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.player-footer-inner {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-up-next {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.player-nav-btns {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}

/* ==========================================================================
   Toast Notifications & Alerts
   ========================================================================== */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
  pointer-events: none;
}

@media (min-width: 900px) {
  .toast-container {
    bottom: 24px;
    left: auto;
    right: 24px;
    transform: none;
  }
}

.toast {
  pointer-events: auto;
  background: var(--text-primary);
  color: var(--bg-canvas);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  animation: toastIn 220ms var(--ease-out);
}

.toast.error {
  background: var(--danger);
  color: #ffffff;
}

.toast.success {
  background: var(--success);
  color: #ffffff;
}

.alert-box {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  line-height: 1.5;
  border: 1px solid transparent;
}

.alert-box.info {
  background: var(--accent-soft);
  border-color: var(--accent-soft-strong);
  color: var(--text-primary);
}

.alert-box.warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
  color: var(--text-primary);
}

.alert-box.danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--text-primary);
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 22px 16px;
  text-align: center;
  background: var(--bg-surface-alt);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes modalPop {
  from { transform: scale(0.97); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes toastIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
