@import url('https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,500;6..72,600&family=Work+Sans:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --ink: #1C2B26;
  --paper: #EAE7DC;
  --paper-2: #F4F2EA;
  --green: #2C4A3C;
  --green-light: #3E6A54;
  --brass: #A9803F;
  --brick: #8B3A2E;
  --line: #C9C4B4;
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body { margin: 0; font-family: 'Work Sans', sans-serif; background: var(--paper); color: var(--ink); overflow-x: hidden; }

/* Login / Setup */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 32px; width: 100%; max-width: 360px; text-align: center;
}
.brand-mark-lg {
  font-family: 'Newsreader', serif; font-size: 30px; font-weight: 600;
  color: var(--paper-2); background: #050810; width: 52px; height: 52px;
  border-radius: 6px; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px;
  overflow: hidden;
}
.login-card h1 { font-family: 'Newsreader', serif; font-size: 22px; margin: 0 0 4px; }
.login-card label { display: block; text-align: left; font-size: 13px; color: #52493d; margin-top: 14px; }
.login-card input {
  width: 100%; margin-top: 5px; padding: 9px 10px; border-radius: 4px; border: 1px solid var(--line);
  font-family: inherit; font-size: 14px;
}
.error-msg { background: #F3DEDA; color: var(--brick); padding: 8px 12px; border-radius: 4px; font-size: 13px; margin-top: 14px; }

/* Layout */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 26px; border-bottom: 1px solid var(--line); background: var(--paper-2);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-family: 'Newsreader', serif; font-size: 24px; font-weight: 600;
  color: var(--paper-2); background: #050810; width: 36px; height: 36px;
  border-radius: 3px; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.brand-title { font-family: 'Newsreader', serif; font-size: 18px; font-weight: 600; }
.brand-sub { font-size: 12px; color: #6b6255; }
.tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tab {
  display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 4px;
  border: none; background: transparent; color: var(--ink); font-size: 14px; cursor: pointer; font-family: inherit;
}
.tab:hover { background: rgba(44,74,60,0.08); }
.tab.active { background: var(--green); color: var(--paper-2); }

.tab-dropdown { position: relative; }
.tab-dropdown-toggle { display: flex; align-items: center; gap: 5px; }
.tab-dropdown-toggle .caret { font-size: 10px; transition: transform 0.15s; }
.tab-dropdown.open .tab-dropdown-toggle .caret { transform: rotate(180deg); }
.tab-dropdown-toggle.has-active { background: rgba(44,74,60,0.14); font-weight: 600; }
.tab-dropdown-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 24px rgba(28,43,38,0.16); min-width: 200px; flex-direction: column; gap: 2px;
}
.tab-dropdown.open .tab-dropdown-menu { display: flex; }
.tab-dropdown-menu .tab { width: 100%; text-align: left; justify-content: flex-start; }

.content { max-width: 1100px; margin: 0 auto; padding: 28px 24px 80px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
h1 { font-family: 'Newsreader', serif; font-size: 26px; font-weight: 600; margin: 0 0 4px; }
h2 { font-family: 'Newsreader', serif; font-size: 19px; font-weight: 600; margin: 0 0 14px; }
.muted { color: #6b6255; font-size: 13px; margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 4px;
  border: 1px solid var(--green); font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  background: transparent; color: var(--green);
}
.btn.primary { background: var(--green); color: var(--paper-2); }
.btn.primary:hover { background: var(--green-light); }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.danger { border-color: var(--brick); color: var(--brick); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.search-row {
  display: flex; align-items: center; gap: 8px; background: var(--paper-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 8px 12px; margin-bottom: 18px; max-width: 360px;
}
.search-row input { border: none; background: transparent; outline: none; font-family: inherit; font-size: 14px; width: 100%; }

.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 6px; padding: 20px; margin-bottom: 18px; }
.table-wrap { background: var(--paper-2); border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 14px; font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; color: #6b6255; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid #DEDACD; }
tbody tr:last-child td { border-bottom: none; }
.mono { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.icon-btn { background: none; border: none; cursor: pointer; padding: 6px; border-radius: 4px; color: #6b6255; font-size: 15px; }
.icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--ink); }
.icon-btn.danger:hover { color: var(--brick); background: rgba(139,58,46,0.1); }

.pill { font-size: 11.5px; padding: 3px 9px; border-radius: 20px; font-weight: 500; }
.pill.warn { background: #F1E2CE; color: #8A6A2F; }
.pill.ok { background: #DCE7DE; color: #2C4A3C; }
.pill.danger { background: #F3E4DF; color: #8B3A2E; }

.stempel {
  display: inline-block; font-family: 'JetBrains Mono', monospace; font-size: 10.5px; letter-spacing: 0.06em;
  text-transform: uppercase; border-radius: 3px; padding: 2px 8px; transform: rotate(-2deg); opacity: 0.9;
  border: 1.5px solid currentColor;
}
.stempel.aktiv { color: #2C4A3C; }
.stempel.inaktiv { color: #8A6A2F; }
.stempel.ausgetreten { color: #8B3A2E; }
.stempel.interessent { color: #3B6E91; }

.empty { padding: 40px; text-align: center; color: #6b6255; background: var(--paper-2); border: 1px dashed var(--line); border-radius: 6px; }

.overlay { position: fixed; inset: 0; background: rgba(28,43,38,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.panel { background: var(--paper-2); border-radius: 8px; padding: 24px; width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto; border: 1px solid var(--line); }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #52493d; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; padding: 8px 10px; border-radius: 4px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); width: 100%;
}
.field input[type="checkbox"], .field input[type="radio"] {
  width: auto; padding: 0; flex-shrink: 0; margin: 0; vertical-align: middle;
}
.field textarea { resize: vertical; }

.template-tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.chip { font-family: inherit; font-size: 13px; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--paper-2); cursor: pointer; color: var(--ink); }
.chip.active { background: var(--brass); border-color: var(--brass); color: #fff; }

.briefe-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
.editor textarea { width: 100%; font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.5; }
.placeholder-help { margin-top: 10px; font-size: 12px; color: #6b6255; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.placeholder-help code { background: #DEDACD; padding: 2px 6px; border-radius: 3px; font-family: 'JetBrains Mono', monospace; }

.preview-label { font-size: 12px; color: #6b6255; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.letter-preview { background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 28px; font-size: 13px; line-height: 1.6; min-height: 320px; box-shadow: 0 2px 6px rgba(0,0,0,0.06); }
.letter-head { margin-bottom: 24px; }
.letter-absender { font-size: 11px; color: #857c6d; white-space: pre-line; }
.letter-vereinsname { font-family: 'Newsreader', serif; font-weight: 600; font-size: 15px; margin-top: 2px; color: var(--green); }
.letter-subject { font-weight: 600; margin: 18px 0 14px; }
.letter-body { white-space: pre-line; }

.print-bar { display: flex; align-items: center; gap: 20px; margin-top: 24px; padding: 16px 18px; background: var(--paper-2); border: 1px solid var(--line); border-radius: 6px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--green); color: #fff; padding: 10px 18px; border-radius: 6px; display: flex; align-items: center; gap: 8px; font-size: 13.5px; z-index: 100; box-shadow: 0 4px 14px rgba(0,0,0,0.2); }
.toast.error { background: var(--brick); }

.hint { text-align: center; font-size: 11.5px; color: #857c6d; padding: 20px 0 0; }

/* PDF-Vorlagen Tab */
.pdf-card { display: grid; grid-template-columns: 260px 1fr; gap: 20px; }
.pdf-canvas-wrap { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 4px; overflow: auto; max-height: 500px; }
.pdf-canvas-wrap canvas { display: block; cursor: crosshair; }
.pdf-field-box { position: absolute; border: 2px dashed var(--brick); background: rgba(139,58,46,0.12); pointer-events: none; }
.gk-aktiv-feld.active, .f-aktiv-feld.active { background: var(--green); color: #fff; border-color: var(--green); }
.upload-drop { border: 1.5px dashed var(--line); border-radius: 6px; padding: 24px; text-align: center; color: #6b6255; margin-bottom: 18px; }

.page-outline-wrap { display: flex; align-items: flex-start; justify-content: center; padding: 16px; background: #EDEBE2; }
.page-outline { position: relative; background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,0.08); cursor: crosshair; }

.logo-preview { width: 100%; max-width: 220px; height: 90px; border: 1px dashed var(--line); border-radius: 4px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; }
.avatar-placeholder { width: 32px; height: 32px; border-radius: 50%; background: var(--brass); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.avatar-lg { width: 72px; height: 72px; border-radius: 50%; overflow: hidden; background: var(--brass); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 600; font-family: 'JetBrains Mono', monospace; flex-shrink: 0; }
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

.import-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 10px; }
.import-table th, .import-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.import-table select { font-size: 12px; padding: 4px; }

.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.letter-logo { max-height: 56px; max-width: 220px; display: block; margin-bottom: 10px; object-fit: contain; }

.zone-toggle { display: flex; gap: 8px; margin-bottom: 10px; }
.zone-toggle button { font-family: inherit; font-size: 12.5px; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.zone-toggle button.active.zone-adr { background: var(--brick); border-color: var(--brick); color: #fff; }
.zone-toggle button.active.zone-abs { background: var(--green); border-color: var(--green); color: #fff; }
.pdf-field-box.abs-box { border-color: var(--green); background: rgba(44,74,60,0.12); }
.env-logo-preview { max-width: 100%; max-height: 100%; object-fit: contain; }

.list-columns { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.list-columns label { display: flex; align-items: center; gap: 6px; font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; cursor: pointer; }
.custom-col-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; }
.custom-col-row .field { flex: 1; }
.custom-col-row .field.w-fixed { flex: 0 0 100px; }

.print-list-table { display: none; }

.print-area { display: none; }
.print-address-area { display: none; }

@media print {
  .no-print { display: none !important; }
  .print-area { display: block !important; }
  .letter-page { page-break-after: always; padding: 2cm; font-family: 'Work Sans', sans-serif; font-size: 13px; line-height: 1.6; }
  .letter-page:last-child { page-break-after: auto; }

  .print-address-area { display: block !important; }
  .addr-page { position: relative; page-break-after: always; }
  .addr-page:last-child { page-break-after: auto; }
  .addr-box { position: absolute; font-family: 'Work Sans', sans-serif; white-space: pre-line; line-height: 1.4; }
  .sender-box { position: absolute; font-family: 'Work Sans', sans-serif; line-height: 1.3; }
  .sender-box img { display: block; max-height: 100%; max-width: 100%; object-fit: contain; margin-bottom: 3px; }
  .qr-inline-box { position: absolute; text-align: center; }
  .qr-inline-box canvas, .qr-inline-box img { width: 100%; height: auto; display: block; }
  .qr-inline-label { font-size: 6.5pt; color: #333; margin-top: 1mm; }
  @page { margin: 0; }

  .print-list-table { display: block !important; width: 100%; }
  .print-list-table h1 { font-family: 'Newsreader', serif; font-size: 20px; margin: 0 0 14px; }
  .print-list-table table { width: 100%; border-collapse: collapse; font-size: 11px; }
  .print-list-table th, .print-list-table td { border: 1px solid #999; padding: 5px 7px; text-align: left; }
  .print-list-table thead { display: table-header-group; }
  .print-list-table tr { page-break-inside: avoid; }
}

.stat-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 6px; padding: 18px; text-align: center; min-width: 0; overflow: hidden; }
.stat-value { font-family: 'Newsreader', serif; font-size: 28px; font-weight: 600; color: var(--green); white-space: nowrap; }
/* Kassenbuch-Beträge können deutlich länger werden als z.B. eine Mitgliederzahl (Tausenderpunkt,
   Komma, Minuszeichen, Euro-Zeichen) - Schrift schrumpft bei Bedarf automatisch mit der
   verfügbaren Breite, damit auch größere Beträge nie über die Kachel hinausragen. */
.kb-stat-value { font-size: clamp(15px, 4.2vw, 22px) !important; }
@media (min-width: 700px) { .kb-stat-value { font-size: clamp(15px, 1.6vw, 22px) !important; } }
.stat-label { font-size: 12.5px; color: #6b6255; margin-top: 4px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { width: 80px; font-size: 13px; flex-shrink: 0; }
.bar-track { flex: 1; height: 10px; background: #DEDACD; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; }
.bar-fill.ok { background: var(--green); }
.bar-fill.warn { background: var(--brass); }
.bar-fill.danger { background: var(--brick); }
.bar-fill.interessent { background: #3B6E91; }

.donut-chart {
  width: 120px; height: 120px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; position: relative;
}
.donut-hole {
  width: 74px; height: 74px; border-radius: 50%; background: var(--paper-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'Newsreader', serif; font-size: 20px; font-weight: 600; color: var(--ink);
}
.donut-hole span { font-family: 'Work Sans', sans-serif; font-size: 10.5px; font-weight: 400; color: #6b6255; text-transform: uppercase; letter-spacing: 0.04em; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; }
.donut-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.bar-num { width: 24px; text-align: right; font-size: 13px; font-family: 'JetBrains Mono', monospace; }
.dash-list { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.dash-list li { padding: 6px 0; border-bottom: 1px solid #DEDACD; }
.dash-list li:last-child { border-bottom: none; }

.qr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.qr-card { border: 1px dashed #999; border-radius: 4px; padding: 12px; text-align: center; page-break-inside: avoid; }

@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4, .briefe-grid, .pdf-card, .stat-grid, .dash-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* Mehrfachauswahl-Kalender (z.B. Tage sperren bei Gastkarten) */
.kal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.kal-tag { border: 1px solid var(--line); border-radius: 6px; background: var(--paper-2); padding: 6px 2px; text-align: center; cursor: pointer; font-size: 12px; min-height: 46px; min-width: 0; overflow: hidden; overflow-wrap: break-word; }
.kal-tag .nr { font-weight: 600; }
.kal-tag .info { font-size: 9.5px; color: var(--muted); margin-top: 2px; min-height: 12px; }
.kal-tag.leer { background: transparent; border: none; cursor: default; }
.kal-tag.ausserhalb { opacity: 0.4; cursor: not-allowed; }
.kal-tag.verfuegbar:hover { border-color: var(--forest); }
.kal-tag.ausgewaehlt { background: var(--brick); border-color: var(--brick); color: #fff; }
.kal-tag.ausgewaehlt .info { color: #fff; }
.kal-tag:disabled { cursor: not-allowed; }
