/* efficient — Dark Cockpit.
   Tiefes Schwarzblau als Grund, Aktivitaetsfarben als einzige Lichtquelle. */

:root {
  --bg: #07090d;
  --bg-2: #0d1118;
  --panel: #11161f;
  --panel-2: #161c27;
  --line: #1e2634;
  --text: #e8edf5;
  --muted: #7c8798;
  --dim: #4a5364;
  --accent: #6ee7f9;
  --danger: #f87171;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior-y: none;
}

body {
  background:
    radial-gradient(120% 80% at 50% -10%, #101828 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
}

button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.muted { color: var(--muted); font-size: 13px; }
[hidden] { display: none !important; }

/* --------------------------------------------------------------- Boot */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 99; }
.boot-pulse {
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(.6); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* --------------------------------------------------------------- Shell */
#app { padding: calc(var(--safe-t) + 14px) 16px calc(96px + var(--safe-b)); max-width: 620px; margin: 0 auto; }
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------- Header */
.now-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.now-meta { display: flex; align-items: center; gap: 10px; }
.phase-chip {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(110, 231, 249, .09); color: var(--accent);
  border: 1px solid rgba(110, 231, 249, .18);
}
.streak-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 600;
}
.streak-flame { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 10px #4ade80; }
.streak-chip.cold .streak-flame { background: var(--dim); box-shadow: none; }

/* --------------------------------------------------------- Overrun-Hinweis */
.overrun {
  background: linear-gradient(180deg, rgba(251,191,119,.10), rgba(251,191,119,.04));
  border: 1px solid rgba(251,191,119,.24);
  border-radius: var(--radius);
  padding: 14px; margin-bottom: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.overrun-text { display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.overrun-text span { color: var(--muted); font-size: 13px; }
.overrun-actions { display: flex; gap: 8px; }
.overrun-actions .btn { flex: 1; padding: 9px; font-size: 14px; }

/* ------------------------------------------------------------ Der Ring */
.current { display: grid; place-items: center; margin: 2px 0 16px; }
.current-ring { position: relative; width: min(44vw, 176px); aspect-ratio: 1; }
.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--line); stroke-width: 7; }
.ring-fill {
  fill: none; stroke: var(--dim); stroke-width: 7; stroke-linecap: round;
  stroke-dasharray: 553; stroke-dashoffset: 553;
  transition: stroke-dashoffset .6s cubic-bezier(.4,0,.2,1), stroke .4s;
}
.current-inner {
  position: absolute; inset: 0; display: grid; place-content: center;
  text-align: center; gap: 4px;
}
.current-label { font-size: 13px; letter-spacing: .04em; color: var(--muted); }
.current-timer {
  font-family: var(--mono); font-size: 27px; font-weight: 500;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.current-since { font-size: 12px; }
.current.live .current-label { color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------- Kacheln */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  position: relative; overflow: hidden;
  padding: 11px 8px 9px; min-height: 68px;
  border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  text-align: center; transition: transform .12s, border-color .2s, background .2s;
}
.tile:active { transform: scale(.96); }
.tile .dot { width: 8px; height: 8px; border-radius: 50%; }
.tile .name {
  font-size: 12.5px; font-weight: 600; line-height: 1.15;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .sub { font-size: 10px; color: var(--dim); font-variant-numeric: tabular-nums; }
.tile.active { background: var(--panel-2); }
.tile.active::after {
  content: ''; position: absolute; inset: 0; border-radius: 14px;
  border: 1.5px solid currentColor; opacity: .6;
}
.tile.active .name { color: inherit; }

/* Neu anlegen und Auf-/Zuklappen sitzen als Kacheln im selben Raster —
   so bleibt der Griff dorthin genauso kurz wie zu einer Aktivitaet. */
.tile.add, .tile.more { border-style: dashed; background: transparent; }
.tile .plus { font-size: 19px; line-height: 1; color: var(--muted); }
.tile.add .name, .tile.more .name { color: var(--muted); font-weight: 500; }
.tile.add:active, .tile.more:active { background: var(--panel); }

.now-foot { margin-top: 12px; }

/* ------------------------------------------------------------ Tagesbar */
.daybar-wrap { margin-top: 26px; }
.daybar-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.daybar {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
}
.daybar.tall { height: 22px; border-radius: 8px; }
.daybar i { display: block; height: 100%; }
.daybar i.gap { background: repeating-linear-gradient(45deg, #141a24 0 4px, #0f141c 4px 8px); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 12px; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend b { width: 7px; height: 7px; border-radius: 2px; }
.legend em { font-style: normal; color: var(--text); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- Zielringe */
.goal-rings { display: flex; gap: 14px; margin-top: 24px; overflow-x: auto; padding-bottom: 4px; }
.goal { flex: 0 0 auto; width: 74px; text-align: center; }
.goal svg { width: 74px; height: 74px; transform: rotate(-90deg); }
.goal .gt { fill: none; stroke: var(--line); stroke-width: 7; }
.goal .gf { fill: none; stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset .7s cubic-bezier(.4,0,.2,1); }
.goal .glabel { font-size: 11px; color: var(--muted); margin-top: 6px; }
.goal .gval { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--dim); }

/* ------------------------------------------------------------ Historie */
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.day-title { text-align: center; }
.day-title > div:first-child { font-size: 18px; font-weight: 600; }
.nav-btn {
  width: 40px; height: 40px; border-radius: 12px; font-size: 22px; line-height: 1;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.nav-btn:disabled { opacity: .3; }
.day-stats { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px;
}
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }

.phase-strip {
  display: flex; gap: 4px; margin-top: 8px;
}
.phase-strip .ph {
  flex: 1 1 0; min-width: 0; padding: 8px 2px; border-radius: 9px;
  background: var(--panel); border: 1px solid var(--line);
  transition: background .15s, border-color .15s;
}
.phase-strip .ph:active { transform: scale(.96); }
.phase-strip .phl {
  display: block; font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: clip; text-align: center;
}
.phase-strip .ph.on { background: rgba(110,231,249,.12); border-color: rgba(110,231,249,.4); }
/* Noch nicht begonnene Phase: sichtbar, aber erkennbar nicht waehlbar. */
.phase-strip .ph.pending { opacity: .38; border-style: dashed; }
.phase-strip .ph.pending .phl { color: var(--dim); }
.phase-strip .ph.on .phl { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------- Zeitfelder in Blaettern */
/* Zwei datetime-local nebeneinander gehen nicht: iOS erzwingt gut 220 px
   Mindestbreite, damit laeuft die Zeile aus dem Blatt heraus. Deshalb
   untereinander, dafuer mit Schnellkorrektur-Knoepfen. */
.timefield { margin-bottom: 12px; }
.timefield input { width: 100%; }
.nudges { display: flex; gap: 6px; margin-top: 7px; }
.nudges button {
  flex: 1; padding: 8px 0; border-radius: 9px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.nudges button:active { background: var(--panel-2); }
.dur-readout {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 11px 14px; margin: 4px 0 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  font-size: 13px; color: var(--muted);
}
.dur-readout b { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.dur-readout.bad { border-color: rgba(248,113,113,.45); }
.dur-readout.bad b { color: var(--danger); }

.list { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; width: 100%; text-align: left;
}
.row:active { background: var(--panel-2); }
.row .bar { width: 3px; align-self: stretch; border-radius: 2px; }
.row .mid { flex: 1; min-width: 0; }
.row .t { font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .n { font-size: 15px; font-weight: 600; margin-top: 2px; }
.row .meta { font-size: 11px; color: var(--dim); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.row .d { font-family: var(--mono); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row.is-gap { background: transparent; border-style: dashed; }
.row.is-gap .n { color: var(--dim); font-weight: 500; }
.tag { background: var(--panel-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; }

/* ------------------------------------------------------------ Statistik */
.seg { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.card .hint { font-size: 12px; color: var(--dim); margin: 0 0 14px; line-height: 1.45; }

.barlist { display: flex; flex-direction: column; gap: 11px; }
.barrow .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.barrow .top em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }
.barrow .track { height: 7px; border-radius: 4px; background: var(--bg-2); overflow: hidden; }
.barrow .fill { height: 100%; border-radius: 4px; transition: width .6s cubic-bezier(.4,0,.2,1); }

.heat { display: grid; grid-template-columns: 42px 1fr; gap: 6px 8px; align-items: center; }
.heat .hl { font-size: 11px; color: var(--muted); text-align: right; }
.heat .hcells { display: grid; grid-template-columns: repeat(24, 1fr); gap: 1px; height: 16px; }
.heat .hcells i { border-radius: 1px; background: var(--bg-2); }
.heat-axis { display: grid; grid-template-columns: repeat(4, 1fr); font-size: 10px; color: var(--dim); margin-left: 50px; margin-top: 6px; }

.weekgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.weekgrid .wd { font-size: 10px; color: var(--dim); text-align: center; }
.weekgrid .wc { aspect-ratio: 1; border-radius: 5px; background: var(--bg-2); border: 1px solid var(--line); }

.delta { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.delta:last-child { border-bottom: 0; }
.delta .n { display: flex; align-items: center; gap: 8px; }
.delta .n b { width: 7px; height: 7px; border-radius: 2px; }
.delta .v { font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 13px; }
.up { color: #4ade80; } .down { color: var(--danger); } .flat { color: var(--dim); }

/* ------------------------------------------------------------- Buttons */
.btn {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 13px 18px; font-size: 15px; font-weight: 600;
  transition: transform .1s;
}
.btn:active { transform: scale(.98); }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn.accent { background: rgba(110,231,249,.10); border-color: rgba(110,231,249,.28); color: var(--accent); }
.btn.danger { color: var(--danger); border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.07); }

/* ---------------------------------------------------------------- Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(8px + var(--safe-b));
  background: rgba(7,9,13,.86);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px; color: var(--dim); padding: 6px 0;
}
.tabs .ti { font-size: 17px; line-height: 1; }
.tabs button.on { color: var(--accent); }

/* -------------------------------------------------------------- Sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; animation: fade .18s ease;
  backdrop-filter: blur(3px);
}
.sheet {
  width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--bg-2); border-top-left-radius: 24px; border-top-right-radius: 24px;
  border-top: 1px solid var(--line);
  padding: 10px 18px calc(24px + var(--safe-b));
  animation: slideup .26s cubic-bezier(.32,.72,0,1);
  max-width: 620px; margin: 0 auto;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 16px; }
.sheet h2 { margin: 0 0 16px; font-size: 18px; }
/* Der Hauptknopf klebt am unteren Rand des Blattes. Bei vielen Aktivitaeten
   wird das Blatt laenger als der Bildschirm, und dann lag "Eintragen"
   ausserhalb des Sichtfelds — man haette erst scrollen muessen. */
.sheet .btn.accent.wide {
  position: sticky;
  bottom: 0;
  z-index: 2;
  box-shadow: 0 6px 20px 10px var(--bg-2);
}

.sheet h4 { margin: 20px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }

/* -------------------------------------------------------------- Inputs */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 12px 14px; font-size: 16px; font-family: inherit;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(110,231,249,.4); }
textarea { min-height: 76px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 8px 13px; border-radius: 10px; font-size: 14px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: rgba(110,231,249,.1); border-color: rgba(110,231,249,.35); color: var(--accent); }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.scale button { padding: 12px 0; border-radius: 11px; background: var(--panel); border: 1px solid var(--line); font-size: 15px; color: var(--muted); }
.scale button.on { background: rgba(110,231,249,.12); border-color: rgba(110,231,249,.4); color: var(--accent); font-weight: 600; }

.setrow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.setrow:last-child { border-bottom: 0; }
.setrow .l { font-size: 15px; }
.setrow .s { font-size: 12px; color: var(--dim); margin-top: 3px; line-height: 1.4; }
.setrow .r { flex: 0 0 auto; }

.actrow { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.actrow .sw { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.actrow .an { flex: 1; font-size: 15px; }
.actrow .ag { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(88px + var(--safe-b)); z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 12px; font-size: 14px;
  animation: fade .2s ease; max-width: 88vw; text-align: center;
}
.toast.err { border-color: rgba(248,113,113,.4); color: #fca5a5; }

.empty { text-align: center; color: var(--dim); font-size: 14px; padding: 34px 20px; line-height: 1.6; }
