﻿:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #166534;
  --warn: #f59e0b;
  --info: #3b82f6;
  --danger: #ef4444;
  --done: #10b981;
  --shadow-toolbar: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-dialog: 0 20px 50px rgba(0, 0, 0, 0.45);
  --row-hover: rgba(255, 255, 255, 0.02);
  --list-divider: rgba(255, 255, 255, 0.04);
  --edit-highlight: rgba(34, 197, 94, 0.04);
  --backdrop: rgba(0, 0, 0, 0.55);
  --danger-soft: #fca5a5;
  --danger-hover-bg: rgba(239, 68, 68, 0.15);
  --accent-soft-bg: rgba(34, 197, 94, 0.08);
  --accent-soft-hover: rgba(34, 197, 94, 0.15);
  --focus-ring: rgba(34, 197, 94, 0.2);
  --resize-grip: rgba(34, 197, 94, 0.35);
  --resize-grip-active: rgba(34, 197, 94, 0.5);
  --badge-offen-bg: #374151;
  --badge-offen-fg: #d1d5db;
  --badge-arbeit-bg: #422006;
  --badge-arbeit-fg: #fcd34d;
  --badge-erledigt-bg: #134e4a;
  --badge-erledigt-fg: #5eead4;
  --badge-vorschlag-bg: #1e3a5f;
  --badge-vorschlag-fg: #93c5fd;
  --badge-besprechen-bg: #422006;
  --badge-besprechen-fg: #fcd34d;
  --badge-todo-bg: #14532d;
  --badge-todo-fg: #86efac;
  --primary-btn-fg: #fff;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e9eef5;
  --border: #cdd6e3;
  --text: #142030;
  --muted: #5a6a7e;
  --accent: #16a34a;
  --accent-dim: #15803d;
  --warn: #d97706;
  --info: #2563eb;
  --danger: #dc2626;
  --done: #059669;
  --shadow-toolbar: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-dialog: 0 16px 40px rgba(15, 23, 42, 0.12);
  --row-hover: rgba(0, 0, 0, 0.025);
  --list-divider: rgba(0, 0, 0, 0.06);
  --edit-highlight: rgba(22, 163, 74, 0.07);
  --backdrop: rgba(15, 23, 42, 0.35);
  --danger-soft: #b91c1c;
  --danger-hover-bg: rgba(220, 38, 38, 0.1);
  --accent-soft-bg: rgba(22, 163, 74, 0.08);
  --accent-soft-hover: rgba(22, 163, 74, 0.14);
  --focus-ring: rgba(22, 163, 74, 0.2);
  --resize-grip: rgba(22, 163, 74, 0.35);
  --resize-grip-active: rgba(22, 163, 74, 0.5);
  --badge-offen-bg: #e5e7eb;
  --badge-offen-fg: #374151;
  --badge-arbeit-bg: #fef3c7;
  --badge-arbeit-fg: #92400e;
  --badge-erledigt-bg: #ccfbf1;
  --badge-erledigt-fg: #0f766e;
  --badge-vorschlag-bg: #dbeafe;
  --badge-vorschlag-fg: #1d4ed8;
  --badge-besprechen-bg: #fef3c7;
  --badge-besprechen-fg: #92400e;
  --badge-todo-bg: #dcfce7;
  --badge-todo-fg: #166534;
  --primary-btn-fg: #fff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding: 2rem 1rem 4rem;
}

.container { max-width: 1100px; margin: 0 auto; }

header {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

header .subtitle {
  color: var(--muted);
  font-size: 1rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.meta-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.meta-card strong {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

nav.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}

nav.toc h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

nav.toc ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

nav.toc a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
}

nav.toc a:hover { text-decoration: underline; }

section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

section h3 {
  font-size: 1rem;
  margin: 1.25rem 0 0.75rem;
  color: var(--accent);
}

section h4 {
  font-size: 0.9rem;
  margin: 1rem 0 0.5rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
}

.badge-vorschlag { background: var(--badge-vorschlag-bg); color: var(--badge-vorschlag-fg); }
.badge-besprechen { background: var(--badge-besprechen-bg); color: var(--badge-besprechen-fg); }
.badge-todo { background: var(--badge-todo-bg); color: var(--badge-todo-fg); }
.badge-erledigt { background: var(--badge-erledigt-bg); color: var(--badge-erledigt-fg); }
.badge-offen { background: var(--badge-offen-bg); color: var(--badge-offen-fg); }
.badge-arbeit { background: var(--badge-arbeit-bg); color: var(--badge-arbeit-fg); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: visible;
}

table.resizable-table {
  table-layout: fixed;
  width: 100%;
  max-width: 100%;
}

table.resizable-table th {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

table.resizable-table td {
  box-sizing: border-box;
}

.col-resize-grip {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  touch-action: none;
}

.col-resize-grip:hover,
.col-resize-grip.active {
  background: var(--resize-grip);
}

.col-resize-grip.active {
  background: var(--resize-grip-active);
}

body.col-resizing {
  cursor: col-resize;
  user-select: none;
}

th.col-nummer,
td.col-nummer {
  width: 3rem;
  min-width: 3rem;
  max-width: 4rem;
  text-align: center;
  white-space: nowrap;
  font-weight: 700;
  color: var(--muted);
}

th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table[data-editable-list] tbody td:first-child,
table[data-editable-list] thead th:first-child {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

table[data-editable-list] tbody td:first-child {
  max-width: 0;
}

/* Alle Tabellen: Zellen und Textfelder wachsen per CSS mit dem Inhalt */
table[data-editable-list] td {
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
  overflow: visible;
  height: auto;
}

table[data-editable-list] td .table-field {
  display: block;
  width: 100%;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
  min-height: 2.4em;
  overflow: hidden;
  resize: none;
  field-sizing: content;
}

body.edit-mode table[data-editable-list] td .table-field {
  resize: vertical;
  min-height: 3em;
}

table[data-editable-list] td .person-input {
  min-height: 1.6em;
}

table[data-list-type="finance-table"] tbody td:nth-child(1),
table[data-list-type="finance-table"] tbody td:nth-child(2) {
  max-width: 0;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: break-word;
}

table.resizable-table tbody td:first-child {
  overflow: visible;
}

th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

tr:hover td { background: var(--row-hover); }

ul.checklist { list-style: none; }

ul.checklist li {
  padding: 0.4rem 0 0.4rem 1.5rem;
  position: relative;
  border-bottom: 1px solid var(--list-divider);
}

ul.checklist li::before {
  content: "☐";
  position: absolute;
  left: 0;
  color: var(--muted);
}

.note {
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid var(--warn);
  padding: 0.75rem 1rem;
  border-radius: 0 8px 8px 0;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.note-info {
  background: rgba(59, 130, 246, 0.1);
  border-left-color: var(--info);
}

.mail-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin: 0.75rem 0;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.team-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.team-card h4 { margin-top: 0; color: var(--text); }

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2rem;
}

.edit-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-toolbar);
}

.edit-toolbar-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-right: 0.25rem;
}

.edit-toolbar button {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.edit-toolbar button:hover { border-color: var(--accent); }

.edit-toolbar button.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--primary-btn-fg);
}

.edit-toolbar button.danger {
  border-color: var(--danger);
  color: var(--danger-soft);
}

.edit-toolbar button.theme-toggle {
  flex-shrink: 0;
}

.edit-toolbar .toolbar-spacer {
  flex: 1;
  min-width: 0.5rem;
}

.edit-toolbar button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.save-hint {
  font-size: 0.8rem;
  color: var(--accent);
  flex-shrink: 0;
}

.person-input,
.editable-input {
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  color: inherit;
  font: inherit;
  width: 100%;
  min-width: 4rem;
  padding: 0.1rem 0;
  border-radius: 0;
}

textarea.editable-input[data-field="aufgabe"],
.editable-input.aufgabe-input {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
  min-height: 2.4em;
  resize: none;
  field-sizing: content;
}

body.edit-mode textarea.editable-input[data-field="aufgabe"],
body.edit-mode .editable-input.aufgabe-input {
  resize: vertical;
  min-height: 3em;
}

.person-input:focus,
.editable-input:focus {
  outline: none;
}

body.edit-mode .person-input,
body.edit-mode .editable-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
}

body.edit-mode .person-input:hover,
body.edit-mode .editable-input:hover {
  border-color: var(--accent);
}

body.edit-mode td:has(.person-input),
body.edit-mode td:has(.editable-input),
body.edit-mode .meta-card:has(.person-input),
body.edit-mode .meta-card:has(.editable-input),
body.edit-mode .team-card:has(.person-input),
body.edit-mode .team-card:has(.editable-input),
body.edit-mode li:has(.editable-input) {
  background: var(--edit-highlight);
}

.person-input[readonly],
.editable-input[readonly] {
  cursor: default;
}

body.edit-mode .person-input[readonly],
body.edit-mode .editable-input[readonly] {
  cursor: text;
}

.editable-input.status-input[readonly],
select.status-select {
  width: auto;
  min-width: 6.5rem;
  max-width: 100%;
  text-align: center;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: default;
}

.editable-input.status-input.status-offen,
select.status-select.status-offen { background: var(--badge-offen-bg); color: var(--badge-offen-fg); }
.editable-input.status-input.status-arbeit,
select.status-select.status-arbeit { background: var(--badge-arbeit-bg); color: var(--badge-arbeit-fg); }
.editable-input.status-input.status-erledigt,
select.status-select.status-erledigt { background: var(--badge-erledigt-bg); color: var(--badge-erledigt-fg); }

select.status-select[disabled] {
  pointer-events: none;
}

table[data-editable-list] td:has([data-field="status"]),
table[data-editable-list] td:has(.badge) {
  cursor: pointer;
}

body.edit-mode select.status-select {
  border: 1px solid var(--accent);
  border-radius: 6px;
  text-align: left;
  font-weight: normal;
  font-size: inherit;
  padding: 0.35rem 0.5rem;
  appearance: auto;
  -webkit-appearance: auto;
  cursor: pointer;
  min-width: 8rem;
}

.edit-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  display: none;
}

body.edit-mode .edit-hint { display: block; }

.col-actions {
  display: none;
  width: 2.75rem;
  text-align: center;
}

body.edit-mode .col-actions { display: table-cell; }

.row-delete,
.item-delete {
  display: none;
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger-soft);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.15rem 0.45rem;
}

body.edit-mode .row-delete,
body.edit-mode .item-delete { display: inline-flex; }

.row-delete:hover,
.item-delete:hover {
  background: var(--danger-hover-bg);
}

ul.checklist li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

ul.checklist li .item-delete {
  position: absolute;
  left: -0.15rem;
  top: 0.45rem;
  padding: 0.1rem 0.35rem;
  font-size: 0.85rem;
}

ul.checklist li:has(.item-delete) {
  padding-left: 1.75rem;
}

.list-add-btn {
  display: none;
  margin-top: 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  border: 1px dashed var(--accent);
  background: var(--accent-soft-bg);
  color: var(--accent);
  cursor: pointer;
}

.list-add-btn:hover {
  background: var(--accent-soft-hover);
}

body.edit-mode .list-add-btn { display: inline-flex; }

.quick-edit-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: -0.25rem 0 1rem;
}

table[data-editable-list] tbody td:not(.col-actions),
.team-card:has([data-store-key]),
.team-card:has([data-person-key]),
.meta-card:has([data-store-key]),
.meta-card:has([data-person-key]),
.editable-text-host,
[data-editable-text] {
  cursor: pointer;
}

.editable-text-host .editable-input,
[data-editable-text] .editable-input {
  width: 100%;
}

header h1 .editable-input {
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

header .subtitle .editable-input {
  font-size: inherit;
  color: inherit;
}

.meta-card .editable-input {
  margin-top: 0.25rem;
}

.mail-block .editable-input,
.note .editable-input,
footer .editable-input {
  white-space: pre-wrap;
  line-height: 1.55;
}

textarea.editable-input[data-field="betrag"],
.editable-input.betrag-input {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
  min-height: 2.4em;
  resize: none;
  field-sizing: content;
}

body.edit-mode textarea.editable-input[data-field="betrag"],
body.edit-mode .editable-input.betrag-input {
  resize: vertical;
  min-height: 3em;
}

textarea.editable-input[data-field="content"],
.editable-input.content-input {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.45;
  min-height: 2.4em;
  resize: none;
  field-sizing: content;
}

body.edit-mode textarea.editable-input[data-field="content"],
body.edit-mode .editable-input.content-input {
  resize: vertical;
  min-height: 3em;
}

body.edit-mode .editable-text-host,
body.edit-mode [data-editable-text] {
  background: var(--edit-highlight);
  border-radius: 8px;
}

.quick-editor {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.quick-editor[hidden] {
  display: none !important;
}

.quick-editor-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
}

.quick-editor-dialog {
  position: relative;
  width: min(640px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-dialog);
  padding: 1rem 1.1rem 0.85rem;
}

.quick-editor-title {
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.quick-editor-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 0.6rem 0.75rem;
}

.quick-editor-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.quick-editor-textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
  white-space: pre-wrap;
}

.quick-editor-dialog select.quick-editor-input {
  appearance: auto;
  -webkit-appearance: auto;
  cursor: pointer;
}

.quick-editor-hint {
  margin-top: 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
}

@media print {
  .col-actions, .row-delete, .item-delete, .list-add-btn { display: none !important; }
  .edit-toolbar, .edit-hint, .quick-edit-hint, .quick-editor { display: none !important; }
  body.edit-mode .person-input,
  body.edit-mode .editable-input {
    background: transparent;
    border: none;
    padding: 0;
  }
  body { background: #fff; color: #000; padding: 0; }
  section, header, nav { break-inside: avoid; border-color: #ccc; background: #fff; }
  .badge { border: 1px solid #999; }
}

/* Auth & landing pages */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-dialog);
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.auth-subtitle {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.auth-card label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.auth-card input,
.auth-card select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
}

.auth-card button.primary {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-card button.secondary {
  margin-top: 1rem;
  width: 100%;
}

.auth-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.landing-card {
  max-width: 480px;
}

.landing-nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.landing-link {
  display: block;
  text-align: center;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  background: var(--surface-2);
}

.landing-link.primary {
  background: var(--accent);
  color: var(--primary-btn-fg);
  border-color: var(--accent-dim);
  font-weight: 600;
}

.landing-link:hover {
  filter: brightness(1.05);
}

.role-hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
}

.page-nav a {
  color: var(--accent);
  text-decoration: none;
}

button.small {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.users-card {
  max-width: 520px;
}

.users-form {
  margin-bottom: 1rem;
}

.user-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.user-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.visitor-read-only .list-add-btn,
.visitor-read-only .row-delete,
.visitor-read-only .item-delete,
.visitor-read-only .col-actions {
  display: none !important;
}
