:root {
  color-scheme: light;
  --club-red: #d3001b;
  --club-red-dark: #8f0012;
  --ink: #172026;
  --muted: #65717a;
  --line: #d8dee4;
  --paper: #ffffff;
  --surface: #f6f8fa;
  --warn: #a15c00;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--surface);
  color: var(--ink);
}

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

button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover {
  border-color: #a9b4bd;
}

.primary {
  background: var(--club-red);
  border-color: var(--club-red);
  color: #fff;
}

.danger {
  color: var(--danger);
}

.document-error {
  color: var(--danger);
  font-weight: 700;
}

.topbar {
  min-height: 92px;
  padding: 18px clamp(16px, 3vw, 34px);
  background: var(--club-red);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 30px;
  letter-spacing: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-actions #currentUser {
  color: #ffe3e7;
}

#pwDialog,
.app-dialog {
  border: none;
  border-radius: 14px;
  padding: 24px;
  width: min(380px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.25);
}

#pwDialog::backdrop,
.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

#pwDialog h3,
.app-dialog h3 {
  margin: 0 0 14px;
}

.app-dialog h4 {
  margin: 14px 0 8px;
}

.pw-form label,
.app-dialog label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.pw-form input,
.app-dialog input,
.app-dialog textarea,
.app-dialog select {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 9px;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-family: inherit;
}

.app-dialog .two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.app-dialog .free-item {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.app-dialog .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pw-error {
  color: var(--danger, #b00020);
  min-height: 1.1em;
  margin: 4px 0 10px;
  font-size: 0.9rem;
}

.eyebrow {
  margin: 0;
  color: #ffe3e7;
  font-size: 13px;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 460px;
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 34px);
}

.workspace,
.detail {
  min-width: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat strong {
  display: block;
  font-size: 24px;
}

.stat span {
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 120px auto;
  gap: 10px;
  margin-bottom: 14px;
}

.billing-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) 90px 90px minmax(300px, 2fr);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.billing-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.billing-actions span {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.batch-result {
  grid-column: 1 / -1;
  color: var(--club-red);
  font-size: 13px;
  min-height: 16px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.sponsor-list {
  display: block;
}

.detail h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.amount {
  font-weight: 700;
  color: var(--club-red);
}

.table-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.sponsor-table,
.mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.sponsor-table th,
.sponsor-table td,
.mini-table th,
.mini-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.sponsor-table th,
.mini-table th {
  background: #f9fafb;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.sponsor-table tbody tr:hover {
  background: #fff6f7;
}

.sponsor-table .money,
.mini-table .money {
  text-align: right;
  white-space: nowrap;
}

.strong {
  color: var(--club-red);
  font-weight: 700;
}

.num {
  white-space: nowrap;
}

.table-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--club-red-dark);
  padding: 0;
  font-weight: 700;
  text-align: left;
}

.muted-row {
  opacity: 0.58;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.status-select {
  min-width: 86px;
  padding: 6px 8px;
  font-weight: 700;
}

.status-select.is-active {
  border-color: #4f8a61;
  background: #edf8f0;
  color: #246337;
}

.status-select.is-archived {
  border-color: #b4b9be;
  background: #f0f1f2;
  color: #626a70;
}

.detail {
  position: sticky;
  top: 18px;
  align-self: start;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.section {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 7px 12px;
  font-size: 14px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.service,
.document {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
}

.service-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.service-head strong {
  font-size: 15px;
}

.service-head button {
  padding: 7px 9px;
  white-space: nowrap;
}

.service-fields,
.metadata-grid {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 5px 10px;
  margin: 9px 0 0;
  font-size: 13px;
}

.mini-table th {
  width: 150px;
}

.editable-metadata th {
  vertical-align: middle;
}

.editable-metadata input,
.editable-metadata textarea {
  border: 1px solid #bcc5cc;
  padding: 8px;
}

.readonly-row {
  background: #f7f8f9;
  color: var(--muted);
}

.readonly-note {
  margin-left: 8px;
  font-size: 11px;
  text-transform: uppercase;
}

.metadata-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 10px;
}

.metadata-actions span {
  color: var(--club-red);
  font-size: 13px;
  margin-right: auto;
}

.mini-table tbody tr:last-child td,
.mini-table tbody tr:last-child th,
.sponsor-table tbody tr:last-child td {
  border-bottom: 0;
}

.metadata-grid {
  grid-template-columns: 150px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.service-fields dt,
.metadata-grid dt {
  color: var(--muted);
}

.service-fields dd,
.metadata-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.service-hint {
  margin-top: 9px;
}

.inline-form,
.service-form,
.doc-form {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 8px;
}

.service-form {
  grid-template-columns: 1fr 1fr 1.5fr 100px 140px 130px 80px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fffafa;
}

.position-grid {
  display: grid;
  grid-template-columns: 140px 160px minmax(170px, 1fr) 90px 140px 100px 70px 90px auto;
  gap: 6px;
  align-items: center;
}

.position-grid input,
.position-grid select {
  padding: 7px;
  min-width: 0;
}

.position-source {
  color: var(--muted);
  font-size: 12px;
}

.doc-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.span-2 {
  grid-column: 1 / -1;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label textarea,
label select {
  color: var(--ink);
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.notice {
  border: 1px solid #f0c36d;
  background: #fff8e5;
  color: var(--warn);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.tabbar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--line);
}

.tab {
  border: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 16px;
}

.tab-active {
  color: var(--club-red);
  background: var(--paper);
  box-shadow: inset 0 -3px 0 var(--club-red);
}

.documents-view .toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.doc-status {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.doc-status.status-erstellt {
  background: #fff8e5;
  color: var(--warn);
}

.doc-status.status-versendet {
  background: #e8f1fb;
  color: #1d4f91;
}

.doc-status.status-bezahlt {
  background: #e8f7ec;
  color: #1c7c3c;
}

.doc-status.status-fehlerhaft {
  background: #fdecea;
  color: var(--danger);
}

.doc-totals {
  margin-top: 10px;
  color: var(--muted);
}

.th-sub {
  font-weight: 400;
  font-size: 11px;
  color: var(--club-red);
  white-space: nowrap;
}

.one-time-panel {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #f0c36d;
  background: #fff8e5;
  border-radius: 8px;
}

.stat-open strong {
  color: var(--warn);
}

.stat-paid strong {
  color: #1c7c3c;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .detail {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats,
  .toolbar,
  .billing-panel,
  .form-grid,
  .service-form,
  .position-grid,
  .doc-form {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .service-head {
    align-items: stretch;
    flex-direction: column;
  }
}
