/* === Reset & Variables === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #1a2332;
  --navy-light: #243447;
  --white: #ffffff;
  --bg: #f5f7fa;
  --text: #1a2332;
  --text-muted: #6b7b8d;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Navigation === */
.nav {
  background: var(--navy);
  color: var(--white);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  margin-right: 2rem;
  white-space: nowrap;
}

.nav-collapse {
  display: flex;
  align-items: center;
  flex: 1;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all 0.15s;
}

.nav-link:hover, .nav-link.active {
  color: var(--white);
  background: var(--navy-light);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.nav-user {
  font-size: 0.85rem;
  opacity: 0.7;
}

.btn-ghost {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--white);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-ghost:hover { background: var(--navy-light); }

/* Hamburger */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  margin-left: auto;
}

.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--white);
  margin: 5px 0;
  transition: 0.3s;
}

@media (max-width: 768px) {
  .nav-hamburger { display: block; }
  .nav-collapse {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--navy);
    padding: 1rem;
    gap: 0.25rem;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }
  .nav--open .nav-collapse { display: flex; }
  .nav-links { flex-direction: column; flex: unset; }
  .nav-link { padding: 0.75rem; font-size: 1rem; }
  .nav-right {
    flex-direction: column;
    margin-left: 0;
    border-top: 1px solid var(--navy-light);
    padding-top: 0.75rem;
    margin-top: 0.5rem;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .nav--open .nav-hamburger span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
  .nav--open .nav-hamburger span:nth-child(2) { opacity: 0; }
  .nav--open .nav-hamburger span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }
}

/* === Main === */
.main {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  flex: 1;
}

/* === Typography === */
h1 { font-size: 1.5rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 0.5rem; }
h2 { font-size: 1.2rem; margin-bottom: 0.75rem; }
.text-muted { color: var(--text-muted); font-size: 0.9rem; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-danger { color: var(--danger); }

/* === Stats Row === */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}

.stat-card--danger { border-left-color: var(--danger); }
.stat-card--success { border-left-color: var(--success); }

.stat-number { font-size: 2rem; font-weight: 700; }
.stat-card--danger .stat-number { color: var(--danger); }
.stat-card--success .stat-number { color: var(--success); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* === Todo List === */
.todo-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--white);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 3px solid transparent;
}

.todo-item--overdue { border-left-color: var(--danger); background: var(--danger-bg); }
.todo-item--done { opacity: 0.5; }

.todo-status {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  margin-top: 2px;
  transition: all 0.15s;
}

.todo-status--offen:hover { border-color: var(--primary); color: var(--primary); }
.todo-status--in_arbeit { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.todo-status--erledigt { border-color: var(--success); color: var(--white); background: var(--success); }

.todo-status-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  min-width: 52px;
}

.todo-status-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
  white-space: nowrap;
}

.todo-status-label--offen { color: var(--text-muted); }
.todo-status-label--in_arbeit { color: var(--primary); }
.todo-status-label--erledigt { color: var(--success); }

/* === Back Link === */
.back-link {
  display: inline-block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
}

.back-link:hover { color: var(--primary); }

.todo-content { flex: 1; min-width: 0; }
.todo-title { font-weight: 500; word-break: break-word; }
.todo-item--done .todo-title { text-decoration: line-through; }

.todo-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

.todo-project { font-size: 0.8rem; color: var(--text-muted); }

.todo-frist {
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--bg);
  color: var(--text-muted);
}

.todo-frist--overdue { background: var(--danger); color: var(--white); }

.todo-prio {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.todo-prio--1 { background: var(--danger-bg); color: var(--danger); }
.todo-prio--2 { background: var(--warning-bg); color: var(--warning); }
.todo-prio--3 { background: var(--bg); color: var(--text-muted); }

.todo-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0.3;
  transition: opacity 0.15s;
}

.todo-item:hover .todo-actions { opacity: 1; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  font-size: 1rem;
  color: var(--text-muted);
}

.btn-icon:hover { background: var(--bg); }
.btn-icon--danger:hover { color: var(--danger); background: var(--danger-bg); }
.btn-icon--small { font-size: 0.8rem; padding: 0.1rem 0.3rem; }

/* === Todo Beschreibung === */
.todo-beschreibung {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
  white-space: pre-line;
}

/* === Todo Details (Notizen aufklappbar) === */
.todo-details {
  margin-top: 0.5rem;
}

.todo-details-toggle {
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  padding: 0.2rem 0;
}

.todo-details-toggle:hover { text-decoration: underline; }

.todo-notiz-count {
  font-size: 0.7rem;
  background: var(--primary);
  color: var(--white);
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
}

/* === Notizen === */
.notizen-liste {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.notiz-item {
  background: var(--bg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border-left: 3px solid var(--primary);
}

.notiz-text {
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: pre-line;
}

.notiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.25rem;
}

.notiz-datum {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.notizen-leer {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
  font-style: italic;
}

.notiz-form {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.notiz-input {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  resize: vertical;
  font-family: inherit;
}

/* === Todo Add Beschreibung === */
.todo-add-desc {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  resize: vertical;
  font-family: inherit;
}

/* === Todo Add Form === */
.todo-add-form {
  margin-top: 1rem;
  background: var(--white);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.todo-add-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.todo-add-input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.todo-add-select, .todo-add-date {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--white);
}

@media (max-width: 600px) {
  .todo-add-row {
    flex-wrap: wrap;
  }
  .todo-add-input { width: 100%; }
  .todo-add-select, .todo-add-date { flex: 1; }
}

/* === Todo Edit Form === */
.todo-edit-form {
  background: var(--white);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 3px solid var(--primary);
}

.todo-edit-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.todo-edit-input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.todo-edit-desc {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  resize: vertical;
  margin-bottom: 0.5rem;
}

.todo-edit-actions {
  display: flex;
  gap: 0.5rem;
}

/* === Progress Bar === */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar--small { height: 6px; margin-top: 0.5rem; }

.progress-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 4px;
  transition: width 0.3s;
  min-width: 0;
}

/* === Progress Grid === */
.progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}

.progress-card {
  background: var(--white);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s;
}

.progress-card:hover { transform: translateY(-1px); }

.progress-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.progress-card-name { font-weight: 500; flex: 1; }
.progress-card-count { font-size: 0.8rem; color: var(--text-muted); }

/* === Project Badge === */
.project-badge {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* === Project Grid === */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.project-card {
  background: var(--white);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: transform 0.1s, box-shadow 0.1s;
}

.project-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

.project-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.project-card-header h3 { font-size: 1rem; }
.project-card-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.75rem; }

.project-card-footer {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* === Page Header === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.page-header h1 { margin-bottom: 0; }
.page-header-actions { display: flex; gap: 0.5rem; }

/* === Filter Tabs === */
.filter-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.filter-tab {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: all 0.15s;
}

.filter-tab:hover { background: var(--white); }
.filter-tab.active { background: var(--white); color: var(--text); font-weight: 500; box-shadow: var(--shadow); }

/* === Forms === */
.form-card {
  background: var(--white);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 500px;
}

.form-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  margin-top: 1rem;
}

.form-card label:first-child { margin-top: 0; }

.form-card input[type="text"],
.form-card input[type="email"],
.form-card input[type="password"],
.form-card textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.form-card input[type="color"] {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

.form-actions .btn-ghost {
  color: var(--text-muted);
  border-color: var(--border);
}

/* === Login === */
.login-wrap {
  max-width: 360px;
  margin: 4rem auto;
  text-align: center;
}

.login-wrap h1 { justify-content: center; margin-bottom: 1.5rem; }

.login-form {
  background: var(--white);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}

.login-form label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  margin-top: 1rem;
}

.login-form label:first-of-type { margin-top: 0; }

.login-form input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.login-form .btn { width: 100%; justify-content: center; margin-top: 1.25rem; }

.alert { padding: 0.5rem 0.75rem; border-radius: var(--radius); font-size: 0.85rem; margin-bottom: 0.75rem; }
.alert-error { background: var(--danger-bg); color: var(--danger); }

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .btn { margin-top: 1rem; }

/* === Footer === */
.site-footer {
  text-align: center;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* === Mobile Optimierungen === */
@media (max-width: 480px) {
  .main { padding: 1rem 0.75rem; }
  h1 { font-size: 1.25rem; }

  /* Groessere Touch-Targets */
  .todo-status { width: 36px; height: 36px; min-width: 36px; font-size: 1rem; }
  .todo-status-wrap { min-width: 44px; }
  .btn-icon { padding: 0.4rem 0.5rem; font-size: 1.1rem; }

  /* Todo-Items kompakter */
  .todo-item { padding: 0.6rem 0.75rem; gap: 0.5rem; }
  .todo-actions { opacity: 1; } /* Immer sichtbar auf Touch */
  .todo-title { font-size: 0.95rem; }

  /* Stats kompakter */
  .stat-number { font-size: 1.5rem; }
  .stat-card { padding: 0.75rem; }

  /* Projekt-Grid einspaltig */
  .project-grid { grid-template-columns: 1fr; }
  .progress-grid { grid-template-columns: 1fr; }

  /* Notiz-Form vertikal */
  .notiz-form { flex-direction: column; }
  .notiz-form .btn { align-self: flex-end; }

  /* Todo-Add vertikal */
  .todo-add-row { flex-direction: column; align-items: stretch; }
  .todo-add-row .btn { align-self: flex-end; }

  /* Page-Header stacking */
  .page-header { flex-direction: column; gap: 0.5rem; }
  .page-header-actions { align-self: flex-start; }

  /* Edit-Form */
  .todo-edit-row { flex-direction: column; }
}

/* Safe area for notched iPhones */
@supports (padding: env(safe-area-inset-top)) {
  .nav { padding-top: env(safe-area-inset-top); }
  .main { padding-left: max(0.75rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right)); }
}

/* === Kalender === */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.cal-title { margin: 0; font-size: 1.3rem; min-width: 180px; text-align: center; }

.cal-nav-btn {
  color: var(--text) !important;
  border-color: var(--border) !important;
  font-size: 1.1rem;
  padding: 0.3rem 0.75rem;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.cal-weekday {
  background: var(--navy);
  color: var(--white);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.5rem 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cal-weekend { opacity: 0.7; }

.cal-day {
  background: var(--white);
  min-height: 80px;
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.cal-day--empty { background: var(--bg); }

.cal-day--today { background: #eff6ff; }

.cal-day-number {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  align-self: flex-end;
}

.cal-day-number--today {
  background: var(--primary);
  color: var(--white);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.cal-todo {
  display: block;
  font-size: 0.7rem;
  padding: 0.15rem 0.3rem;
  border-radius: 3px;
  border-left: 3px solid var(--primary);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.cal-todo:hover { background: var(--border); }
.cal-todo--done { opacity: 0.4; text-decoration: line-through; }

/* Kalender Liste */
.cal-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.cal-list-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--white);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cal-list-date {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 45px;
}

.cal-list-project {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 100px;
}

.cal-list-title {
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  flex: 1;
}

.cal-list-title:hover { color: var(--primary); }

/* Kalender Mobile */
@media (max-width: 480px) {
  .cal-day { min-height: 50px; padding: 0.2rem; }
  .cal-day-number { font-size: 0.7rem; }
  .cal-day-number--today { width: 20px; height: 20px; font-size: 0.65rem; }
  .cal-todo { font-size: 0.6rem; padding: 0.1rem 0.2rem; }
  .cal-weekday { font-size: 0.65rem; padding: 0.35rem 0.15rem; }
  .cal-list-project { display: none; }
}

/* Standalone (Homescreen) mode */
@media (display-mode: standalone) {
  .nav {
    padding-top: env(safe-area-inset-top, 20px);
    height: auto;
    min-height: 56px;
  }
  .nav-brand { font-size: 1.2rem; padding: 0.5rem 0; }
  .nav-hamburger { padding: 0.75rem 0.5rem; }
  .nav-hamburger span { width: 26px; height: 3px; }
}
