:root {
  color-scheme: light dark;

  --bg-light: #f4f6f9;
  --bg-dark: #0b1120;
  --surface-light: #ffffff;
  --surface-dark: #131c31;
  --surface-2-light: #eef2f7;
  --surface-2-dark: #1b2742;
  --text-light: #0f172a;
  --text-dark: #f1f5f9;
  --muted-light: #475569;
  --muted-dark: #94a3b8;
  --border-light: rgba(15, 23, 42, 0.1);
  --border-dark: rgba(241, 245, 249, 0.12);
  --accent-light: #2563eb;
  --accent-dark: #60a5fa;
  --accent-fg-light: #ffffff;
  --accent-fg-dark: #071327;
  --danger-light: #dc2626;
  --danger-dark: #f87171;
  --warn-bg-light: #fef2f2;
  --warn-bg-dark: rgba(220, 38, 38, 0.16);
  --warn-border-light: #fca5a5;
  --warn-border-dark: rgba(248, 113, 113, 0.45);

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --surface-2: var(--surface-2-light);
  --text: var(--text-light);
  --muted: var(--muted-light);
  --border: var(--border-light);
  --accent: var(--accent-light);
  --accent-fg: var(--accent-fg-light);
  --danger: var(--danger-light);
  --warn-bg: var(--warn-bg-light);
  --warn-border: var(--warn-border-light);

  --target-size: 36px;
  --hour-height: 96px;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --surface-2: var(--surface-2-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --border: var(--border-dark);
    --accent: var(--accent-dark);
    --accent-fg: var(--accent-fg-dark);
    --danger: var(--danger-dark);
    --warn-bg: var(--warn-bg-dark);
    --warn-border: var(--warn-border-dark);
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

@supports (color: light-dark(white, black)) {
  :root {
    --bg: light-dark(var(--bg-light), var(--bg-dark));
    --surface: light-dark(var(--surface-light), var(--surface-dark));
    --surface-2: light-dark(var(--surface-2-light), var(--surface-2-dark));
    --text: light-dark(var(--text-light), var(--text-dark));
    --muted: light-dark(var(--muted-light), var(--muted-dark));
    --border: light-dark(var(--border-light), var(--border-dark));
    --accent: light-dark(var(--accent-light), var(--accent-dark));
    --accent-fg: light-dark(var(--accent-fg-light), var(--accent-fg-dark));
    --danger: light-dark(var(--danger-light), var(--danger-dark));
    --warn-bg: light-dark(var(--warn-bg-light), var(--warn-bg-dark));
    --warn-border: light-dark(var(--warn-border-light), var(--warn-border-dark));
    accent-color: var(--accent);
  }
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

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

html {
  scroll-padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  text-wrap: balance;
  margin: 0;
}

p, li {
  text-wrap: pretty;
}

[hidden] {
  display: none !important;
}

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

:where(button, select, input:not([type="checkbox"], [type="radio"]), .icon-btn) {
  min-block-size: var(--target-size);
}

/* Login */
.login-shell {
  min-block-size: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.login-card {
  width: min(100%, 25rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.9rem;
}

.login-badge {
  display: inline-block;
  width: fit-content;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border-radius: 11px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  padding: 0.38rem 0.72rem;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: var(--target-size);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 1.05rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.58rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
  font-size: 0.86rem;
}

.form-error {
  color: var(--danger);
  font-size: 0.86rem;
  margin: 0;
}

/* App Shell */
.app-shell {
  min-block-size: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(4.6rem + env(safe-area-inset-bottom, 0px));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: max(0.65rem, env(safe-area-inset-top, 0px)) max(0.9rem, env(safe-area-inset-right, 0px)) 0.65rem max(0.9rem, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.date-title-btn {
  border: 0;
  background: transparent;
  padding: 0.25rem 0.5rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

#header-weekday {
  font-weight: 700;
  font-size: 1rem;
}

.date-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  top: calc(4.2rem + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: var(--bg);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

.workspace {
  width: min(100%, 1260px);
  margin: 0 auto;
  padding: 0.85rem max(0.85rem, env(safe-area-inset-right, 0px)) 1.5rem max(0.85rem, env(safe-area-inset-left, 0px));
  flex: 1;
}

/* View Day Layout */
.view-day {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.day-main {
  display: grid;
  gap: 0.75rem;
  min-inline-size: 0;
}

.desktop-sidebar {
  display: none;
  gap: 0.9rem;
  align-content: start;
}

@media (min-width: 960px) {
  .app-shell {
    padding-bottom: 5.5rem;
  }
  .view-day {
    grid-template-columns: minmax(0, 1.6fr) minmax(290px, 0.9fr);
    align-items: start;
  }
  .desktop-sidebar {
    display: grid;
    position: sticky;
    top: 4.5rem;
  }
  .bottom-nav {
    max-width: 420px;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%);
    bottom: 0.85rem !important;
    border-radius: 999px !important;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
}

/* Warnings */
.warnings-list {
  display: grid;
  gap: 0.45rem;
}

.warning-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--danger);
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 600;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

/* Stats Strip */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.38rem;
}

.stat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.stat-head strong {
  white-space: nowrap;
}

.stat-label {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.76rem;
}

.stat-sub {
  font-size: 0.74rem;
  color: var(--muted);
}

.progress-track {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill-planned {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  border-radius: 999px;
  opacity: 0.28;
  transition: width 0.25s ease;
}

.progress-fill {
  position: relative;
  height: 100%;
  border-radius: 999px;
  width: 0%;
  transition: width 0.25s ease;
}

.progress-da {
  background: #7c3aed;
}

.progress-gym {
  background: #059669;
}

/* Prayer Strip */
.prayer-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

@media (min-width: 600px) {
  .prayer-strip {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.prayer-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.32rem 0.52rem;
  font-size: 0.74rem;
}

.prayer-chip strong {
  font-variant-numeric: tabular-nums;
}

/* Timeline */
.timeline-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.timeline-scroll {
  overflow-y: auto;
  max-block-size: calc(100dvh - 18rem);
  min-block-size: 460px;
}

.timeline-canvas {
  position: relative;
  height: calc(19 * var(--hour-height)); /* 05:00 - 24:00 */
  margin: 0.5rem 0.65rem 0.5rem 0.45rem;
}

.timeline-hours {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hour-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--hour-height);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
}

.hour-label {
  width: 3rem;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transform: translateY(-0.55em);
  background: var(--surface);
  padding-right: 0.35rem;
}

.timeline-events {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3.15rem;
  right: 0;
}

/* Now Line */
.now-line {
  position: absolute;
  left: 2.9rem;
  right: 0;
  height: 2px;
  background: #ef4444;
  z-index: 20;
  pointer-events: none;
}

.now-dot {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #ef4444;
}

.now-badge {
  position: absolute;
  right: 4px;
  top: -10px;
  font-size: 0.68rem;
  font-weight: 700;
  background: #ef4444;
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

/* Timeline Block */
.t-block {
  position: absolute;
  border-radius: 11px;
  padding: 0.3rem 0.55rem;
  border: 1px solid transparent;
  border-left-width: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: box-shadow 0.15s ease, opacity 0.15s ease;
}

.t-block.compact {
  padding: 0.12rem 0.5rem;
  border-radius: 8px;
  justify-content: center;
}

.t-block.compact .t-title {
  font-size: 0.76rem;
  -webkit-line-clamp: 1;
}

.t-block:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.t-block.dragging {
  opacity: 0.88;
  z-index: 25;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

.t-block.status-done {
  opacity: 0.58;
}

.t-block.status-done .t-title {
  text-decoration: line-through;
}

.t-block.status-missed, .t-block.status-skipped {
  opacity: 0.4;
}

/* Category Colors */
.type-uni_pflicht {
  background: color-mix(in srgb, #2563eb 13%, var(--surface));
  border-color: color-mix(in srgb, #2563eb 30%, transparent);
  border-left-color: #2563eb;
}

.type-uni_vorlesung {
  background: color-mix(in srgb, var(--muted) 7%, var(--surface));
  border: 1px dashed var(--border);
  border-left: 3px dashed var(--muted);
  opacity: 0.55;
}

.type-fahrt {
  background: color-mix(in srgb, #64748b 11%, var(--surface));
  border-left-color: #64748b;
}

.type-gebet, .type-freitagsgebet {
  background: color-mix(in srgb, #0d9488 14%, var(--surface));
  border-left-color: #0d9488;
}

.type-doktorarbeit {
  background: color-mix(in srgb, #7c3aed 13%, var(--surface));
  border-left-color: #7c3aed;
}

.type-gym {
  background: color-mix(in srgb, #059669 13%, var(--surface));
  border-left-color: #059669;
}

.type-familie {
  background: color-mix(in srgb, #d97706 14%, var(--surface));
  border-left-color: #d97706;
}

.type-aufgabe {
  background: color-mix(in srgb, #db2777 12%, var(--surface));
  border-left-color: #db2777;
}

.type-termin, .type-sonstiges {
  background: color-mix(in srgb, #0284c7 12%, var(--surface));
  border-left-color: #0284c7;
}

.t-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  min-width: 0;
}

.t-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  flex: 1;
}

.t-title {
  font-weight: 600;
  font-size: 0.82rem;
  line-height: 1.2;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.t-time-loc {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.t-badges {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.badge-pflicht {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 5px;
  background: #2563eb;
  color: #fff;
}

.badge-fixed {
  font-size: 0.72rem;
  opacity: 0.85;
}

.drag-handle {
  touch-action: none;
  cursor: grab;
  padding: 2px 4px;
  font-size: 0.85rem;
  opacity: 0.55;
  line-height: 1;
}

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

.family-actions {
  display: flex;
  gap: 0.35rem;
  margin-top: 2px;
}

.mini-pill-btn {
  min-block-size: 26px !important;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

/* Sidebar & Cards */
.sidebar-card, .settings-card, .task-item, .week-day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

.sidebar-head, .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.task-list-compact, .tasks-full-list {
  display: grid;
  gap: 0.5rem;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.7rem 0.8rem;
}

.task-check {
  width: 22px;
  height: 22px;
  min-block-size: 22px !important;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
}

.task-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.task-title {
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.kw-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.quick-kw-bar {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.task-meta {
  font-size: 0.77rem;
  color: var(--muted);
  margin-top: 2px;
}

.week-mini {
  display: grid;
  gap: 0.4rem;
}

.week-mini-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 0;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

/* Week View */
.week-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}

.week-day-card {
  display: grid;
  gap: 0.45rem;
  align-content: start;
  cursor: pointer;
}

.week-day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}

.week-chip {
  font-size: 0.78rem;
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
}

.week-chip.ignored {
  opacity: 0.48;
  border-left-style: dashed;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 0.85rem;
}

.settings-card-wide {
  grid-column: 1 / -1;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.sync-list {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.sync-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  padding: 0.45rem 0.6rem;
  border-radius: 9px;
  background: var(--surface-2);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0.3rem max(0.5rem, env(safe-area-inset-right, 0px)) max(0.4rem, env(safe-area-inset-bottom, 0px)) max(0.5rem, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

.nav-tab {
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.35rem 0.4rem;
  border-radius: 12px;
  cursor: pointer;
}

.nav-tab.active {
  color: var(--accent);
}

/* Native Modal Dialogs */
dialog {
  width: min(94vw, 31rem);
  max-height: 90dvh;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.15rem;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(3px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-form {
  display: grid;
  gap: 0.75rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field {
  display: grid;
  gap: 0.3rem;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.checkbox-row input {
  width: 20px;
  height: 20px;
  min-block-size: 20px !important;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-status {
  background: var(--surface-2);
  border-color: var(--border);
  font-size: 0.8rem;
  padding: 0.4rem 0.65rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.spacer {
  flex: 1;
}

@media (max-width: 440px) {
  .hide-xs {
    display: none;
  }
}
