:root {
  --bg: #f6f8f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --primary-soft: #e6f4f2;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* ---------- Layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}
.brand span {
  color: var(--primary);
}
.nav {
  display: flex;
  gap: 6px;
  flex: 1;
}
.nav a {
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.94rem;
  font-weight: 500;
}
.nav a:hover {
  background: var(--bg);
  text-decoration: none;
}
.nav a.active {
  color: var(--primary);
  background: var(--primary-soft);
}
.logout button {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}
.logout button:hover {
  border-color: var(--muted);
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-head h1 {
  font-size: 1.5rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.head-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}
.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card {
  margin-top: 18px;
}
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.card-body {
  padding: 20px;
}

/* ---------- Table ---------- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tbody tr:hover {
  background: var(--bg);
}
tbody tr:last-child td {
  border-bottom: none;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge.new {
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.badge.in_progress {
  background: #fef9c3;
  color: #854d0e;
}
.badge.done {
  background: var(--success-soft);
  color: #166534;
}
.badge.archived {
  background: #f1f5f9;
  color: var(--muted);
}

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 20px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field.full {
  grid-column: 1 / -1;
}
label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea {
  resize: vertical;
  min-height: 90px;
}
.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}
.checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}
.checkbox label {
  color: var(--text);
  font-weight: 500;
}
.field-error {
  color: var(--danger);
  font-size: 0.8rem;
}
.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  margin: 4px 0 -4px;
  grid-column: 1 / -1;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
}
.btn:hover {
  background: var(--primary-dark);
  text-decoration: none;
}
.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover {
  background: var(--bg);
}
.btn.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: #fecaca;
}
.btn.danger:hover {
  background: var(--danger-soft);
}
.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 22px;
  flex-wrap: wrap;
}
.form-actions .spacer {
  flex: 1;
}

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 18px;
}
.alert.success {
  background: var(--success-soft);
  color: #166534;
  border: 1px solid #bbf7d0;
}
.alert.error {
  background: var(--danger-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card .card-body {
  padding: 28px;
}
.login-brand {
  text-align: center;
  margin-bottom: 22px;
}
.login-brand .brand {
  font-size: 1.3rem;
}
.login-brand p {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 6px 0 0;
}

/* ---------- Filter tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.tab:hover {
  text-decoration: none;
  border-color: var(--muted);
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.tab-count {
  font-size: 0.78rem;
  background: rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  padding: 1px 8px;
  font-weight: 600;
}
.tab.active .tab-count {
  background: rgba(255, 255, 255, 0.25);
}

/* ---------- Segmented status control ---------- */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}
.seg-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
button.seg-item:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.seg-item.current {
  cursor: default;
  color: #fff;
  border-color: transparent;
}
.seg-item.current.new {
  background: var(--primary);
}
.seg-item.current.in_progress {
  background: var(--warning);
}
.seg-item.current.done {
  background: var(--success);
}
.seg-item.current.archived {
  background: var(--muted);
}
.seg-lg .seg-item {
  font-size: 0.9rem;
  padding: 9px 16px;
}

/* ---------- Consent rows ---------- */
.consent-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  padding: 8px 0;
}
.consent-row + .consent-row {
  border-top: 1px solid var(--border);
}
.consent-row .yes {
  color: var(--success);
  font-weight: 600;
}
.consent-row .no {
  color: var(--muted);
  font-weight: 600;
}

/* ---------- File preview ---------- */
.file-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.file-preview img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.file-preview iframe {
  width: 100%;
  height: 620px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* ---------- KPI stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-head svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
  flex-shrink: 0;
}
.stat .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}

/* ---------- Status bar (Detailseite) ---------- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  margin-bottom: 18px;
}
.status-bar-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}
.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 6px;
  color: var(--text);
  line-height: 1.2;
}
.stat .value small {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-left: 4px;
}
.stat .value.text {
  font-size: 1.05rem;
  font-weight: 600;
  word-break: break-word;
}

/* ---------- Detail: two-column layout ---------- */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.detail-main > .card:first-child,
.detail-side > .card:first-child {
  margin-top: 0;
}
.detail-side {
  position: sticky;
  top: 80px;
}
/* Kompaktere Rechnungs-Vorschau in der Seitenspalte */
.detail-side .file-preview iframe {
  height: 380px;
}
.detail-side .seg {
  flex-direction: column;
  align-items: stretch;
}
.detail-side .seg-item {
  text-align: center;
}

@media (max-width: 900px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }
  .detail-side {
    position: static;
  }
  .detail-side .seg {
    flex-direction: row;
  }
}

/* ---------- Read-only data grid ---------- */
.data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 28px;
}
.data-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.data-item .k {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}
.data-item .v {
  font-size: 0.98rem;
  word-break: break-word;
}

/* ---------- Icons ---------- */
.icon {
  width: 18px;
  height: 18px;
  vertical-align: -3px;
  color: var(--primary);
}

/* ---------- Clickable table rows ---------- */
table.clickable tbody tr {
  cursor: pointer;
}
.row-open {
  color: var(--primary);
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}

/* ---------- Misc ---------- */
.muted {
  color: var(--muted);
}
.meta-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

@media (max-width: 640px) {
  .form-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }
  .topbar-inner {
    gap: 14px;
  }
  .nav a {
    padding: 8px 8px;
  }
}
