/**
 * KCDD.de - Stylesheet fuer Vereinsverwaltung, Strichlisten-Matrix, Foto-Scanner,
 * Kassenbuch, Statistiken und druckbaren Blanko-Bogen.
 */

:root {
  --kcdd-bg: #f4f6f9;
  --kcdd-surface: #ffffff;
  --kcdd-surface-alt: #f8fafc;
  --kcdd-border: #dde3ea;
  --kcdd-text: #182230;
  --kcdd-text-muted: #5b6777;
  --kcdd-primary: #c81e1e;
  --kcdd-primary-dark: #9e1515;
  --kcdd-accent: #1d4ed8;
  --kcdd-success: #15803d;
  --kcdd-warning: #b45309;
  --kcdd-danger: #b91c1c;
  --kcdd-radius: 10px;
  --kcdd-shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--kcdd-bg);
  color: var(--kcdd-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Barrierefreie Focus-Rings */
.btn:focus-visible,
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--kcdd-accent);
  outline-offset: 2px;
}

/* Taktiles Feedback */
.btn:active,
.tally-btn:active {
  transform: scale(0.97);
}

.btn-icon:active {
  transform: scale(0.92);
}

/* DEV-Umgebungs-Banner */
.dev-banner-ribbon {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  right: 12px;
  z-index: 9999;
  background: var(--kcdd-primary);
  color: #ffffff;
  padding: 5px 12px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* Topbar & Navigation */
.kcdd-header {
  background: #111827;
  color: #ffffff;
  border-bottom: 3px solid var(--kcdd-primary);
  position: sticky;
  top: 0;
  z-index: 1000;
  padding-top: env(safe-area-inset-top, 0px);
}

.kcdd-header-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.kcdd-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #ffffff;
}

.kcdd-brand img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: 50%;
  background: #ffffff;
  padding: 2px;
}

.kcdd-brand-title {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.kcdd-brand-sub {
  font-size: 0.75rem;
  color: #9ca3af;
  display: block;
}

.kcdd-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.kcdd-nav-link {
  color: #e5e7eb;
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .kcdd-nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
  }
}

.kcdd-nav-link.active {
  background: var(--kcdd-primary);
  color: #ffffff;
}

.kcdd-role-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.role-badge.role-readonly {
  background: #374151;
  color: #e5e7eb;
}

.role-badge.role-kassenwart {
  background: #1d4ed8;
  color: #ffffff;
}

.role-badge.role-admin {
  background: #15803d;
  color: #ffffff;
}

/* Haupt-Container */
.kcdd-main {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 16px calc(48px + env(safe-area-inset-bottom, 0px));
}

/* Karten & Grid */
.kcdd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.kcdd-card {
  background: var(--kcdd-surface);
  border: 1px solid var(--kcdd-border);
  border-radius: var(--kcdd-radius);
  padding: 18px;
  box-shadow: var(--kcdd-shadow);
  margin-bottom: 20px;
}

.kcdd-stat-card {
  background: var(--kcdd-surface);
  border: 1px solid var(--kcdd-border);
  border-radius: var(--kcdd-radius);
  padding: 16px;
  box-shadow: var(--kcdd-shadow);
}

.kcdd-stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--kcdd-text-muted);
  margin-bottom: 4px;
}

.kcdd-stat-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--kcdd-text);
  font-variant-numeric: tabular-nums;
}

.kcdd-stat-sub {
  font-size: 0.82rem;
  color: var(--kcdd-text-muted);
  margin-top: 4px;
}

/* Buttons & Formulare */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--kcdd-primary);
  color: #ffffff;
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover {
    background: var(--kcdd-primary-dark);
  }
}

.btn-secondary {
  background: #ffffff;
  color: var(--kcdd-text);
  border-color: var(--kcdd-border);
}

@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover {
    background: #f1f5f9;
  }
}

.btn-accent {
  background: var(--kcdd-accent);
  color: #ffffff;
}

.btn-success {
  background: var(--kcdd-success);
  color: #ffffff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.82rem;
}

.form-control {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.92rem;
  background: #ffffff;
  color: var(--kcdd-text);
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}

.form-group {
  flex: 1 1 180px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--kcdd-text-muted);
  margin-bottom: 4px;
}

/* Tabellen */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--kcdd-border);
  border-radius: 8px;
}

.kcdd-table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.kcdd-table th,
.kcdd-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--kcdd-border);
  text-align: left;
}

.kcdd-table th {
  background: #f8fafc;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
}

.kcdd-table tr:last-child td {
  border-bottom: none;
}

.text-right {
  text-align: right !important;
}

.text-center {
  text-align: center !important;
}

/* Interaktive Strichlisten-Matrix (15 Kegler x 22 Spalten) */
.matrix-scroll-wrapper {
  width: 100%;
  max-height: 76vh;
  max-height: 76dvh;
  overflow: auto;
  border: 2px solid #1e293b;
  border-radius: 8px;
  background: #ffffff;
  position: relative;
}

.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.matrix-table th,
.matrix-table td {
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  padding: 5px 6px;
  vertical-align: middle;
}

.matrix-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #1e293b;
  color: #ffffff;
  font-weight: 700;
  text-align: center;
}

.matrix-table thead tr.price-subhead th {
  top: 112px;
  background: #334155;
  color: #f8fafc;
  font-size: 0.74rem;
  padding: 3px 4px;
}

.matrix-col-rotate {
  height: 112px;
  min-width: 48px;
  max-width: 64px;
  white-space: nowrap;
  vertical-align: bottom !important;
  padding-bottom: 8px !important;
}

.matrix-col-rotate > span {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 98px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.76rem;
  line-height: 1.15;
}

.matrix-sticky-col {
  position: sticky;
  left: 0;
  z-index: 15;
  background: #f8fafc;
  font-weight: 700;
  min-width: 145px;
  max-width: 170px;
  white-space: nowrap;
  border-right: 2px solid #1e293b !important;
}

.matrix-table thead th.matrix-sticky-col {
  z-index: 30;
  background: #0f172a;
}

.matrix-row-absent td:not(.matrix-sticky-col):not(.matrix-status-cell):not(.matrix-sum-cell) {
  opacity: 0.42;
  background: #f1f5f9;
}

/* Strichlisten-Zelle */
.tally-cell {
  min-width: 54px;
  text-align: center;
  padding: 3px !important;
}

.tally-control {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.tally-btn {
  width: 22px;
  height: 26px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  color: #1e293b;
}

.tally-btn.plus {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}

.tally-input {
  width: 36px;
  height: 26px;
  text-align: center;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.84rem;
  padding: 0 2px;
}

.tally-input.has-val {
  background: #fef2f2;
  border-color: var(--kcdd-primary);
  color: var(--kcdd-primary-dark);
}

.tally-marks-preview {
  font-family: monospace;
  font-size: 0.7rem;
  color: var(--kcdd-primary);
  letter-spacing: 1px;
  min-height: 12px;
  line-height: 1;
  margin-top: 2px;
}

.ai-filled-cell {
  background: #fef3c7 !important;
  box-shadow: inset 0 0 0 2px #f59e0b;
}

.ai-visual-hint {
  font-size: 0.62rem;
  color: #92400e;
  line-height: 1.1;
  margin-top: 2px;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: auto;
  margin-right: auto;
}

/* Lightbox & Foto-Scanner Container (UI-Tester konform: 100dvh & object-fit: contain) */
.lightbox-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  background: rgba(15, 23, 42, 0.88);
  z-index: 2000;
  display: none;
  flex-direction: column;
}

.lightbox-modal.active {
  display: flex;
}

.lightbox-content-area {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  height: 100%;
  width: 100%;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-image {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.scanner-preview-box {
  background: #0f172a;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
  max-height: 460px;
  overflow: auto;
  text-align: center;
}

.scanner-preview-box img {
  max-width: 100%;
  max-height: 310px;
  object-fit: contain;
  border-radius: 4px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* Alert-Boxen */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 0.9rem;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* Druckansicht fuer Blanko-Strichlistenbogen (A4 Querformat) */
@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 10pt;
  }
  .kcdd-header,
  .no-print,
  .dev-banner-ribbon {
    display: none !important;
  }
  .kcdd-main {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .kcdd-card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .print-bogen-table {
    width: 100%;
    border-collapse: collapse;
    border: 2px solid #000000;
  }
  .print-bogen-table th,
  .print-bogen-table td {
    border: 1px solid #000000 !important;
    padding: 3px 4px !important;
    font-size: 8.5pt !important;
  }
}
