/**
 * Dashboard – Ohne Login: nur Suchleiste. Mit Login: Apps oben, Suchleiste mittig (volle Breite), Apps unten.
 * Suchleiste: Eingabefeld + KI-Link (Suche per Enter).
 */

.dashboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing);
  min-height: 0;
  gap: var(--spacing);
  overflow: hidden;
}

/* Suchzeile – Leiste oben, Suche-Button zentral darunter */
.dashboard-search-row {
  width: 100%;
  max-width: 720px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.dashboard-search-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Suchleiste im Stil von Kopf-/Fußzeile (gleiche Transparenz) */
.dashboard-search-bmatrix {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: clamp(40px, 6vh, 48px);
  padding: 0 0.5rem 0 1rem;
  background: var(--bg-header);
  border: 1px solid var(--border-color, var(--border));
  border-radius: 2rem;
  box-shadow: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.dashboard-search-bmatrix:focus-within {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
  border-color: var(--line-color, var(--accent));
}

.dashboard-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 1rem;
  padding: 0.5rem 0;
  outline: none;
}

.dashboard-search-input::placeholder {
  color: var(--text-muted);
}

.dashboard-search-ki {
  flex-shrink: 0;
  margin-left: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent-ki);
  text-decoration: none;
  border-radius: 1.5rem;
  border: 1px solid transparent;
  transition: background 0.2s;
}

.dashboard-search-ki:hover {
  background: var(--bg-hover);
}

/* Suchbutton zentral unter der Suchleiste (eigene Zeile) */
.dashboard-search-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.75rem;
  width: 100%;
  flex-shrink: 0;
}
.dashboard-search-btn-below {
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  border-radius: 0.25rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.dashboard-search-btn-below:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

/* App-Grids oben und unten – quadratische Kacheln, an Suchleiste/Viewport angepasst */
.dashboard-apps-above,
.dashboard-apps-below {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 900px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.dashboard-apps-grid {
  --grid-gap: 6rem;
  /* Kleinere Kacheln, nur Icon; mehr Abstand */
  --avail-w: min(900px, 100vw - 2 * var(--spacing));
  --tile-by-width: calc((var(--avail-w) - (var(--grid-cols, 5) - 1) * var(--grid-gap)) / var(--grid-cols, 5));
  --avail-h-half: calc((100vh - var(--header-height) - var(--footer-height) - var(--search-row-height) - 3 * var(--spacing)) / 2);
  --tile-by-height: calc((var(--avail-h-half) - (var(--grid-rows, 2) - 1) * var(--grid-gap)) / var(--grid-rows, 2));
  --tile-size: min(var(--tile-by-width), var(--tile-by-height), 52px);
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 5), var(--tile-size));
  grid-template-rows: repeat(var(--grid-rows, 2), var(--tile-size));
  gap: var(--grid-gap);
  width: max-content;
  max-width: 100%;
  height: max-content;
  max-height: 100%;
}

.dashboard-cell-app {
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: var(--tile-size);
  height: var(--tile-size);
  min-width: 0;
  min-height: 0;
}

.dashboard-app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  aspect-ratio: 1;
  padding: 0.2rem;
  text-decoration: none;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: none;
  transition: transform 0.12s, opacity 0.2s;
}

.dashboard-app:hover {
  transform: scale(1.1);
  opacity: 0.9;
}

.dashboard-app-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.dashboard-app-favicon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

/* Nur Icon anzeigen – Label ausblenden */
.dashboard-app .dashboard-app-label {
  display: none;
}

.dashboard-app-empty {
  background: transparent;
  border: 1px dashed var(--border-color, var(--border));
  cursor: default;
}

.dashboard-app-empty:hover {
  transform: none;
}

/* Bearbeitungsmodus – Label und Rahmen sichtbar */
.dashboard-edit-mode .dashboard-app-in-edit .dashboard-app-label {
  display: -webkit-box;
  font-size: 0.6rem;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 0.15rem;
}
.dashboard-edit-mode .dashboard-app-in-edit,
.dashboard-edit-mode .dashboard-app-empty {
  background: rgba(255, 255, 255, 0.06);
  border: 1px dashed var(--border-color, var(--border));
  border-radius: var(--radius-sm);
}

/* Bearbeitungsmodus */
.dashboard-app-in-edit {
  cursor: pointer;
  position: relative;
}
.dashboard-app-edit-btn {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
  border: none;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.2s;
}
.dashboard-app-edit-btn:hover {
  opacity: 1;
}
.dashboard-app-delete-btn {
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  border: none;
  border-radius: 4px;
  background: #dc2626;
  color: #fff;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.2s;
}
.dashboard-app-delete-btn:hover {
  opacity: 1;
  background: #b91c1c;
}
.dashboard-app-add {
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 300;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.dashboard-app-add:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

/* App bearbeiten – Modal */
.app-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing);
}
.app-edit-modal[aria-hidden="true"],
.app-edit-modal[hidden] {
  display: none;
}
.app-edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
.app-edit-modal-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: var(--spacing-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.app-edit-modal-title {
  margin: 0 0 var(--spacing);
  font-size: 1.2rem;
}
.app-edit-form .app-edit-label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.app-edit-form .app-edit-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: var(--spacing);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 1rem;
}
.app-edit-actions {
  display: flex;
  gap: var(--spacing);
  margin-top: var(--spacing);
}
.app-edit-btn {
  padding: 0.5rem 1rem;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
}
.app-edit-cancel {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.app-edit-save {
  background: var(--accent);
  color: #fff;
}
.app-edit-save:hover {
  background: var(--accent-hover);
}
.app-edit-modal-close {
  position: absolute;
  top: var(--spacing);
  right: var(--spacing);
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.app-edit-modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

@media (max-width: 767px) {
  .dashboard-search-ki span {
    font-size: 0.8rem;
  }
}
