:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --border: #d9dee7;
  --primary: #2f5bea;
  --primary-dark: #2346b8;
  --danger: #d13b3b;
  --success: #1f9d55;
  --warning: #c77700;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

h1, h2 { margin: 0 0 1rem; line-height: 1.25; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; margin-top: 1.5rem; }
.list-header h1, .list-header h2 { margin: 0; }

.container { width: 100%; max-width: 1150px; margin: 0 auto; padding: 0 1rem; }
.narrow { max-width: 640px; }

/* Topbar */
.topbar { background: var(--text); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 1rem; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.nav { display: flex; gap: 0.25rem; }
.nav a { color: #cfd6e4; text-decoration: none; padding: 0.4rem 0.8rem; border-radius: 6px; }
.nav a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }

/* Layout */
main { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.layout { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.layout .card { margin-bottom: 0; }

/* Forms */
.field { display: flex; flex-direction: column; margin-bottom: 0.9rem; flex: 1; min-width: 0; }
.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
label { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.3rem; }
input[type="text"], input[type="search"], textarea, select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }
.form-error { background: #fdecec; color: var(--danger); border: 1px solid #f5c2c2; padding: 0.5rem 0.75rem; border-radius: 6px; font-size: 0.9rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-block;
  font: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover { background: #f0f2f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0b4b4; }
.btn-danger:hover { background: #fdecec; }
.btn-small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
#create-form .btn-primary { width: 100%; }

/* Toolbar */
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 0.5rem; }
.toolbar { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1rem; }
.toolbar-row { display: flex; gap: 0.5rem; }
.toolbar-row select { width: auto; }
.filter-group { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.filter { font: inherit; font-size: 0.88rem; padding: 0.35rem 0.85rem; border-radius: 999px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.filter.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Task list */
.task-list { list-style: none; padding: 0; margin: 0; }
.task { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.8rem 0.25rem; border-top: 1px solid var(--border); }
.task:first-child { border-top: none; }
.check input { width: 1.2rem; height: 1.2rem; margin-top: 0.2rem; cursor: pointer; }
.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; word-wrap: break-word; }
.task-desc { color: var(--muted); font-size: 0.9rem; word-wrap: break-word; }
.task-meta { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.3rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap; }
.task-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task.overdue .due { color: var(--danger); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 2rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.badge { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.prio-hoch { background: #fde2e2; color: #a12626; }
.prio-mittel { background: #fff1d6; color: #8a5300; }
.prio-tief { background: #e1f3e8; color: #17703d; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
.stat { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; align-items: center; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.stat-open .stat-value { color: var(--primary); }
.stat-done .stat-value { color: var(--success); }
.stat-overdue .stat-value { color: var(--danger); }
.progress { height: 14px; background: #e6e9ef; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--success); transition: width 0.4s; }
.prio-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.prio-list .badge { min-width: 70px; text-align: center; margin-right: 0.5rem; }

/* Toasts */
#toast-container { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 0.65rem 1rem; border-radius: 8px; box-shadow: var(--shadow); transition: opacity 0.4s; max-width: 320px; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast.hide { opacity: 0; }

/* Auth */
.user-area { display: flex; align-items: center; gap: 0.6rem; color: #cfd6e4; font-size: 0.9rem; }
.btn-ghost { background: transparent; color: #cfd6e4; border-color: rgba(255, 255, 255, 0.3); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.auth { max-width: 440px; }
.btn-block { width: 100%; }
.password-wrap { display: flex; gap: 0.4rem; }
.password-wrap input { flex: 1; min-width: 0; }
.auth-switch { text-align: center; margin: 1rem 0 0; font-size: 0.9rem; }
.auth-switch a { color: var(--primary); }
.rules { list-style: none; padding: 0; margin: 0.5rem 0 0; font-size: 0.85rem; color: var(--muted); }
.rules li::before { content: "✗ "; color: var(--danger); font-weight: 700; }
.rules li.ok { color: var(--success); }
.rules li.ok::before { content: "✓ "; color: var(--success); }

.footer { color: var(--muted); font-size: 0.8rem; text-align: center; padding-bottom: 1.5rem; }

/* Responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .task { flex-wrap: wrap; }
  .task-actions { width: 100%; padding-left: 2rem; }
  .toolbar-row { flex-direction: column; }
  .toolbar-row select { width: 100%; }
  .stat-value { font-size: 1.6rem; }
}
