/* TimeFlow — handgeschriebenes CSS, kein Build-Schritt.
   Palette als Custom Properties; hell ist die Basis, dunkel wird
   darübergelegt. Ein manueller Umschalter setzt data-theme am <html>. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dce0e8;
  --border-strong: #c3c9d6;
  --text: #171a21;
  --text-muted: #666e80;
  --text-faint: #97a0b2;

  --accent: #4f46e5;
  --accent-soft: #e8e7fd;
  --accent-text: #ffffff;
  --now: #e0483a;

  --prio-1: #3b82f6;
  --prio-2: #f59e0b;
  --prio-3: #ef4444;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 4px 12px rgba(16, 20, 30, .06);
  --shadow-lift: 0 8px 28px rgba(16, 20, 30, .22);

  --gutter: 58px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f2430;
    --border: #272d3a;
    --border-strong: #39415420;
    --text: #e8eaf0;
    --text-muted: #9aa3b5;
    --text-faint: #6b7488;
    --accent: #7c78f0;
    --accent-soft: #262450;
    --accent-text: #ffffff;
    --now: #ff6b5c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    --shadow-lift: 0 8px 28px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f2430;
  --border: #272d3a;
  --text: #e8eaf0;
  --text-muted: #9aa3b5;
  --text-faint: #6b7488;
  --accent: #7c78f0;
  --accent-soft: #262450;
  --now: #ff6b5c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
  --shadow-lift: 0 8px 28px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select { font: inherit; color: inherit; }

.muted { color: var(--text-muted); }

/* ── Login ────────────────────────────────────────────────────────────── */

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.login-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: .5px;
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; font-size: 14px; }

.login-card form { text-align: left; }

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="datetime-local"], input[type="time"],
input[type="date"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:disabled { opacity: .6; cursor: default; }

.form-error {
  margin: 0 0 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--prio-3) 14%, transparent);
  color: var(--prio-3);
  font-size: 13px;
}

/* ── App-Gerüst ───────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.2px;
}

.topbar .date-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: -2px;
}

.topbar .spacer { flex: 1; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-muted);
  flex: 0 0 auto;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.is-active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.pill-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}

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

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ── Eingang ──────────────────────────────────────────────────────────── */

.inbox {
  width: 320px;
  flex: 0 0 auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inbox-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
}

.inbox-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-faint);
}

.inbox-count {
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 8px;
}

.inbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 16px;
  -webkit-overflow-scrolling: touch;
}

.inbox-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

.inbox-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 11px;
  margin-bottom: 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  touch-action: none;
  position: relative;
}

.inbox-item:active { cursor: grabbing; }
.inbox-item.is-ghost { opacity: .35; }

.inbox-item .title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  word-break: break-word;
}

.inbox-item.is-done .title { text-decoration: line-through; color: var(--text-faint); }

.inbox-item .meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.quick-add {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
}

.quick-add input {
  margin: 0;
  background: var(--surface-2);
}

/* Checkbox */
.check {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  margin-top: 1px;
  border: 1.5px solid var(--border-strong);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  color: transparent;
}

.check:hover { border-color: var(--accent); }
.is-done .check, .check.is-checked {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Timeline ─────────────────────────────────────────────────────────── */

.timeline-wrap {
  flex: 1;
  overflow-y: auto;
  position: relative;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

.timeline {
  position: relative;
  margin: 8px 12px 0 0;
}

/* Stundenraster liegt über die volle Breite, Blöcke nur rechts der Uhrzeiten. */
.grid { position: absolute; inset: 0; }

.lane {
  position: absolute;
  left: var(--gutter);
  right: 0;
  top: 0;
  bottom: 0;
}

.hour-row {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  pointer-events: none;
}

.hour-row.is-half { border-top-style: dotted; opacity: .55; }

.hour-label {
  position: absolute;
  left: 0;
  top: -8px;
  width: calc(var(--gutter) - 12px);
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.now-line {
  position: absolute;
  left: calc(var(--gutter) - 8px);
  right: 0;
  height: 0;
  border-top: 2px solid var(--now);
  pointer-events: none;
  z-index: 6;
}

.now-line::before {
  content: "";
  position: absolute;
  left: -5px;
  top: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--now);
}

.now-label {
  position: absolute;
  left: calc(-1 * var(--gutter) + 6px);
  top: -9px;
  font-size: 10px;
  font-weight: 700;
  color: var(--now);
  font-variant-numeric: tabular-nums;
}

/* Blöcke */
.block {
  position: absolute;
  border-radius: var(--radius);
  padding: 6px 9px;
  overflow: hidden;
  font-size: 13px;
  border: 1px solid transparent;
  z-index: 2;
}

.block-task {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
  border-left: 3px solid var(--accent);
}

.block-task:active { cursor: grabbing; }

.block-task[data-priority="1"] { border-left-color: var(--prio-1); }
.block-task[data-priority="2"] { border-left-color: var(--prio-2); }
.block-task[data-priority="3"] { border-left-color: var(--prio-3); }

.block-task.is-done { opacity: .5; }
.block-task.is-done .block-title { text-decoration: line-through; }

.block-task.is-dragging {
  z-index: 20;
  box-shadow: var(--shadow-lift);
  transform: scale(1.015);
  opacity: .95;
}

.block-event {
  background: repeating-linear-gradient(
    45deg,
    var(--surface-2),
    var(--surface-2) 6px,
    transparent 6px,
    transparent 12px
  );
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  z-index: 1;
}

.block-head {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.block-title {
  font-weight: 600;
  line-height: 1.25;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.block-time {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

/* Kurze Blöcke: alles in eine Zeile quetschen */
.block.is-short { padding: 3px 9px; display: flex; align-items: center; }
.block.is-short .block-time { display: none; }
.block.is-short .block-title { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.resize-handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  cursor: ns-resize;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 26px;
  height: 3px;
  border-radius: 2px;
  transform: translateX(-50%);
  background: var(--border-strong);
  opacity: 0;
  transition: opacity .12s;
}

.block-task:hover .resize-handle::after { opacity: .8; }

/* Einfügemarke beim Ziehen aus dem Eingang */
.drop-hint {
  position: absolute;
  left: 0;
  right: 0;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  opacity: .8;
  z-index: 15;
  pointer-events: none;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* Element, das am Finger klebt */
.drag-proxy {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  max-width: 260px;
  transform: rotate(-1.2deg);
}

/* ── Detail-Sheet ─────────────────────────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, .45);
  z-index: 100;
  display: grid;
  place-items: end center;
}

.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lift);
  max-height: 88dvh;
  overflow-y: auto;
}

@media (min-width: 720px) {
  .sheet-backdrop { place-items: center; }
  .sheet { border-radius: 18px; }
}

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 0 auto 14px;
}

.sheet h3 { margin: 0 0 14px; font-size: 16px; }

.sheet label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.sheet textarea { min-height: 72px; resize: vertical; }

.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; min-width: 0; }

.sheet-actions {
  display: flex;
  gap: 9px;
  margin-top: 6px;
}

.sheet-actions .btn-primary { flex: 1; }

.btn-ghost {
  padding: 11px 14px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--prio-3); border-color: color-mix(in srgb, var(--prio-3) 35%, transparent); }

.prio-picker { display: flex; gap: 6px; margin-bottom: 16px; }

.prio-option {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}

.prio-option.is-selected { border-color: currentColor; }
.prio-option[data-value="1"].is-selected { color: var(--prio-1); background: color-mix(in srgb, var(--prio-1) 12%, transparent); }
.prio-option[data-value="2"].is-selected { color: var(--prio-2); background: color-mix(in srgb, var(--prio-2) 12%, transparent); }
.prio-option[data-value="3"].is-selected { color: var(--prio-3); background: color-mix(in srgb, var(--prio-3) 12%, transparent); }
.prio-option[data-value="0"].is-selected { color: var(--text); background: var(--surface-2); }

/* ── Toast ────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  box-shadow: var(--shadow-lift);
  animation: toast-in .18s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
}

/* ── Mobil ────────────────────────────────────────────────────────────── */

.inbox-toggle { display: none; }

@media (max-width: 860px) {
  .inbox {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: 62dvh;
    z-index: 90;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow-lift);
    transform: translateY(100%);
    transition: transform .22s cubic-bezier(.32, .72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .inbox.is-open { transform: translateY(0); }
  .inbox-toggle { display: grid; }

  .timeline { margin-right: 8px; }
}

/* ── Seite „Wiederholungen & Routinen" ────────────────────────────────── */

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 20px 16px calc(60px + env(safe-area-inset-bottom));
}

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.page-head h1 { margin: 0; font-size: 20px; }

.section { margin-bottom: 34px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-faint);
}

.section-head .spacer { flex: 1; }

.section-hint {
  margin: -6px 0 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  margin-bottom: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card.is-inactive { opacity: .5; }

.card-body { flex: 1; min-width: 0; }
.card-body .name { font-weight: 600; }

.card-body .rule {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.empty-card {
  padding: 26px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Wochentag-Auswahl */
.weekday-picker { display: flex; gap: 5px; margin-bottom: 16px; }

.weekday {
  flex: 1;
  padding: 9px 0;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}

.weekday.is-selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

/* Umschalter Regelmäßig/Flexibel */
.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 16px;
}

.segmented button {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.segmented button.is-selected {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* Schritte einer Routine */
.step-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.step-row input[type="text"] { margin: 0; flex: 1; }
.step-row input[type="number"] { margin: 0; width: 84px; flex: 0 0 auto; }

.step-remove {
  flex: 0 0 auto;
  width: 34px;
  height: 38px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-faint);
  cursor: pointer;
}

.step-remove:hover { color: var(--prio-3); border-color: var(--prio-3); }

.add-step {
  width: 100%;
  padding: 9px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 16px;
}

.add-step:hover { color: var(--accent); border-color: var(--accent); }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.switch-row label { margin: 0; }

/* Herkunfts-Marke auf Blöcken aus Serien/Routinen */
.block-badge {
  font-size: 10px;
  opacity: .75;
  flex: 0 0 auto;
  margin-top: 2px;
}

/* Offline-Hinweis */
.offline-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--prio-2);
  color: #1b1400;
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  z-index: 250;
  box-shadow: var(--shadow-lift);
}
