/* ============================================================
   BAN YARO — Komponenten
   Alle wiederverwendbaren UI-Bausteine an einem Ort.
   Kein Baustein wird zweimal definiert.
   ============================================================ */

/* ------------------------------------------------------------
   1. BUTTONS
   ------------------------------------------------------------ */
.btn {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  gap:             var(--space-2);
  padding:         var(--space-3) var(--space-5);
  font-size:       var(--text-base);
  font-weight:     var(--weight-semibold);
  line-height:     1;
  border-radius:   var(--radius-md);
  border:          2px solid transparent;
  transition:      background var(--transition-fast),
                   color var(--transition-fast),
                   border-color var(--transition-fast),
                   transform var(--transition-fast),
                   box-shadow var(--transition-fast);
  cursor:          pointer;
  white-space:     nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action:    manipulation;
  min-height:      44px; /* Touch-Target Minimum */
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background:  var(--c-primary);
  color:       var(--c-text-inverse);
  border-color:var(--c-primary);
}
.btn-primary:hover {
  background:   var(--c-primary-dark);
  border-color: var(--c-primary-dark);
}

.btn-secondary {
  background:   var(--c-surface);
  color:        var(--c-text);
  border-color: var(--c-border);
  box-shadow:   var(--shadow-xs);
}
.btn-secondary:hover {
  background:   var(--c-surface-2);
  border-color: var(--c-surface-3);
}

.btn-ghost {
  background:   transparent;
  color:        var(--c-text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background:   var(--c-surface-2);
  color:        var(--c-text);
}

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

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

/* Größen */
.btn-sm {
  padding:     var(--space-2) var(--space-3);
  font-size:   var(--text-sm);
  min-height:  36px;
  border-radius: var(--radius-sm);
}
.btn-lg {
  padding:     var(--space-4) var(--space-8);
  font-size:   var(--text-md);
  min-height:  52px;
  border-radius: var(--radius-lg);
}
.btn-full { width: 100%; }

.btn:disabled {
  opacity: 0.45;
  cursor:  not-allowed;
  transform: none;
}

/* Icon-only Button */
.btn-icon {
  padding:       var(--space-2);
  border-radius: var(--radius-md);
  min-height:    44px;
  min-width:     44px;
}

/* ------------------------------------------------------------
   2. CARDS
   ------------------------------------------------------------ */
.card {
  background:    var(--c-surface);
  border:        1px solid var(--c-border-light);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-sm);
  overflow:      hidden;
}

.card-body {
  padding: var(--space-4);
}

.card-header {
  padding:       var(--space-4);
  border-bottom: 1px solid var(--c-border-light);
  font-weight:   var(--weight-semibold);
  font-size:     var(--text-md);
}

.card-footer {
  padding:    var(--space-3) var(--space-4);
  border-top: 1px solid var(--c-border-light);
  background: var(--c-bg);
}

/* Klickbare Card */
.card-clickable {
  cursor:     pointer;
  transition: box-shadow var(--transition-fast),
              transform  var(--transition-fast);
}
.card-clickable:hover {
  box-shadow: var(--shadow-md);
  transform:  translateY(-1px);
}
.card-clickable:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Horizontale Card (Bild links + Inhalt rechts) */
.card-horizontal {
  display: flex;
  align-items: stretch;
}
.card-horizontal .card-image {
  width:      88px;
  flex-shrink: 0;
  object-fit: cover;
}

/* ------------------------------------------------------------
   3. BADGES & STATUS-PILLS
   ------------------------------------------------------------ */
.badge {
  display:       inline-flex;
  align-items:   center;
  gap:           var(--space-1);
  padding:       var(--space-1) var(--space-2);
  font-size:     var(--text-xs);
  font-weight:   var(--weight-semibold);
  border-radius: var(--radius-full);
  white-space:   nowrap;
}

.badge-primary  { background: var(--c-primary-subtle); color: var(--c-primary-dark); }
.badge-success  { background: var(--c-success-subtle); color: var(--c-success); }
.badge-danger   { background: var(--c-danger-subtle);  color: var(--c-danger); }
.badge-warning  { background: var(--c-warning-subtle); color: var(--c-primary-dark); }
.badge-info     { background: var(--c-info-subtle);    color: var(--c-info); }
.badge-nature   { background: var(--c-nature-subtle);  color: var(--c-nature); }
.badge-muted    { background: var(--c-surface-2);      color: var(--c-text-secondary); }

/* Dot-Indicator */
.badge-dot::before {
  content:       '';
  display:       inline-block;
  width:         6px;
  height:        6px;
  border-radius: var(--radius-full);
  background:    currentColor;
}

/* Giftköder-spezifisch — besonders auffällig */
.badge-alarm {
  background:  var(--c-danger);
  color:       #fff;
  font-size:   var(--text-xs);
  font-weight: var(--weight-bold);
  animation:   pulse-alarm 2s ease-in-out infinite;
}
@keyframes pulse-alarm {
  0%, 100% { box-shadow: 0 0 0 0 rgba(196, 57, 26, 0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(196, 57, 26, 0); }
}

/* ------------------------------------------------------------
   4. FORMULARE
   ------------------------------------------------------------ */
.form-group {
  display:        flex;
  flex-direction: column;
  gap:            var(--space-2);
}

.form-label {
  font-size:   var(--text-sm);
  font-weight: var(--weight-medium);
  color:       var(--c-text-secondary);
}

.form-control {
  width:         100%;
  padding:       var(--space-3) var(--space-4);
  font-size:     var(--text-base);
  color:         var(--c-text);
  background:    var(--c-surface);
  border:        1.5px solid var(--c-border);
  border-radius: var(--radius-md);
  transition:    border-color var(--transition-fast),
                 box-shadow   var(--transition-fast);
  min-height:    44px;
  appearance:    none;
  -webkit-appearance: none;
}

.form-control::placeholder { color: var(--c-text-muted); }

.form-control:focus {
  outline:      none;
  border-color: var(--c-primary);
  box-shadow:   0 0 0 3px rgba(196, 132, 58, 0.15);
}

.form-control:invalid:not(:placeholder-shown) {
  border-color: var(--c-danger);
}

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

.form-control-icon {
  position: relative;
}
.form-control-icon .form-control {
  padding-left: var(--space-10);
}
.form-control-icon .icon {
  position:  absolute;
  left:      var(--space-3);
  top:       50%;
  transform: translateY(-50%);
  color:     var(--c-text-muted);
  pointer-events: none;
}

.form-hint {
  font-size: var(--text-xs);
  color:     var(--c-text-muted);
}
.form-error {
  font-size: var(--text-xs);
  color:     var(--c-danger);
}

/* Toggle / Checkbox */
.toggle {
  position: relative;
  display:  inline-block;
  width:    48px;
  height:   28px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position:      absolute;
  inset:         0;
  background:    var(--c-border);
  border-radius: var(--radius-full);
  transition:    background var(--transition-normal);
  cursor:        pointer;
}
.toggle-slider::before {
  content:       '';
  position:      absolute;
  width:         22px;
  height:        22px;
  left:          3px;
  top:           3px;
  background:    #fff;
  border-radius: var(--radius-full);
  transition:    transform var(--transition-normal);
  box-shadow:    var(--shadow-sm);
}
.toggle input:checked + .toggle-slider {
  background: var(--c-primary);
}
.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ------------------------------------------------------------
   5. AVATAR
   ------------------------------------------------------------ */
.avatar {
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
  border-radius: var(--radius-full);
  overflow:      hidden;
  background:    var(--c-surface-2);
  color:         var(--c-text-secondary);
  font-weight:   var(--weight-semibold);
  flex-shrink:   0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm  { width: 32px;  height: 32px;  font-size: var(--text-xs); }
.avatar-md  { width: 44px;  height: 44px;  font-size: var(--text-sm); }
.avatar-lg  { width: 64px;  height: 64px;  font-size: var(--text-lg); }
.avatar-xl  { width: 96px;  height: 96px;  font-size: var(--text-2xl); }
.avatar-2xl { width: 128px; height: 128px; font-size: var(--text-3xl); }

/* Hunde-Avatar mit Rahmen in Primärfarbe */
.avatar-dog {
  border: 3px solid var(--c-primary-light);
  box-shadow: 0 0 0 1px var(--c-primary);
}

/* ------------------------------------------------------------
   6. LISTE (Einstellungen, Menüs)
   ------------------------------------------------------------ */
.list {
  background:    var(--c-surface);
  border:        1px solid var(--c-border-light);
  border-radius: var(--radius-lg);
  overflow:      hidden;
}

.list-item {
  display:     flex;
  align-items: center;
  gap:         var(--space-3);
  padding:     var(--space-4);
  border-bottom: 1px solid var(--c-border-light);
  transition:  background var(--transition-fast);
  min-height:  52px;
}
.list-item:last-child { border-bottom: none; }
.list-item.clickable  { cursor: pointer; }
.list-item.clickable:hover { background: var(--c-bg); }

.list-item-icon {
  width:         40px;
  height:        40px;
  border-radius: var(--radius-md);
  display:       flex;
  align-items:   center;
  justify-content: center;
  flex-shrink:   0;
  font-size:     20px;
}

.list-item-content { flex: 1; min-width: 0; }
.list-item-title   { font-weight: var(--weight-medium); }
.list-item-desc    { font-size: var(--text-sm); color: var(--c-text-secondary); }

/* ------------------------------------------------------------
   7. TOAST / BENACHRICHTIGUNGEN
   ------------------------------------------------------------ */
.toast-container {
  position:       fixed;
  top:            calc(var(--safe-top) + var(--space-4));
  left:           50%;
  transform:      translateX(-50%);
  z-index:        1000;
  display:        flex;
  flex-direction: column;
  gap:            var(--space-2);
  pointer-events: none;
  width:          calc(100% - var(--space-8));
  max-width:      400px;
}

.toast {
  display:       flex;
  align-items:   center;
  gap:           var(--space-3);
  padding:       var(--space-3) var(--space-4);
  background:    var(--c-text);
  color:         var(--c-text-inverse);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-lg);
  font-size:     var(--text-sm);
  font-weight:   var(--weight-medium);
  pointer-events: auto;
  animation:     toast-in 200ms ease forwards;
}

.toast-success { background: var(--c-success); }
.toast-danger  { background: var(--c-danger); }
.toast-warning { background: var(--c-warning); color: var(--c-text); }
.toast-info    { background: var(--c-info); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0)    scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.96); }
}
.toast.removing { animation: toast-out 200ms ease forwards; }

/* ------------------------------------------------------------
   8. MODAL
   ------------------------------------------------------------ */
.modal-overlay {
  position:   fixed;
  inset:      0;
  background: rgba(42, 31, 20, 0.5);
  z-index:    900;
  display:    flex;
  align-items: flex-end;
  justify-content: center;
  padding:    var(--space-4);
  backdrop-filter: blur(2px);
  animation:  overlay-in var(--transition-normal) ease;
  touch-action: manipulation;
}
@media (min-width: 768px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background:    var(--c-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width:         100%;
  max-width:     480px;
  max-height:    90vh;
  overflow-y:    auto;
  box-shadow:    var(--shadow-xl);
  animation:     modal-in var(--transition-slow) cubic-bezier(0.34, 1.56, 0.64, 1);
}
@media (min-width: 768px) {
  .modal {
    border-radius: var(--radius-xl);
    animation:     overlay-in var(--transition-normal) ease;
  }
}

.modal-handle {
  width:         40px;
  height:        4px;
  background:    var(--c-border);
  border-radius: var(--radius-full);
  margin:        var(--space-3) auto;
}
@media (min-width: 768px) { .modal-handle { display: none; } }

.modal-header {
  padding:        var(--space-4) var(--space-6);
  border-bottom:  1px solid var(--c-border-light);
  display:        flex;
  align-items:    center;
  justify-content:space-between;
}
.modal-title {
  font-size:   var(--text-lg);
  font-weight: var(--weight-semibold);
}
.modal-body   { padding: var(--space-6); }
.modal-footer {
  padding:    var(--space-4) var(--space-6);
  border-top: 1px solid var(--c-border-light);
  display:    flex;
  gap:        var(--space-3);
  justify-content: flex-end;
}

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modal-in {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ------------------------------------------------------------
   9. LADEINDIKATOR
   ------------------------------------------------------------ */
.spinner {
  width:         24px;
  height:        24px;
  border:        2.5px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: var(--radius-full);
  animation:     spin 0.7s linear infinite;
  flex-shrink:   0;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

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

.loading-overlay {
  position:        absolute;
  inset:           0;
  background:      rgba(250, 247, 242, 0.7);
  display:         flex;
  align-items:     center;
  justify-content: center;
  z-index:         10;
  border-radius:   inherit;
}

/* ------------------------------------------------------------
   10. LEERER ZUSTAND (Empty State)
   ------------------------------------------------------------ */
.empty-state {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  text-align:      center;
  padding:         var(--space-12) var(--space-8);
  gap:             var(--space-4);
}
.empty-state-icon {
  font-size:     48px;
  line-height:   1;
  margin-bottom: var(--space-2);
}
.empty-state-title {
  font-size:   var(--text-lg);
  font-weight: var(--weight-semibold);
  color:       var(--c-text);
}
.empty-state-text {
  font-size: var(--text-sm);
  color:     var(--c-text-secondary);
  max-width: 280px;
  line-height: var(--leading-relaxed);
}

/* ------------------------------------------------------------
   11. FOTO-UPLOAD
   ------------------------------------------------------------ */
.photo-upload {
  position:       relative;
  border:         2px dashed var(--c-border);
  border-radius:  var(--radius-lg);
  background:     var(--c-bg);
  display:        flex;
  flex-direction: column;
  align-items:    center;
  justify-content:center;
  gap:            var(--space-2);
  padding:        var(--space-8);
  cursor:         pointer;
  transition:     border-color var(--transition-fast),
                  background   var(--transition-fast);
  min-height:     140px;
}
.photo-upload:hover {
  border-color: var(--c-primary);
  background:   var(--c-primary-subtle);
}
.photo-upload input[type="file"] {
  position: absolute;
  inset:    0;
  opacity:  0;
  cursor:   pointer;
}
.photo-upload-icon  { font-size: 32px; color: var(--c-text-muted); }
.photo-upload-text  { font-size: var(--text-sm); color: var(--c-text-secondary); }
.photo-upload-hint  { font-size: var(--text-xs); color: var(--c-text-muted); }

/* Vorschau nach Upload */
.photo-preview {
  position:      relative;
  border-radius: var(--radius-lg);
  overflow:      hidden;
}
.photo-preview img { width: 100%; object-fit: cover; }
.photo-preview-remove {
  position:      absolute;
  top:           var(--space-2);
  right:         var(--space-2);
  width:         32px;
  height:        32px;
  border-radius: var(--radius-full);
  background:    rgba(42, 31, 20, 0.6);
  color:         #fff;
  display:       flex;
  align-items:   center;
  justify-content: center;
  cursor:        pointer;
  font-size:     16px;
}

/* ------------------------------------------------------------
   12. TRENNLINIEN & ABSCHNITTE
   ------------------------------------------------------------ */
.divider {
  height:     1px;
  background: var(--c-border-light);
  margin:     var(--space-4) 0;
}

.section-title {
  font-size:     var(--text-xs);
  font-weight:   var(--weight-semibold);
  color:         var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding:       var(--space-4) var(--space-4) var(--space-2);
}

/* ------------------------------------------------------------
   13. FAB — Floating Action Button (der + Button)
   ------------------------------------------------------------ */
.fab {
  position:      fixed;
  z-index:       200;
  width:         56px;
  height:        56px;
  border-radius: var(--radius-full);
  background:    var(--c-primary);
  color:         #fff;
  box-shadow:    var(--shadow-lg);
  display:       flex;
  align-items:   center;
  justify-content: center;
  font-size:     28px;
  cursor:        pointer;
  transition:    transform var(--transition-fast),
                 box-shadow var(--transition-fast);
  -webkit-tap-highlight-color: transparent;

  /* Mobile: über der Bottom-Nav zentriert */
  bottom: calc(var(--nav-bottom-height) + var(--safe-bottom) + var(--space-4));
  left:   50%;
  transform: translateX(-50%);
}
.fab:hover {
  transform:  translateX(-50%) scale(1.05);
  box-shadow: var(--shadow-xl);
}
.fab:active {
  transform:  translateX(-50%) scale(0.95);
}

/* Desktop: FAB positioniert sich neu */
@media (min-width: 768px) {
  .fab {
    bottom:    var(--space-8);
    left:      auto;
    right:     var(--space-8);
    transform: none;
  }
  .fab:hover  { transform: scale(1.05); }
  .fab:active { transform: scale(0.95); }
}

/* ------------------------------------------------------------
   12. TAGEBUCH
   ------------------------------------------------------------ */

/* Monats-Trennlinie */
.diary-month-header {
  font-size:     var(--text-sm);
  font-weight:   var(--weight-semibold);
  color:         var(--c-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding:       var(--space-4) 0 var(--space-2);
  border-bottom: 1px solid var(--c-border);
  margin-bottom: var(--space-3);
}
.diary-month-header:first-child {
  padding-top: 0;
}

/* Eintragskarte */
.diary-card {
  background:    var(--c-surface);
  border:        1px solid var(--c-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  overflow:      hidden;
  cursor:        pointer;
  transition:    box-shadow var(--transition-fast),
                 transform  var(--transition-fast);
  box-shadow:    var(--shadow-xs);
  -webkit-tap-highlight-color: transparent;
}
.diary-card:hover {
  box-shadow: var(--shadow-md);
  transform:  translateY(-1px);
}
.diary-card:active {
  transform: scale(0.99);
}

/* Meilenstein-Hervorhebung */
.diary-card--milestone {
  border-color: var(--c-primary);
  border-width: 2px;
  background:   linear-gradient(
    135deg,
    var(--c-surface) 0%,
    color-mix(in srgb, var(--c-primary) 6%, var(--c-surface)) 100%
  );
}

/* Foto oben */
.diary-card-photo {
  width:  100%;
  height: 180px;
  overflow: hidden;
}
.diary-card-photo img {
  width:       100%;
  height:      100%;
  object-fit:  cover;
  display:     block;
}

/* Card Body */
.diary-card-body {
  padding: var(--space-3) var(--space-4);
}

/* Meta-Zeile: Typ + Datum */
.diary-card-meta {
  display:         flex;
  justify-content: space-between;
  align-items:     center;
  margin-bottom:   var(--space-1);
}
.diary-card-type {
  font-size:   var(--text-xs);
  font-weight: var(--weight-semibold);
  color:       var(--c-primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.diary-card-date {
  font-size: var(--text-xs);
  color:     var(--c-text-secondary);
}

/* Titel */
.diary-card-title {
  font-size:   var(--text-base);
  font-weight: var(--weight-semibold);
  color:       var(--c-text);
  margin-bottom: var(--space-1);
}

/* Text-Vorschau */
.diary-card-text {
  font-size:   var(--text-sm);
  color:       var(--c-text-secondary);
  line-height: 1.5;
  margin:      0 0 var(--space-2);
  display:     -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow:    hidden;
}

/* Tags */
.diary-card-tags {
  display:   flex;
  flex-wrap: wrap;
  gap:       var(--space-1);
  margin-top: var(--space-1);
}

/* Detail-Ansicht */
.diary-detail-milestone-badge {
  display:       inline-flex;
  align-items:   center;
  gap:           var(--space-1);
  background:    color-mix(in srgb, var(--c-primary) 12%, transparent);
  color:         var(--c-primary-dark);
  font-weight:   var(--weight-semibold);
  font-size:     var(--text-sm);
  padding:       var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-3);
}

/* Leaflet-Attribution ausblenden */
.leaflet-control-attribution { display: none !important; }
