/* ─── Overlays: Modal, Credential-Hint-Banner, Info-Tooltip ─── */

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: calc(var(--space-5) + env(safe-area-inset-top, 0px)) calc(var(--space-5) + env(safe-area-inset-right, 0px)) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)) calc(var(--space-5) + env(safe-area-inset-left, 0px));
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: fadeIn 150ms ease;
}
/* Handy: Modale von unten wie ein Sheet, mit Tastatur oben ausgerichtet. */
@media (max-width: 600px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-card, .modal-card.modal-card-lg {
    max-width: none;
    border-radius: 18px 18px 0 0;
    border-left: none; border-right: none; border-bottom: none;
    padding: var(--space-5) calc(var(--space-5) + env(safe-area-inset-right, 0px)) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)) calc(var(--space-5) + env(safe-area-inset-left, 0px));
    max-height: 85vh;
    animation: sheetUp 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  @keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.modal-card h2 {
  font-size: var(--fs-base);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.modal-card .input-group {
  margin-bottom: 14px;
}

.modal-card .input-group label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.modal-error {
  color: var(--error);
  font-size: var(--fs-sm);
  min-height: 1.2em;
}

.modal-success {
  color: var(--success);
  font-size: var(--fs-sm);
  min-height: 1.2em;
}

.modal-card-lg {
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .modal-card-lg {
    max-width: 100%;
    max-height: 90vh;
  }
}

@media (min-width: 768px) {
  .modal-card {
    max-width: 420px;
    padding: 28px;
  }
}

/* Credential Hint Banner (non-blocking) */

.cred-hint {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  margin: var(--space-2) var(--space-4);
  font-size: var(--fs-xs);
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.cred-hint svg {
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.cred-hint a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.cred-hint-close {
  flex-shrink: 0;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: var(--fs-md);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.cred-hint-close:hover {
  color: var(--text-primary);
}

/* Info-Tooltip (ⓘ) — CSS-only, Hover + Fokus (Tap auf Touch fokussiert). */

.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: -1px;
  color: var(--text-muted);
  cursor: help;
  outline: none;
}

.info-tip:hover,
.info-tip:focus {
  color: var(--text-secondary);
  z-index: var(--z-tip);
}

.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: -8px;
  width: max-content;
  max-width: min(280px, 78vw);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: var(--fs-xs);
  font-weight: 400;
  line-height: 1.5;
  text-align: left;
  white-space: normal;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  /* display:none statt visibility:hidden — eine unsichtbare, absolut
     positionierte Blase zählt sonst zur Overflow-Breite und macht die
     Seite horizontal scrollbar. */
  display: none;
  pointer-events: none;
  z-index: var(--z-tip);
}

.info-tip:hover::after,
.info-tip:focus::after {
  display: block;
}

/* In den KPI-Karten sitzt das ⓘ hinter dem Label — Blase nicht am Kartenrand
   abschneiden lassen (öffnet nach rechts ab Icon-Position). */

.kpi-lbl .info-tip { margin-left: 2px; }

.dash-card-head h3 .info-tip { margin-left: 4px; }

/* Rechte KPI-Spalten: Blase nach links öffnen, sonst läuft sie aus dem Viewport. */

@media (max-width: 639px) {
  .dash-kpis .kpi-card:nth-child(even) .info-tip::after { left: auto; right: -8px; }
}

@media (min-width: 640px) and (max-width: 899px) {
  .dash-kpis .kpi-card:nth-child(3n) .info-tip::after { left: auto; right: -8px; }
}

@media (min-width: 900px) and (max-width: 1199px) {
  .dash-kpis .kpi-card:nth-child(4n) .info-tip::after { left: auto; right: -8px; }
}

@media (min-width: 1200px) {
  .dash-kpis .kpi-card:nth-child(7n) .info-tip::after { left: auto; right: -8px; }
}

/* Horizontal scrollen ist tabu (Native-App-Gefühl) — auch eine geöffnete
   Tooltip-Blase am Rand darf die Seite nie in die Breite ziehen. */

.dash-home-scroll { overflow-x: hidden; }

/* ── Befehlspalette (⌘K) ────────────────────────────────────────────────── */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--space-4) var(--space-4);
  animation: fadeIn 120ms ease;
}
.cmdk {
  width: min(560px, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.cmdk-input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: var(--fs-input);
  color: var(--text-primary);
  outline: none;
}
.cmdk-list { overflow-y: auto; padding: var(--space-1) 0; }
.cmdk-group {
  padding: 8px var(--space-4) 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 8px var(--space-4);
  border: none;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}
.cmdk-item.is-active, .cmdk-item:hover { background: var(--accent-muted); }
.cmdk-icon { display: inline-flex; color: var(--text-muted); flex-shrink: 0; }
.cmdk-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-hint { font-size: var(--fs-xs); color: var(--text-muted); flex-shrink: 0; }
.cmdk-empty { padding: var(--space-6) var(--space-4); text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }
.cmdk-foot {
  display: flex;
  gap: var(--space-3);
  padding: 6px var(--space-4);
  border-top: 1px solid var(--border);
  font-size: 10.5px;
  color: var(--text-muted);
}
.cmdk-foot kbd {
  font-family: var(--font);
  font-size: 10px;
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-tertiary);
  margin-right: 2px;
}
@media (max-width: 860px) {
  .cmdk-overlay { padding: max(var(--safe-top), 8px) var(--space-2) var(--space-2); align-items: stretch; }
  .cmdk { max-height: none; }
  .cmdk-foot { display: none; }
}
