/* ═══════════════════════════════════════════════════════════
   Globale UI-Komponenten — FFW App (v20)
   Verwendet ausschließlich kanonische Design-Token aus DESIGN.md.

   Bedienkonzept (kanonisch):
   - Page-Header: Titel + ein Subtitle; Primäraktionen rechts
   - Buttons: primary | secondary | ghost (+ danger nur für Zerstören)
   - Labels: Sentence case (kein ALL-CAPS)
   - Empty State: genau eine Primary-CTA, Secondary optional
   - Modal: gleiche Radien/Buttons wie Seite, kein Card-in-Card
   ═══════════════════════════════════════════════════════════ */

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--btn-height, 44px);
  height: auto;
  padding: 0 16px;
  border-radius: var(--r-md);
  font-size: var(--text-footnote);
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  background: var(--bg-card);
  color: var(--t1);
  border-color: var(--border-med);
  box-sizing: border-box;
}

.btn:hover:not(:disabled) {
  background: var(--bg-card-2);
  transform: translateY(-1px);
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* primary — eine klare Hauptaktion pro Kontext */
.btn-primary,
.btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-primary:hover:not(:disabled),
.btn.primary:hover:not(:disabled) {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  box-shadow: 0 2px 8px rgba(0, 102, 204, 0.25);
}

/* secondary — neutrale Alternativaktion (kein hellblaues Special) */
.btn-secondary,
.btn.secondary {
  background: var(--bg-card-2);
  color: var(--t1);
  border-color: var(--border-med);
}

.btn-secondary:hover:not(:disabled),
.btn.secondary:hover:not(:disabled) {
  background: var(--bg-card);
  border-color: var(--brand);
  color: var(--brand);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-text);
  border-color: var(--danger-text);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
  background: var(--success-text);
  border-color: var(--success-text);
}

.btn-white {
  background: #fff;
  color: var(--t1);
  border-color: var(--border);
}

.btn-white:hover:not(:disabled) {
  background: var(--bg-card-2);
}

.btn-ghost,
.btn.ghost {
  background: transparent;
  color: var(--t2);
  border-color: var(--border-med);
}

.btn-ghost:hover:not(:disabled),
.btn.ghost:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-light);
}

.btn-sm { padding: 0 10px; font-size: var(--text-caption1); border-radius: var(--r-sm); min-height: 32px; height: auto; }
.btn-lg { padding: 0 20px; font-size: var(--text-callout); border-radius: var(--r-lg); min-height: 48px; }
.btn.icon-only { padding: 0; width: 44px; justify-content: center; }

/* ── Data Tables ─────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  background: var(--bg-card-2);
  font-weight: 600;
  font-size: 12px;
  color: var(--t2);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-card-2); }

.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .actions .btn { padding: 5px 10px; font-size: 12px; min-height: 32px; }

.data-table-wrap { overflow-x: auto; border-radius: var(--r-md); }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  padding: 16px;
}

.modal-overlay.is-open,
.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--r-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: scale(0.96);
  transition: transform 0.2s;
}

.modal-overlay.is-open .modal,
.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 700; color: var(--t1); margin: 0; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--t3);
  padding: 4px;
  border-radius: 6px;
  line-height: 0;
}

.modal-close:hover { color: var(--t1); background: var(--bg-card-2); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1 1 auto; }

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* Form als Modal-Inhalt: Kopf bleibt außerhalb, Fuß bleibt unten */
.modal > form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

/* ── Formular-Komponenten ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: var(--text-footnote);
  font-weight: 600;
  color: var(--t2);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-med);
  border-radius: var(--r-sm);
  background: var(--bg-card);
  color: var(--t1);
  font-size: var(--text-callout);
  line-height: 1.4;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23636366' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

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

@media (max-width: 520px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-row .form-group { margin-bottom: 0; }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--space-xl) var(--space-lg);
  text-align: left;
}

.empty-state-title {
  margin: 0 0 var(--space-sm);
  font-size: var(--text-title3);
  font-weight: 700;
  color: var(--t1);
  letter-spacing: -0.02em;
}

.empty-state-text {
  margin: 0;
  font-size: var(--text-subheadline);
  color: var(--t2);
  line-height: 1.45;
  max-width: 40em;
}

.empty-state-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-items: center;
  margin-top: var(--space-md);
}

.form-hint {
  font-size: 11px;
  color: var(--t2);
  margin-top: 4px;
}

.input-with-button {
  display: flex;
  gap: 8px;
}

.input-with-button .form-input { flex: 1; }
.input-with-button .btn { flex-shrink: 0; white-space: nowrap; }

/* ── Toast / In-App Feedback ───────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toastIn 0.25s ease;
}

.toast-success { border-color: var(--success-bg); }
.toast-error   { border-color: var(--danger-bg); }
.toast-warning { border-color: var(--warning-bg); }
.toast-info    { border-color: var(--info-bg); }

.toast-icon { flex-shrink: 0; width: 18px; height: 18px; }
.toast-success .toast-icon { color: var(--success); }
.toast-error   .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info    .toast-icon { color: var(--info); }

.toast-content { flex: 1; }
.toast-title { font-weight: 600; color: var(--t1); margin-bottom: 2px; }
.toast-message { color: var(--t2); line-height: 1.4; }

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--t3);
  padding: 0;
  line-height: 0;
}

.toast-close:hover { color: var(--t1); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Loading / Spinner ─────────────────────────────────────── */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn .spinner { border-top-color: currentColor; }

/* ── Trial CTA (Demo-Login) ──────────────────────────────── */
.trial-cta {
  margin-top: 18px;
  padding: 14px;
  background: var(--bg-card-2);
  border: 1px solid var(--border-med);
  border-radius: var(--r-md);
  text-align: center;
}
.trial-cta p {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--t1);
  font-weight: 500;
}
.trial-cta a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  text-decoration: none;
}
.trial-cta a:hover { text-decoration: underline; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .toast-container { left: 12px; right: 12px; max-width: none; top: 12px; }
  .modal { max-height: calc(100vh - 24px); }
  .data-table th,
  .data-table td { padding: 8px 10px; font-size: 12px; }
}
