/* ============================================================
   Gym Tracker – Design System
   Dark-First, Mobile-Optimiert, PWA
   ============================================================ */

:root {
  /* Schrift */
  --font-body: 'Inter', system-ui, sans-serif;

  /* Fluid Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2rem);

  /* Spacing (4px System) */
  --s1: 0.25rem;  /* 4px */
  --s2: 0.5rem;   /* 8px */
  --s3: 0.75rem;  /* 12px */
  --s4: 1rem;     /* 16px */
  --s5: 1.25rem;  /* 20px */
  --s6: 1.5rem;   /* 24px */
  --s8: 2rem;     /* 32px */

  /* Radius */
  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1rem;
  --r-xl: 1.25rem;
  --r-full: 9999px;

  /* Transition */
  --transition: 160ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Safe Areas (Notch/Statusbar) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: calc(64px + var(--safe-bottom));
  --header-height: 56px;
}

/* ---- DARK THEME (Default) ---- */
:root, [data-theme="dark"] {
  --bg:           #0f0f0f;
  --surface:      #1a1a1a;
  --surface-2:    #222222;
  --surface-3:    #2a2a2a;
  --border:       rgba(255,255,255,0.08);
  --divider:      rgba(255,255,255,0.06);

  --text:         #f0f0f0;
  --text-muted:   #888888;
  --text-faint:   #555555;

  --accent:       #e8ff47;  /* Neon-Gelb: typisch fuer Gym-Apps */
  --accent-dim:   rgba(232,255,71,0.12);
  --accent-text:  #0f0f0f;

  --red:          #ff4d4d;
  --green:        #4caf50;
  --blue:         #4d9fff;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
}

/* ---- LIGHT THEME ---- */
[data-theme="light"] {
  --bg:           #f5f5f5;
  --surface:      #ffffff;
  --surface-2:    #f9f9f9;
  --surface-3:    #f0f0f0;
  --border:       rgba(0,0,0,0.08);
  --divider:      rgba(0,0,0,0.06);

  --text:         #111111;
  --text-muted:   #666666;
  --text-faint:   #aaaaaa;

  --accent:       #1a1a1a;
  --accent-dim:   rgba(0,0,0,0.06);
  --accent-text:  #ffffff;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.15);
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   LAYOUT
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ---- Header ---- */
.app-header {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--header-height);
  padding: 0 var(--s4);
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-left { display: flex; align-items: center; gap: var(--s3); }

.logo {
  width: 28px;
  height: 28px;
  color: var(--accent);
  flex-shrink: 0;
}

.header-title {
  font-size: var(--text-base);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-right { display: flex; align-items: center; gap: var(--s2); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--text-xs);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Screen Container ---- */
.screen-container {
  flex: 1;
  padding-top: var(--header-height);
  padding-bottom: var(--nav-height);
}

.screen {
  display: none;
  animation: fadeIn 200ms ease;
}

.screen.active {
  display: block;
}

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

.screen-content {
  padding: var(--s6) var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}

.screen-content h1 {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: var(--s2);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 44px;
  min-height: 44px;
  padding: var(--s1);
  color: var(--text-faint);
  transition: color var(--transition);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
}

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

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

/* ============================================================
   COMPONENTS
   ============================================================ */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: var(--s3) var(--s5);
  border-radius: var(--r-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  min-height: 44px;
  user-select: none;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-3); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-full { width: 100%; }
.btn-sm { min-height: 36px; padding: var(--s2) var(--s3); font-size: var(--text-xs); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }

.text-btn {
  font-size: var(--text-sm);
  color: var(--accent);
  font-weight: 500;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-sm);
  transition: opacity var(--transition);
}
.text-btn:hover { opacity: 0.75; }

/* ---- Cards ---- */
.stat-card, .chart-card, .session-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-sm);
}

/* ---- Quick Stats ---- */
.quick-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s3);
}

.stat-card {
  padding: var(--s4) var(--s3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s1);
  text-align: center;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---- Greeting ---- */
.greeting {
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.greeting-sub {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--s1);
}

/* ---- Section Header ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h2 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: var(--text-xs);
}

/* ---- Session Cards ---- */
.session-card {
  padding: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.session-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.session-date {
  font-size: var(--text-sm);
  font-weight: 600;
}

.session-badge {
  font-size: var(--text-xs);
  padding: 2px var(--s2);
  border-radius: var(--r-full);
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

.session-exercises {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

/* ---- Empty State ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--s8) var(--s4);
  gap: var(--s4);
  text-align: center;
  color: var(--text-muted);
  min-height: 200px;
}

.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-faint);
}

/* ---- Forms / Inputs ---- */
.input-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--s2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.input-field {
  width: 100%;
  padding: var(--s3) var(--s4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--text-base);
  min-height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.select-wrapper {
  position: relative;
}

.select-icon {
  position: absolute;
  right: var(--s3);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

/* ---- Set Rows ---- */
.sets-container { display: flex; flex-direction: column; gap: var(--s2); }

.set-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s3);
}

.set-num {
  width: 24px;
  height: 24px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
  color: var(--text-muted);
}

.set-inputs { display: flex; gap: var(--s3); flex: 1; }

.input-group { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.input-group label {
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-weight: 500;
}

.input-mini {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: var(--s2) var(--s3);
  font-size: var(--text-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-height: 44px;
  text-align: center;
  width: 100%;
  transition: border-color var(--transition);
}

.input-mini:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- Workout Header ---- */
.workout-header { display: flex; flex-direction: column; gap: var(--s1); }
.workout-meta { font-size: var(--text-sm); color: var(--text-muted); display: flex; gap: var(--s2); }
.dot-sep { color: var(--text-faint); }

/* ---- Chart Cards ---- */
.chart-card { padding: var(--s4); }
.chart-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--s4);
}
.chart-wrap { height: 200px; position: relative; }

.chart-controls {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.time-pills {
  display: flex;
  gap: var(--s2);
}

.pill {
  padding: var(--s2) var(--s4);
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface);
  transition: all var(--transition);
  min-height: 36px;
}

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

/* ---- Calendar Strip ---- */
.calendar-strip {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--s2);
}

.calendar-strip::-webkit-scrollbar { display: none; }

.cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 40px;
  padding: var(--s2) var(--s1);
  border-radius: var(--r-md);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.cal-day.has-workout .cal-dot {
  background: var(--accent);
}

.cal-day.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.cal-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--text-faint);
}

.cal-num { font-weight: 600; }
.cal-dow { color: var(--text-faint); }

/* ---- Settings ---- */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}

.settings-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--s3) var(--s4) var(--s2);
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4);
  border-top: 1px solid var(--divider);
  transition: background var(--transition);
  cursor: pointer;
}

.settings-item:hover { background: var(--surface-2); }
.settings-item:first-of-type { border-top: none; }

.settings-item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-label { font-size: var(--text-sm); font-weight: 500; }
.settings-value { font-size: var(--text-xs); color: var(--text-muted); }
.settings-arrow { color: var(--text-faint); width: 16px; height: 16px; }

/* ---- Skeleton Loader ---- */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.skeleton {
  background: linear-gradient(90deg,
    var(--surface-2) 25%,
    var(--surface-3) 50%,
    var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--r-sm);
}

.skeleton-heading { height: 1.5em; width: 40%; margin-bottom: var(--s3); }
.skeleton-text    { height: 1em;   margin-bottom: var(--s2); }
.skeleton-text:last-child { width: 65%; }

/* ---- Responsive (Tablet+) ---- */
@media (min-width: 480px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
