:root {
  --bg: #0f1419;
  --bg-elev: #1a222c;
  --bg-elev-2: #222d3a;
  --text: #e8edf2;
  --muted: #8a99a8;
  --accent: #f5a623;   /* Wachs-Amber */
  --accent-2: #ffc65c;
  --ok: #35c759;
  --warn: #ff9f0a;
  --err: #ff453a;
  --border: #2a3542;
  --radius: 16px;
  font-size: 17px;
}

* { box-sizing: border-box; }

/* Muss ID-Selektoren wie #view-login { display:flex } überstimmen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  /* iOS safe areas berücksichtigen (Notch / Homescreen-Vollbild) */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.view { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }

/* --- Branding --- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.6rem; margin: 0; letter-spacing: 0.5px; }
.brand.small h1 { font-size: 1.25rem; }
.brand-drop {
  width: 32px; height: 32px;
  background: url("/icons/icon-192.png") center / cover no-repeat;
  border-radius: 8px;
  flex: none;
}
.brand.small .brand-drop { width: 26px; height: 26px; border-radius: 7px; }
.login-box .brand-drop { width: 40px; height: 40px; border-radius: 10px; }

/* --- Login --- */
#view-login { display: flex; align-items: center; min-height: 80vh; }
.login-box {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
}
.login-box .brand { justify-content: center; margin-bottom: 6px; }
.login-box .muted { text-align: center; margin: 0 0 20px; }

form { display: flex; flex-direction: column; gap: 12px; }

input[type="password"], input[type="text"], input[type="date"], select {
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--accent);
  color: #1a1200;
  transition: opacity 0.15s ease;
}
button:active { opacity: 0.7; }
button:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-weight: 500;
}

/* --- App-Header --- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}

/* --- Karten --- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 1.05rem; margin: 0; }

/* --- Statuszeile mit Punkt --- */
.status-row { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot-err { background: var(--err); box-shadow: 0 0 8px var(--err); }
.dot-warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot-wait { background: var(--muted); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 0.35; } 50% { opacity: 1; } }

.detail-list { list-style: none; padding: 0; margin: 12px 0 0; }
.detail-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.detail-list li span:first-child { color: var(--muted); }
.detail-list li span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

/* --- Fehlerbox (laut sichtbar) --- */
.error-box {
  background: rgba(255, 69, 58, 0.12);
  border: 1px solid rgba(255, 69, 58, 0.5);
  border-radius: 12px;
  padding: 12px 14px;
  margin-top: 12px;
  color: #ffb4ae;
  font-size: 0.95rem;
  line-height: 1.4;
}

.muted { color: var(--muted); }
.error { color: var(--err); font-size: 0.95rem; margin: 4px 0 0; }
.timestamp { color: var(--muted); font-size: 0.85rem; margin-top: 10px; }

.phase-note { margin-top: 8px; }
.phase-note .muted { font-size: 0.9rem; line-height: 1.5; }

/* --- Tabs & Bottom-Nav --- */
.view#view-app { padding-bottom: 96px; } /* Platz für die Tabbar */
.tab-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.tab-head h2 { font-size: 1.3rem; margin: 0; }
.card-head.between, .between { display: flex; align-items: center; justify-content: space-between; }
.card-head h3 { font-size: 1rem; margin: 0; }
.small-note { font-size: 0.85rem; margin-top: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: rgba(20, 27, 35, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}
.tabbtn {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 0.72rem; font-weight: 600; display: flex; flex-direction: column;
  align-items: center; gap: 3px; padding: 6px 0; border-radius: 10px;
}
.tabbtn .ico { font-size: 1.3rem; }
.tabbtn.is-active { color: var(--accent); }

/* --- Badges --- */
.badge {
  font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  white-space: nowrap; flex: none;
}
.badge-ok { background: rgba(53,199,89,0.18); color: #7ee29a; }
.badge-err { background: rgba(255,69,58,0.18); color: #ff9d95; }
.badge-warn { background: rgba(255,159,10,0.18); color: #ffce80; }
.badge-neutral { background: var(--bg-elev-2); color: var(--muted); }
.badge-soon { background: rgba(255,199,92,0.18); color: #ffdd9e; }

/* --- Wachs-Zeilen (Flüssig + Heiß) --- */
.wax-line { margin: 10px 0; }
.wax-line-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.85rem; margin-bottom: 4px; }
.chain-lifetime { font-size: 0.9rem; color: var(--muted); margin: 6px 0 10px; }
.chain-lifetime strong { color: var(--text); font-variant-numeric: tabular-nums; }

/* --- Stillgelegte Ketten --- */
.retired { margin-top: 10px; }
.retired summary { color: var(--muted); font-size: 0.9rem; cursor: pointer; padding: 6px 0; }
.retired-row { padding: 4px 0 4px 12px; }

/* --- Fortschrittsbalken --- */
.bar { height: 8px; background: var(--bg-elev-2); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.bar-ok { background: var(--ok); }
.bar-warn { background: var(--warn); }
.bar-err { background: var(--err); }

/* --- Ketten-Karten --- */
.chain.is-due { border-color: rgba(255,69,58,0.5); }
.chain-title { font-size: 1.05rem; margin: 0; }
.mini { font-size: 0.82rem; }
.chain .mini { margin: 2px 0; }
.chain-stats { display: flex; justify-content: space-between; align-items: baseline; margin: 4px 0 6px; }
.chain-stats strong { font-size: 1.05rem; }
.chain-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chain-actions button { flex: 1; min-width: 120px; padding: 11px 12px; font-size: 0.9rem; }

button.secondary { background: var(--bg-elev-2); color: var(--accent-2); border: 1px solid var(--border); }
button.danger { background: rgba(255,69,58,0.15); color: #ff9d95; border: 1px solid rgba(255,69,58,0.4); }

.error-box.small { font-size: 0.85rem; padding: 8px 10px; }
.ok-text { color: var(--ok); }

/* --- Auswertung --- */
.period-picker { display: flex; gap: 8px; margin-bottom: 16px; }
.period-picker button {
  flex: 1; background: var(--bg-elev); color: var(--muted);
  border: 1px solid var(--border); padding: 10px 8px; font-size: 0.85rem; font-weight: 600;
}
.period-picker button.is-active { background: var(--accent); color: #1a1200; border-color: var(--accent); }
.big-stat { display: flex; flex-direction: column; gap: 2px; }
.big-num { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* --- Fahrrad-Zeilen (editierbar) --- */
.bike-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.bike-row:first-of-type { border-top: none; }
.bike-info { flex: 1; min-width: 0; }
.bike-info strong { font-size: 1rem; }
.bike-km { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.icon-btn { padding: 8px 12px; font-size: 1rem; }

/* --- Strava --- */
.btn-link {
  display: inline-block; text-decoration: none; text-align: center;
  font-weight: 700; border-radius: 12px; padding: 13px 16px;
}
.btn-link.strava { background: #fc4c02; color: #fff; width: 100%; }
.strava-card { background: var(--bg-elev); }
.mini-head { margin: 0 0 8px; font-size: 0.95rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* --- Toast (kurze Rückmeldung) --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 200;
  max-width: 90%; padding: 12px 18px; border-radius: 12px;
  font-size: 0.9rem; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.toast-ok { background: var(--ok); color: #04220f; }
.toast-err { background: var(--err); color: #2a0805; }

/* --- Formulare in Karten/Modals --- */
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
form label { margin-top: 4px; }
form label input, form label select { margin-top: 6px; }

/* --- Modal --- */
#modal-root { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal {
  position: relative; width: 100%; max-width: 640px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow-y: auto;
  animation: slideup 0.2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0.5; } to { transform: none; opacity: 1; } }
.modal h3 { margin: 0 0 14px; font-size: 1.2rem; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions button { flex: 1; }
@media (min-width: 560px) { #modal-root { align-items: center; } .modal { border-radius: 20px; } }
