/**
 * STC Massong – Komponenten
 * Alle wiederverwendbaren UI-Komponenten:
 * Buttons, Formulare, Cards, Badges, Modals, Tabellen, Alerts, Empty States.
 * Benötigt: tokens.css, base.css
 */

/* ═══════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.7rem 1.5rem;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
  white-space: nowrap;
  text-decoration: none;
  vertical-align: middle;
}

.btn:focus-visible {
  outline: 3px solid var(--color-brand);
  outline-offset: 2px;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

/* --- Größen --- */
.btn-sm {
  padding: 0.4rem 1rem;
  font-size: var(--font-size-sm);
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: var(--font-size-lg);
}

/* --- Primär (Marken-Grün) --- */
.btn-primary {
  background: var(--color-brand);
  color: var(--color-dark);
  border-color: var(--color-brand);
  font-weight: var(--font-weight-bold);
}

.btn-primary:hover {
  background: var(--color-brand-dark);
  border-color: var(--color-brand-dark);
  box-shadow: var(--shadow-brand);
  transform: translateY(-1px);
  text-decoration: none;
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: none;
}

/* --- Sekundär (Grau) --- */
.btn-secondary {
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-border);
  color: var(--color-dark);
  text-decoration: none;
}

/* --- Erfolg (Grün) --- */
.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.btn-success:hover {
  background: var(--color-success-dark);
  border-color: var(--color-success-dark);
  text-decoration: none;
}

/* --- Gefahr (Rot) --- */
.btn-danger {
  background: var(--color-error);
  color: white;
  border-color: var(--color-error);
}

.btn-danger:hover {
  background: var(--color-error-dark);
  border-color: var(--color-error-dark);
  text-decoration: none;
}

/* --- Ghost (Transparent) --- */
.btn-ghost {
  background: transparent;
  color: var(--color-text-light);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--color-bg-subtle);
  color: var(--color-dark);
  text-decoration: none;
}

/* --- Outline Primär --- */
.btn-outline-primary {
  background: transparent;
  color: var(--color-brand-darker);
  border-color: var(--color-brand);
}

.btn-outline-primary:hover {
  background: var(--color-brand);
  color: var(--color-dark);
  text-decoration: none;
}

/* --- Icon-Button (Rund) --- */
.btn-icon {
  padding: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  font-size: var(--font-size-xl);
}

/* Alias für Kompatibilität */
.btn-small { padding: 0.4rem 1rem; font-size: var(--font-size-sm); }


/* ═══════════════════════════════════════════════════════════
   FORMULARE
═══════════════════════════════════════════════════════════ */

.form-group {
  margin-bottom: var(--space-6);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.form-label.required::after {
  content: ' *';
  color: var(--color-error);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-bg-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

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

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: var(--line-height-relaxed);
}

.form-select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
}

/* Fehler-State */
.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: var(--color-error);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--color-error);
  margin-top: var(--space-1);
}

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  margin-top: var(--space-1);
}

/* Zweispaltige Zeile */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

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

/* Datum + Zahl Inputs nebeneinander */
.date-inputs {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

/* Datumsliste */
.date-list {
  list-style: none;
  margin-top: var(--space-4);
}

.date-item {
  background: var(--color-bg-subtle);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
}


/* ═══════════════════════════════════════════════════════════
   CARDS
═══════════════════════════════════════════════════════════ */

.card {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-8);
  border: 1px solid transparent;
}

.card-sm {
  padding: var(--space-6);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.card-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-dark);
}

.card-title-sm {
  font-size: var(--font-size-xl);
}

/* Karte mit Marken-Akzent links */
.card-accent {
  border-left: 4px solid var(--color-brand);
}

/* ═══════════════════════════════════════════════════════════
   BADGES / TAGS
═══════════════════════════════════════════════════════════ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  white-space: nowrap;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
}

.badge-danger {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.badge-info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
}

.badge-neutral {
  background: var(--color-bg-subtle);
  color: var(--color-text-light);
}

.badge-brand {
  background: var(--color-brand-subtle);
  color: var(--color-brand-darker);
}


/* ═══════════════════════════════════════════════════════════
   ALERTS / MELDUNGEN
═══════════════════════════════════════════════════════════ */

.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border: 1px solid transparent;
}

.alert-success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-color: var(--color-success-dark);
}

.alert-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-color: var(--color-warning-dark);
}

.alert-error,
.alert-danger {
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border-color: var(--color-error);
  border-left-width: 4px;
}

.alert-info {
  background: var(--color-info-bg);
  color: var(--color-info-text);
  border-color: var(--color-info);
}

/* Erfolgs-Nachricht (größer, für Bestätigungen) */
.success-message {
  background: var(--color-success-bg);
  border: 2px solid var(--color-success-dark);
  color: var(--color-success-text);
  padding: var(--space-6);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-6);
  font-weight: var(--font-weight-semibold);
}

/* Fehler-Meldung (Login etc.) */
.error-message {
  background: var(--color-error-bg);
  color: var(--color-error);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
  display: none;
  border-left: 4px solid var(--color-error);
  font-size: var(--font-size-sm);
}

.error-message.show {
  display: block;
}


/* ═══════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════ */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--color-bg-card);
  border-radius: var(--radius-xl);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2xl);
}

.modal-content-sm  { max-width: 400px; }
.modal-content-md  { max-width: 600px; }
.modal-content-lg  { max-width: 800px; }
.modal-content-xl  { max-width: 1000px; }

/* Standard: mittel */
.modal-content:not([class*="modal-content-"]) { max-width: 600px; }

.modal-header {
  background: linear-gradient(135deg, var(--color-dark) 0%, var(--color-black) 100%);
  color: white;
  padding: var(--space-6) var(--space-8);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-bottom: 3px solid var(--color-brand);
  position: relative;
}

.modal-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-snug);
  margin-bottom: var(--space-1);
  color: inherit;
}

.modal-subtitle {
  font-size: var(--font-size-sm);
  color: rgba(255, 255, 255, 0.75);
  font-weight: var(--font-weight-normal);
}

.modal-body {
  padding: var(--space-8);
}

.modal-footer,
.modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}

/* Schließen-Button im Modal-Header */
.close-modal {
  position: absolute;
  top: var(--space-4);
  right: var(--space-6);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: var(--font-size-3xl);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-normal);
  line-height: 1;
}

.close-modal:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Teilen-Button im Modal-Header */
.share-modal {
  position: absolute;
  top: var(--space-4);
  right: 4.5rem;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: var(--font-size-3xl);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-normal);
}

.share-modal:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Toast (Kopier-Bestätigung) */
.share-toast {
  position: absolute;
  top: 5rem;
  right: var(--space-6);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  pointer-events: none;
  animation: fadeInOut 2.5s ease forwards;
  z-index: var(--z-raised);
}

@keyframes fadeInOut {
  0%   { opacity: 0; transform: translateY(-6px); }
  15%  { opacity: 1; transform: translateY(0); }
  75%  { opacity: 1; }
  100% { opacity: 0; }
}


/* ═══════════════════════════════════════════════════════════
   TABELLEN
═══════════════════════════════════════════════════════════ */

.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

th, td {
  padding: var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

th {
  background: var(--color-bg-hover);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-light);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--color-bg-hover);
}

tbody tr:last-child td {
  border-bottom: none;
}

/* Aktions-Buttons Spalte */
.action-buttons {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  th, td {
    padding: var(--space-3) var(--space-2);
  }

  table {
    font-size: var(--font-size-xs);
  }
}


/* ═══════════════════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════════════════ */

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-8);
  color: var(--color-text-light);
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: var(--space-4);
  opacity: 0.3;
  display: block;
}

.empty-state h3 {
  font-size: var(--font-size-xl);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--font-size-base);
  color: var(--color-text-light);
}


/* ═══════════════════════════════════════════════════════════
   INFO-GRID (Detail-Ansicht)
═══════════════════════════════════════════════════════════ */

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  background: var(--color-bg-hover);
  padding: var(--space-6);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-8);
}

.info-item-detail {
  display: flex;
  flex-direction: column;
}

.info-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-light);
  margin-bottom: var(--space-1);
}

.info-value {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

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


/* ═══════════════════════════════════════════════════════════
   LOADING SPINNER
═══════════════════════════════════════════════════════════ */

.loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-full);
  border-top-color: white;
  animation: spin 0.8s linear infinite;
}

.loading-spinner-dark {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--color-brand);
}

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

/* Seitenweite Lade-Animation */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
}

.page-loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-radius: var(--radius-full);
  border-top-color: var(--color-brand);
  animation: spin 0.8s linear infinite;
}


/* ═══════════════════════════════════════════════════════════
   SEKTION-TITEL
═══════════════════════════════════════════════════════════ */

.section-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-dark);
  margin-bottom: var(--space-4);
}
