/*
 * Tastenkappen-Navigation für techprax.ch (Astro-Build).
 * Eingebunden in jede Seite über <link rel="stylesheet" href="/keycaps.css">.
 * Nutzt die Farb-Variablen der Hauptseite (--color-ink-*, --color-brand-*),
 * mit Fallbacks für Seiten ohne diese Variablen (/erp, /buspro-umstieg).
 * Aktive Seite = gedrückte Taste, gesteuert über aria-current="page".
 */

:root {
  --kc-top: #ffffff;
  --kc-face: var(--color-ink-100, #f3f2ec);
  --kc-edge: var(--color-ink-300, #c9c5b3);
  --kc-text: var(--color-ink-700, #3d3b32);
  --kc-text-hover: var(--color-ink-900, #1a1a16);
  --kc-active-top: var(--color-brand-600, #1f549b);
  --kc-active-face: var(--color-brand-800, #18386a);
  --kc-active-edge: var(--color-brand-950, #0b1c3a);
  --kc-focus: var(--color-brand-500, #2a6cba);
}

/* Desktop-Navigation (Astro), Mobile-Menü (Astro), Navigation /erp + /buspro-umstieg */
nav[aria-label='Hauptnavigation'] > a,
#mobile-menu a:not(.btn-primary),
#navlinks > a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.375rem 0.7rem;
  border: 1px solid var(--kc-edge);
  border-radius: 0.55rem;
  background: linear-gradient(to bottom, var(--kc-top), var(--kc-face));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.9),
    0 3px 0 var(--kc-edge),
    0 4px 10px -3px rgb(26 26 22 / 0.18);
  color: var(--kc-text);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition:
    transform 80ms ease-out,
    box-shadow 80ms ease-out,
    background 150ms;
}

nav[aria-label='Hauptnavigation'] {
  gap: 0.4rem;
  padding-bottom: 3px; /* Platz für die Tastenkante */
}

nav[aria-label='Hauptnavigation'] > a:hover,
#mobile-menu a:not(.btn-primary):hover,
#navlinks > a:hover {
  background: linear-gradient(to bottom, #ffffff, var(--color-ink-50, #fafaf7));
  color: var(--kc-text-hover);
}

nav[aria-label='Hauptnavigation'] > a:active,
#mobile-menu a:not(.btn-primary):active,
#navlinks > a:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.9),
    0 1px 0 var(--kc-edge),
    0 1px 3px -1px rgb(26 26 22 / 0.2);
}

nav[aria-label='Hauptnavigation'] > a:focus-visible,
#mobile-menu a:not(.btn-primary):focus-visible,
#navlinks > a:focus-visible {
  outline: 2px solid var(--kc-focus);
  outline-offset: 3px;
}

/* Aktive Seite: gedrückte Taste in Markenblau */
nav[aria-label='Hauptnavigation'] > a[aria-current='page'],
#mobile-menu a[aria-current='page']:not(.btn-primary) {
  transform: translateY(2px);
  border-color: var(--kc-active-edge);
  background: linear-gradient(
    to bottom,
    var(--kc-active-top),
    var(--kc-active-face)
  );
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.18),
    0 1px 0 var(--kc-active-edge);
  color: #ffffff;
}

/* Mobile-Menü: Tasten in voller Breite, linksbündig, mit Abstand */
#mobile-menu a:not(.btn-primary) {
  justify-content: flex-start;
  min-height: 2.75rem;
  padding: 0.6rem 1rem;
  margin-bottom: 0.45rem;
}

/* Hauptaktion («Termin anfragen» usw.) als Enter-Taste mit Tiefe */
.btn-primary {
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.18),
    0 3px 0 var(--kc-active-edge),
    0 6px 14px -6px rgb(11 28 58 / 0.45);
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.18),
    0 1px 0 var(--kc-active-edge);
}

/* Mittlere Breiten (1024–1279 px): kompakte Tasten, damit die Leiste passt */
@media (max-width: 1279px) {
  nav[aria-label='Hauptnavigation'] {
    gap: 0.2rem;
  }
  nav[aria-label='Hauptnavigation'] > a {
    min-height: 2rem;
    padding: 0.3rem 0.42rem;
    font-size: 0.78rem;
  }
}

/* /erp und /buspro-umstieg: eigene Navigation mit grossem Abstand */
#navlinks {
  gap: 0.45rem !important;
}
#navlinks > a {
  padding: 0.3rem 0.6rem;
  font-size: 0.9rem;
}
#navlinks.open > a {
  justify-content: flex-start;
  width: 100%;
}

@media (max-width: 1120px) {
  nav[aria-label='Hauptnavigation'] {
    gap: 0.12rem;
  }
  nav[aria-label='Hauptnavigation'] > a {
    padding: 0.28rem 0.32rem;
    font-size: 0.74rem;
  }
}
@media (min-width: 921px) and (max-width: 1120px) {
  #navlinks {
    gap: 0.25rem !important;
  }
  #navlinks > a {
    padding: 0.28rem 0.42rem;
    font-size: 0.82rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  nav[aria-label='Hauptnavigation'] > a,
  #mobile-menu a,
  #navlinks > a,
  .btn-primary {
    transition: none;
    transform: none !important;
  }
}

/* Den animierten Unterstrich der Hauptseite (.nav-link::after) braucht es
   bei Tasten nicht – die Taste selbst zeigt Hover und aktive Seite. */
nav[aria-label='Hauptnavigation'] > a::after {
  display: none;
}

/* Links, die in einem neuen Tab öffnen (z. B. «ERP-Software»): Pfeil-Hinweis,
   für Screenreader als Text «öffnet in neuem Tab» */
nav[aria-label='Hauptnavigation'] > a[target='_blank']::after,
#mobile-menu a[target='_blank']::after {
  content: '↗' / 'öffnet in neuem Tab';
  display: inline;
  position: static;
  height: auto;
  margin-left: 0.3em;
  background: none;
  transform: none;
  font-size: 0.85em;
  opacity: 0.7;
}

/* Footer-Link «ERP-Software» (neuer Tab): gleicher Pfeil-Hinweis */
footer a[href='/erp'][target='_blank']::after {
  content: '↗' / 'öffnet in neuem Tab';
  margin-left: 0.3em;
  font-size: 0.85em;
  opacity: 0.7;
}

/* «Fernwartung»: Taste leuchtet sanft grün pulsierend (Live-Hilfe-Signal).
   Hellgrüne Fläche, Ink-Text (Kontrast > 10:1), Glühring per Animation.
   Auf der Fernwartung-Seite selbst bleibt die Taste als «gedrückt» ohne Puls. */
@keyframes kc-pulse {
  0%,
  100% {
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 0.9),
      0 3px 0 #15803d,
      0 4px 10px -3px rgb(26 26 22 / 0.18),
      0 0 0 0 rgb(74 222 128 / 0.55);
  }
  50% {
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 0.9),
      0 3px 0 #15803d,
      0 4px 14px -2px rgb(22 163 74 / 0.45),
      0 0 0 7px rgb(74 222 128 / 0);
  }
}
nav[aria-label='Hauptnavigation'] > a[href='/fernwartung']:not([aria-current]),
#mobile-menu a[href='/fernwartung']:not([aria-current]) {
  border-color: #15803d;
  background: linear-gradient(to bottom, #f0fdf4, #bbf7d0);
  color: #14532d;
  animation: kc-pulse 2s ease-in-out infinite;
}
nav[aria-label='Hauptnavigation']
  > a[href='/fernwartung']:not([aria-current]):hover,
#mobile-menu a[href='/fernwartung']:not([aria-current]):hover {
  background: linear-gradient(to bottom, #ffffff, #dcfce7);
  color: #052e16;
}
nav[aria-label='Hauptnavigation']
  > a[href='/fernwartung']:not([aria-current]):active,
#mobile-menu a[href='/fernwartung']:not([aria-current]):active {
  animation: none;
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.9),
    0 1px 0 #15803d;
}
@media (prefers-reduced-motion: reduce) {
  nav[aria-label='Hauptnavigation'] > a[href='/fernwartung'],
  #mobile-menu a[href='/fernwartung'] {
    animation: none;
    box-shadow:
      inset 0 1px 0 rgb(255 255 255 / 0.9),
      0 3px 0 #15803d,
      0 0 0 3px rgb(74 222 128 / 0.45);
  }
}
