:root {
  --bg:      #000;
  --bg2:     #1c1c1e;
  --bg3:     #2c2c2e;
  --bg4:     #3a3a3c;
  --text:    #fff;
  --text2:   rgba(235,235,245,.6);
  --text3:   rgba(235,235,245,.3);
  --green:   #30d158;
  --blue:    #0a84ff;
  --red:     #ff453a;
  --orange:  #ff9f0a;
  --yellow:  #ffd60a;
  --sep:     rgba(84,84,88,.65);
  --tab-h:   calc(49px + env(safe-area-inset-bottom));
  --top:     env(safe-area-inset-top);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---- Login ---- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-box {
  width: 100%; max-width: 320px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.login-logo { font-size: 64px; }
.login-box h1 { font-size: 28px; font-weight: 700; }
.login-box p  { color: var(--text2); font-size: 15px; }
.login-box input {
  width: 100%; padding: 14px 16px;
  background: var(--bg2); border: none; border-radius: 12px;
  color: var(--text); font-size: 16px; outline: none;
  -webkit-appearance: none;
}

/* ---- App shell ---- */
#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  position: relative;
}
#data-chrome {
  flex-shrink: 0;
  padding-top: calc(var(--top) + 12px);
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
#data-chrome h2 { font-size: 22px; font-weight: 700; padding: 0 16px 8px; }
main#content {
  flex: 1; overflow-y: auto;
  padding-bottom: var(--tab-h);
  -webkit-overflow-scrolling: touch;
  will-change: transform;
  position: relative;
  z-index: 2;
  background: var(--bg);
  scrollbar-width: none;
}
main#content::-webkit-scrollbar { display: none; }
/* Bleibt bei der Daten-Tab-Höhe von #content (unter dem Chrome) synchron -
   top/bottom werden beim Drag-Start per JS aus #content übernommen. */
.content-preview {
  position: absolute; left: 0; right: 0;
  overflow: hidden;
  padding-bottom: var(--tab-h);
  will-change: transform;
  pointer-events: none;
  z-index: 1;
  display: none;
}

/* ---- Tab bar ---- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--tab-h);
  background: rgba(28,28,30,.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}
.tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  padding: 6px 0 2px;
  color: var(--text2);
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
}
.tab.active { color: var(--blue); }
.tab-icon  { font-size: 22px; line-height: 1; }
.tab-label { font-size: 10px; font-weight: 500; }

/* ---- Common ---- */
.screen { padding: 0 0 16px; }

.screen-header {
  padding: 12px 16px 8px;
  padding-top: calc(var(--top) + 12px);
}
.screen-header h2 { font-size: 22px; font-weight: 700; }
.screen-header .subtitle { font-size: 13px; color: var(--text2); margin-top: 2px; }

.section { margin: 12px 16px 0; }
.section-title {
  font-size: 13px; font-weight: 600;
  color: var(--text2); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 8px;
  padding-left: 4px;
}

.card {
  background: var(--bg2);
  border-radius: 16px;
  overflow: hidden;
}
.card + .card { margin-top: 8px; }

.card-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sep);
}
.card-row:last-child { border-bottom: none; }

/* ---- Buttons ---- */
.btn-primary {
  width: 100%; padding: 15px;
  background: var(--blue); color: #fff;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { opacity: .8; }

.btn-pill {
  padding: 8px 16px;
  background: var(--bg3); color: var(--text);
  border: none; border-radius: 20px;
  font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn-pill:active { opacity: .7; }
.btn-pill.active { background: var(--blue); color: #fff; }
.btn-pill.green  { background: rgba(48,209,88,.2); color: var(--green); }
.btn-pill.red    { background: rgba(255,69,58,.15); color: var(--red); }

.btn-icon {
  width: 36px; height: 36px;
  background: var(--bg3); color: var(--text2);
  border: none; border-radius: 10px;
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.btn-icon:active { opacity: .7; }

/* ---- Progress bar ---- */
.progress-bar {
  height: 6px; background: var(--bg3);
  border-radius: 3px; overflow: hidden;
  margin-top: 6px;
}
.progress-fill {
  height: 100%; border-radius: 3px;
  background: var(--blue);
  transition: width .3s ease;
}
.progress-fill.green  { background: var(--green); }
.progress-fill.orange { background: var(--orange); }
.progress-fill.full   { background: var(--green); }

/* ---- Metric card ---- */
.metric-row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--sep);
}
.metric-row:last-child { border-bottom: none; }
.metric-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.metric-label { display: flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 500; }
.metric-value { font-size: 15px; color: var(--text2); }
.metric-value span { color: var(--text); font-weight: 600; }
.quick-btns {
  display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px;
}

/* ---- Training ---- */
.training-card { padding: 16px; }
.training-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.training-meta { font-size: 13px; color: var(--text2); margin-bottom: 14px; }
.training-btns { display: flex; gap: 8px; }
.training-btns .btn-pill { flex: 1; text-align: center; font-size: 13px; }
.training-btns .btn-pill.selected-0 { background: rgba(255,69,58,.2); color: var(--red); }
.training-btns .btn-pill.selected-1 { background: rgba(255,159,10,.2); color: var(--orange); }
.training-btns .btn-pill.selected-2 { background: rgba(48,209,88,.2); color: var(--green); }

/* ---- Supplement ---- */
.supp-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--sep);
}
.supp-row:last-child { border-bottom: none; }
.supp-info { flex: 1; }
.supp-name { font-size: 15px; font-weight: 500; }
.supp-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.supp-toggle {
  width: 44px; height: 28px;
  background: var(--bg4); border: none; border-radius: 14px;
  cursor: pointer; position: relative;
  transition: background .2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.supp-toggle::after {
  content: ''; position: absolute;
  width: 22px; height: 22px;
  background: #fff; border-radius: 11px;
  top: 3px; left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.supp-toggle.on { background: var(--green); }
.supp-toggle.on::after { transform: translateX(16px); }
.supp-notdue { opacity: .35; }

/* ---- Date nav ---- */
.date-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg2); border-radius: 14px;
  margin: 8px 16px 0;
}
.date-nav-label { font-size: 16px; font-weight: 600; }
.date-nav button {
  background: none; border: none; color: var(--blue);
  font-size: 22px; cursor: pointer; padding: 4px 8px;
  -webkit-tap-highlight-color: transparent;
}
.date-nav-center {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.date-nav-input {
  background: none; border: none; color: var(--text);
  font-size: 16px; font-weight: 600; text-align: center;
  -webkit-appearance: none; color-scheme: dark;
  -webkit-tap-highlight-color: transparent;
}
.date-nav-today {
  background: none; border: none; color: var(--blue) !important;
  font-size: 12px !important; font-weight: 500; padding: 0 !important;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}

/* ---- List items ---- */
.list-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--sep);
}
.list-item:last-child { border-bottom: none; }
.list-item-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; font-weight: 500; line-height: 1.3; }
.list-item-sub   { font-size: 13px; color: var(--text2); margin-top: 3px; }
.list-item-action {
  background: none; border: none; color: var(--red);
  font-size: 20px; padding: 4px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.list-item-action:active { opacity: .6; }

.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text2); font-size: 15px;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ---- Sub-tabs ---- */
.sub-tabs {
  position: relative;
  display: flex; gap: 0;
  overflow-x: auto; padding: 0 16px;
  margin-bottom: 4px;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
  mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}
.sub-tabs::-webkit-scrollbar { display: none; }
.sub-tab {
  flex-shrink: 0; padding: 8px 16px;
  background: none; border: none; color: var(--text2);
  font-size: 14px; font-weight: 500; cursor: pointer;
  border-bottom: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
}
.sub-tab.active { color: var(--blue); }
.sub-tab-indicator {
  position: absolute; bottom: 0; left: 0; height: 2px;
  background: var(--blue);
  transition: transform .2s ease, width .2s ease;
  will-change: transform;
}

/* ---- Chat ---- */
.chat-screen {
  display: flex; flex-direction: column;
  height: 100%;
}
.chat-header {
  padding: 12px 16px 10px;
  padding-top: calc(var(--top) + 12px);
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--sep);
}
.chat-header h2 { font-size: 18px; font-weight: 700; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  scrollbar-width: none;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.chat-messages::-webkit-scrollbar { display: none; }
.msg {
  max-width: 80%; padding: 10px 14px;
  border-radius: 18px; font-size: 15px; line-height: 1.4;
  word-break: break-word; white-space: pre-wrap;
}
.msg.user {
  background: var(--blue); color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.msg.bot {
  background: var(--bg2); color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.loading { color: var(--text2); }
.chat-input-bar {
  display: flex; gap: 8px; padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: rgba(28,28,30,.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--sep);
}
.chat-input-bar input {
  flex: 1; padding: 10px 14px;
  background: var(--bg3); border: none; border-radius: 20px;
  color: var(--text); font-size: 15px; outline: none;
  -webkit-appearance: none;
}
.chat-send {
  width: 38px; height: 38px;
  background: var(--blue); border: none; border-radius: 50%;
  color: #fff; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.chat-send:active { opacity: .8; }

/* ---- Input modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 480px;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
}
.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal input[type=number], .modal input[type=text], .modal input[type=date], .modal input[type=time], .modal textarea {
  width: 100%; padding: 14px 16px;
  background: var(--bg3); border: none; border-radius: 12px;
  color: var(--text); font-size: 17px; outline: none;
  -webkit-appearance: none; margin-bottom: 12px;
  color-scheme: dark;
}
.modal textarea { height: 80px; resize: none; font-family: inherit; }
.modal-btns { display: flex; gap: 10px; }
.modal-btns button { flex: 1; }
.btn-cancel {
  flex: 1; padding: 14px;
  background: var(--bg3); color: var(--text);
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ---- Stats ---- */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; padding: 0 16px;
}
.stat-card {
  background: var(--bg2); border-radius: 14px;
  padding: 14px;
}
.stat-card-label { font-size: 12px; color: var(--text2); font-weight: 500; margin-bottom: 4px; }
.stat-card-value { font-size: 24px; font-weight: 700; }
.stat-card-unit  { font-size: 12px; color: var(--text2); margin-left: 2px; }
.stat-card-goal  { font-size: 11px; color: var(--text3); margin-top: 6px; }

/* ---- Spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--bg3);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 48px auto;
}

/* ---- Settings ---- */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--sep);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { font-size: 15px; }
.settings-row input[type=number] {
  width: 90px; padding: 8px 12px;
  background: var(--bg3); border: none; border-radius: 10px;
  color: var(--text); font-size: 15px; text-align: right; outline: none;
  -webkit-appearance: none;
}
