/* ---------- FitFlow – Dark Theme, Handy/Tablet/TV ---------- */
:root {
  --bg: #0f1216;
  --panel: #171c22;
  --panel2: #1d242d;
  --border: #232b34;
  --text: #e8edf2;
  --muted: #9aa7b4;
  --accent: #3ecf8e;
  --accent-dark: #2aa86f;
  --danger: #ff6b6b;
  --warn: #f5b95f;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; }
.page-title { font-size: 1.5rem; margin: 0 0 18px; }
h2 { font-size: 1.1rem; margin: 26px 0 12px; }
h2:first-child { margin-top: 0; }
.hint { color: var(--muted); font-size: .9rem; }
.error { color: var(--danger); font-size: .95rem; margin: 10px 0; }
.ok { color: var(--accent); font-size: .95rem; margin: 10px 0; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
  min-width: 0;
}
.brand { font-weight: 800; font-size: 1.25rem; letter-spacing: .3px; color: var(--text); }
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a, .nav-logout {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-size: .95rem;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  white-space: nowrap;
}
.nav a:hover, .nav-logout:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel2); color: var(--text); font-weight: 600; }
.nav-logout { margin-top: 10px; color: var(--muted); }
.side-foot { font-size: .8rem; color: var(--muted); word-break: break-all; }
.main { padding: 30px 32px 70px; max-width: 1100px; width: 100%; min-width: 0; }

/* ---------- Karten & Grids ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card .thumb {
  width: 100%; height: 130px; object-fit: cover;
  border-radius: 10px; background: var(--panel2);
}
.card .thumb-emoji {
  width: 100%; height: 130px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 3rem; background: var(--panel2);
}
.card h3 { margin: 0; font-size: 1.05rem; }
.card .desc { color: var(--muted); font-size: .9rem; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.card .btn-primary { flex: 1; text-align: center; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--panel2); color: var(--muted); font-size: .8rem;
}
.badge.green { color: var(--accent); border: 1px solid var(--accent-dark); }

/* ---------- Buttons & Inputs ---------- */
.btn, .btn-primary, .btn-ghost, .btn-danger {
  font-family: inherit; font-size: .95rem;
  border-radius: 10px; padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--panel2); color: var(--text);
  cursor: pointer;
  min-height: 44px;
}
.btn:hover, .btn-ghost:hover { background: #242d38; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #08130d; font-weight: 700; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { color: var(--danger); border-color: #4a2a2a; }
.btn-ghost { background: transparent; }
.big { font-size: 1.1rem; padding: 14px 22px; min-height: 54px; }
.block { display: block; width: 100%; text-align: center; }
.icon-btn { min-height: 38px; padding: 6px 12px; font-size: 1rem; }

.input, .select, .textarea {
  font-family: inherit; font-size: 1rem;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; width: 100%;
  min-height: 44px;
}
.textarea { min-height: 110px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--accent-dark); border-color: transparent; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 6px; }
.check { display: flex; align-items: center; gap: 10px; font-size: .95rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

/* ---------- Sterne ---------- */
.stars { display: inline-flex; gap: 4px; }
.stars button {
  background: none; border: none; font-size: 1.6rem; cursor: pointer;
  color: #3a4552; padding: 2px; line-height: 1;
}
.stars button.on { color: var(--warn); }
.stars button:hover { transform: scale(1.15); }

/* ---------- Tabelle ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px; border-bottom: 1px solid var(--border); }

/* ---------- Routine-Builder ---------- */
.step-row {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
}
.step-row .name { flex: 1; min-width: 140px; font-weight: 600; }
.step-row .input { width: 130px; }

/* ---------- Chat ---------- */
.chat-box { display: flex; flex-direction: column; gap: 12px; max-height: 62vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 82%; padding: 12px 16px; border-radius: 14px; font-size: .97rem; white-space: pre-wrap; }
.msg.user { background: var(--panel2); align-self: flex-end; border: 1px solid var(--border); }
.msg.assistant { background: var(--panel); align-self: flex-start; border: 1px solid var(--border); }
.msg .plan-card { margin-top: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: .88rem; font-family: inherit;
}
.chip:hover { border-color: var(--accent-dark); }
.chat-input { display: flex; gap: 10px; }
.chat-input .input { flex: 1; }

/* ---------- Player ---------- */
.player {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: 18px 22px calc(18px + env(safe-area-inset-bottom));
}
.player-top { display: flex; align-items: center; gap: 14px; }
.p-progress { flex: 1; height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; }
.p-progress .fill { height: 100%; background: var(--accent); width: 0%; transition: width .4s; }
.auto-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.auto-label input { width: 18px; height: 18px; accent-color: var(--accent); }
.p-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center; padding: 20px 10px; overflow-y: auto;
}
.p-img { max-width: min(78vw, 560px); max-height: 34vh; object-fit: contain; border-radius: 14px; }
.p-title { font-size: clamp(1.6rem, 4.5vw, 3rem); font-weight: 800; margin: 0; }
.p-desc { color: var(--muted); font-size: clamp(1rem, 2vw, 1.35rem); max-width: 700px; margin: 0; }
.p-timer {
  font-size: clamp(3.4rem, 12vw, 7.5rem); font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--text); min-height: 1.2em;
}
.p-timer.warn { color: var(--warn); }
.p-timer.done { color: var(--accent); }
.p-notime { color: var(--muted); font-size: 1.1rem; }
.p-foot { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 10px; }
.p-foot .row { justify-content: center; }
.reps { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.reps .input { width: 110px; }
.break-big { font-size: clamp(2rem, 6vw, 4rem); font-weight: 800; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 34px; max-width: 400px; width: 100%;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-card .brand { font-size: 1.8rem; }
.login-card p { color: var(--muted); margin: 0; }

/* ---------- TV (ab 1200px) ---------- */
@media (min-width: 1200px) {
  html { font-size: 19px; }
  .layout { grid-template-columns: 270px 1fr; }
  .main { padding: 40px 48px 80px; max-width: 1280px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
  .card .thumb, .card .thumb-emoji { height: 170px; }
  .btn, .btn-primary, .btn-ghost { min-height: 52px; font-size: 1.05rem; }
}

/* ---------- Handy ---------- */
@media (max-width: 899px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side {
    position: static;
    background: var(--bg);
    border-right: none; border-bottom: none;
    padding: 12px 14px 0;
    gap: 0;
  }
  .side .brand { font-size: 1.1rem; padding: 0 4px; }
  .side-foot { display: none; }
  .main { padding: 16px 14px 80px; }
  .page-title { font-size: 1.25rem; margin-bottom: 12px; }
  h2 { font-size: 1rem; margin-top: 22px; margin-bottom: 10px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; gap: 8px; }
  .card .thumb, .card .thumb-emoji { height: 80px; border-radius: 8px; }
  .card .thumb-emoji { font-size: 2rem; }
  .card h3 { font-size: 1rem; }
  .card .row { gap: 8px; }
  .btn, .btn-primary, .btn-ghost { min-height: 42px; padding: 10px 14px; font-size: .9rem; }
  .btn-primary.big, .big { min-height: 50px; font-size: 1.05rem; }
  .step-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .step-row .input, .step-row .select { width: 100%; }
  .player { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .input, .select, .textarea { min-height: 42px; padding: 10px 12px; font-size: .95rem; }
  .field { margin-bottom: 12px; }
  .row { gap: 8px; }
  .spread { flex-wrap: wrap; }
  .week-grid { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .week-col { padding: 6px; min-height: 60px; }
  .week-day { font-size: .7rem; }
  .week-item { font-size: .72rem; }
  #chat-fab { bottom: 70px; right: 14px; width: 48px; height: 48px; }
  #chat-panel { bottom: 0; left: 0; right: 0; width: 100%; max-width: 100%; max-height: 75vh; border-radius: 16px 16px 0 0; }
}

/* ---------- Neue Seiten-Components ---------- */
.streak-badge {
  display: inline-block; padding: 8px 16px; border-radius: 999px;
  background: rgba(245, 185, 95, 0.15); border: 1px solid var(--warn);
  color: var(--warn); font-weight: 700; font-size: 1rem; margin-bottom: 16px;
}
.today-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 20px;
}
.today-label {
  font-size: .75rem; font-weight: 700; letter-spacing: 1.5px;
  color: var(--accent); margin-bottom: 6px;
}
.week-strip { margin: 20px 0; }
.week-dots { display: flex; gap: 6px; }
.week-dot {
  width: 32px; height: 32px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: .7rem;
  background: var(--panel2); color: var(--muted); border: 2px solid var(--border);
}
.week-dot.done { background: var(--accent-dark); color: #fff; border-color: var(--accent); }
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.stat-box { flex: 1; min-width: 80px; text-align: center; padding: 12px; background: var(--panel); border-radius: 10px; border: 1px solid var(--border); }
.stat-num { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 56px; padding: 8px 0; }
.bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-width: 12px; opacity: .85; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; font-size: .95rem; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover { color: var(--text); }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 20px; }
.week-col { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-height: 80px; }
.week-col.today { border-color: var(--accent); }
.week-day { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: .8rem; }
.today-label { color: var(--accent); font-weight: 700; }
.week-item { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .82rem; }
.week-item:last-child { border-bottom: none; }
.week-empty { text-align: center; padding: 12px 0; }

/* Leaderboard */
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.lb-rank { font-weight: 800; font-size: 1.1rem; color: var(--muted); min-width: 24px; }
.lb-name { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-bar-wrap { flex: 2; height: 8px; background: var(--panel2); border-radius: 99px; overflow: hidden; min-width: 60px; }
.lb-bar { height: 100%; background: var(--accent); border-radius: 99px; }
.lb-val { font-weight: 700; font-size: .9rem; color: var(--accent); white-space: nowrap; }

/* Mobile: Bottom-Tab-Bar */
@media (max-width: 899px) {
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: rgba(15, 18, 22, .97); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); border-bottom: none;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
    overflow-x: visible;
    flex-direction: row;
    gap: 0;
  }
  .nav a {
    flex: 1; text-align: center; padding: 8px 4px; font-size: .72rem;
    border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
    white-space: normal;
  }
  .nav a.active { background: rgba(62, 207, 142, 0.15); color: var(--accent); }
}

/* ---------- KI-Assistent Floating Widget ---------- */
#chat-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(62, 207, 142, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#chat-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(62, 207, 142, 0.5);
}
#chat-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 1000;
  width: 440px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
#chat-panel.open {
  display: flex;
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 120px;
  max-height: 280px;
}
.chat-body .msg {
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.chat-body .msg.user {
  background: var(--accent-dark);
  color: #fff;
  margin-left: 30px;
}
.chat-body .msg.assistant {
  background: var(--panel2);
  margin-right: 30px;
}
.chat-body .msg.muted {
  color: var(--muted);
}
.chat-body .plan-card {
  margin-top: 6px;
  padding: 6px 10px;
  background: rgba(62, 207, 142, 0.1);
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  font-size: 0.85rem;
}
.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.chat-chips .chip {
  font-size: 0.75rem;
  padding: 4px 10px;
}
.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.chat-input .input {
  flex: 1;
  min-width: 0;
}
@media (max-width: 480px) {
  #chat-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 76px;
  }
  #chat-fab {
    bottom: 14px;
    right: 14px;
    width: 46px;
    height: 46px;
    font-size: 1.3rem;
  }
}
