/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f5f5f7;
  --bg-elevated: #ececf1;
  --bg-card: #ffffff;
  --bg-hover: #ececf1;
  --border: #e2e2e7;
  --border-strong: #c7c7cc;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #8e8e93;
  --accent: #007aff;
  --accent-subtle: rgba(0, 122, 255, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --dropdown-bg: rgba(255, 255, 255, 0.96);
  --backdrop: rgba(0, 0, 0, 0.2);
  --kbd-bg: #e5e5ea;
  --kbd-text: #636366;
  --radius: 12px;
  --transition: 0.18s cubic-bezier(0.25, 0.1, 0.25, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-card: #161618;
    --bg-hover: #242428;
    --border: #2c2c2e;
    --border-strong: #3a3a3c;
    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-muted: #6e6e73;
    --accent: #0a84ff;
    --accent-subtle: rgba(10, 132, 255, 0.15);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.65);
    --dropdown-bg: rgba(28, 28, 30, 0.96);
    --backdrop: rgba(0, 0, 0, 0.55);
    --kbd-bg: #2c2c2e;
    --kbd-text: #98989d;
  }
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-card: #161618;
  --bg-hover: #242428;
  --border: #2c2c2e;
  --border-strong: #3a3a3c;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-muted: #6e6e73;
  --accent: #0a84ff;
  --accent-subtle: rgba(10, 132, 255, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.65);
  --dropdown-bg: rgba(28, 28, 30, 0.96);
  --backdrop: rgba(0, 0, 0, 0.55);
  --kbd-bg: #2c2c2e;
  --kbd-text: #98989d;
}

html[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elevated: #ececf1;
  --bg-card: #ffffff;
  --bg-hover: #ececf1;
  --border: #e2e2e7;
  --border-strong: #c7c7cc;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-muted: #8e8e93;
  --accent: #007aff;
  --accent-subtle: rgba(0, 122, 255, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --dropdown-bg: rgba(255, 255, 255, 0.96);
  --backdrop: rgba(0, 0, 0, 0.2);
  --kbd-bg: #e5e5ea;
  --kbd-text: #636366;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.hidden { display: none !important; }

/* ===== Loader ===== */
.loader {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: var(--bg);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.loader.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-ring {
  width: 28px;
  height: 28px;
  position: relative;
}

.loader-arc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--text-secondary);
  animation: spin 0.9s linear infinite;
}

.loader-text {
  margin-top: 14px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
}

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

/* ===== Main Layout ===== */
.main {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 36px 48px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  overflow-y: auto;
}
.main.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.header-btn:hover {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-strong);
}

.header-svg {
  width: 17px;
  height: 17px;
  display: block;
}

/* ===== Search Section (Top Search Bar) ===== */
.search-section {
  width: 100%;
  max-width: 580px;
  margin: 0 auto 20px;
  position: relative;
}

.search-wrapper {
  position: relative;
  width: 100%;
  z-index: 40;
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  padding: 0 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
}

.search-bar:focus-within,
.search-bar.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle), var(--shadow-sm);
}

.search-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-icon svg {
  width: 17px;
  height: 17px;
  display: block;
}

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.search-input::placeholder {
  color: var(--text-muted);
}

.search-clear-btn {
  border: none;
  background: var(--bg-elevated);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  transition: var(--transition);
  flex-shrink: 0;
}
.search-clear-btn:hover {
  color: var(--text);
  background: var(--border-strong);
}

.search-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--kbd-text);
  background: var(--kbd-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
  user-select: none;
}

/* Search Dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--dropdown-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 420px;
  animation: dropdownAppear 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
  z-index: 50;
}

@keyframes dropdownAppear {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-results {
  overflow-y: auto;
  padding: 6px;
  flex: 1;
}

.search-category {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.search-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s ease;
  user-select: none;
}

.search-item:hover,
.search-item.is-selected {
  background: var(--bg-hover);
}

.search-item-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.search-item-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.search-item.is-selected .search-item-icon,
.search-item:hover .search-item-icon {
  color: var(--accent);
}

.search-item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.search-item-title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-tag {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.search-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.search-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-elevated);
}

.search-footer-shortcuts {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-footer kbd {
  font-size: 10px;
  padding: 1px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-right: 3px;
}

/* ===== Quick Actions Section ===== */
.quick-actions-section {
  width: 100%;
  max-width: 580px;
  margin: 0 auto 32px;
}

.quick-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 15px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.quick-action-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.quick-action-btn:active {
  transform: translateY(0);
}

.quick-action-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.quick-action-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.quick-action-label {
  letter-spacing: -0.1px;
}

/* ===== Apps Grid ===== */
.apps-section {
  flex: none;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, 170px);
  justify-content: center;
  gap: 14px;
}

/* ===== App Card (zentriert) ===== */
.app-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 18px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  opacity: 0;
  transform: translateY(8px);
  animation: cardAppear 0.45s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.app-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.app-card:active {
  background: var(--bg-hover);
  transform: translateY(0);
}

.app-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border-radius: 10px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.app-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  color: inherit;
}

.app-card:hover .app-icon {
  color: var(--accent);
}

.app-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}

.app-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

@keyframes cardAppear {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Sanftes Einblenden der nachgeladenen Sektionen */
.conn-section:not(.hidden),
.recent-section:not(.hidden) {
  animation: sectionAppear 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
}

@keyframes sectionAppear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Verbindungen (schmale Chip-Reihe) ===== */
.conn-section {
  margin-top: 36px;
}

.conn-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.conn-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.conn-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  max-width: 260px;
}

.conn-chip:hover {
  border-color: var(--border-strong);
  background: var(--bg-elevated);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.conn-chip-icon {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.conn-chip:hover .conn-chip-icon {
  color: var(--accent);
}

.conn-chip-icon svg {
  width: 15px;
  height: 15px;
  display: block;
}

.conn-chip-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Recent-Sektion (Office-Stil) ===== */
.recent-section {
  margin-top: 40px;
}

.recent-heading {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.recent-rows {
  margin-top: 6px;
}

.recent-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  border-radius: 8px;
  transition: background var(--transition);
}

.recent-rows .recent-row:last-child {
  border-bottom: none;
}

.recent-row:hover {
  background: var(--bg-hover);
}

.recent-row-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.recent-row-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.recent-row-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.recent-row-title {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-row-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 80px 20px;
  text-align: center;
}
.empty-state p {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}
.empty-state span {
  font-size: 13px;
  color: var(--text-muted);
}

.empty-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  color: var(--text-muted);
}
.empty-icon svg {
  width: 28px;
  height: 28px;
}

/* ===== Footer ===== */
.footer {
  margin-top: 40px;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .main {
    padding: 24px 18px;
  }
  .header {
    margin-bottom: 20px;
  }
  .title {
    font-size: 22px;
  }
  .apps-grid {
    grid-template-columns: repeat(auto-fit, 150px);
    gap: 12px;
  }
  .app-card {
    padding: 18px 12px 16px;
  }
  .app-icon {
    width: 40px;
    height: 40px;
  }
  .app-icon svg {
    width: 20px;
    height: 20px;
  }
  .conn-section {
    margin-top: 26px;
  }
  .recent-section {
    margin-top: 32px;
  }
}

@media (max-width: 380px) {
  .apps-grid {
    grid-template-columns: repeat(2, 1fr);
    justify-content: center;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
