:root {
  /* hr-* Backward-Aliase → semantische Tokens */
  --hr-bg-page: var(--bg-app);
  --hr-link-color: var(--accent-text);
  --hr-link-hover-bg: var(--accent-soft);
  --hr-link-soft: var(--accent-soft);
  --hr-primary-deep: var(--text-primary);
  --hr-primary-soft: var(--text-secondary);
  --hr-primary-light: var(--bg-surface-alt);
  --hr-neutral-100: var(--bg-surface);
  --hr-neutral-200: var(--bg-surface-alt);
  --hr-neutral-300: var(--border-default);
  --hr-neutral-400: var(--border-strong);
  --hr-text-dark: var(--text-primary);
  --hr-text-muted: var(--text-secondary);
  --hr-shadow-sm: var(--shadow-sm);
  --hr-shadow-md: var(--shadow-md);

  --sidebar-width: 230px;
}

/* ══════════════════════════════════════════════════════════════
   Vertikale Sidebar (Desktop)
   ══════════════════════════════════════════════════════════════ */
.navbar {
  background: var(--nav-bg);
  border-right: 1px solid var(--border-default);
  box-shadow: none;
  position: relative;
  z-index: 50;
}

.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100dvh;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.22s ease, min-width 0.22s ease;
}

.nav-container {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0;
}

/* ── Logo ──────────────────────────────────────────────────── */
.nav-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  padding: 1.1rem 1.2rem 0.8rem;
}

.nav-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.nav-powered-by {
  display: none;
}

.nav-logo-kicker {
  display: none;
}

.nav-logo-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  line-height: 1.15;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Kategorie-Label ───────────────────────────────────────── */
.nav-section-label {
  padding: 1.2rem 1.2rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* ── Nav-Items (vertikal) ──────────────────────────────────── */
.nav-main {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  flex: 0 0 auto;
  padding: 0.4rem 0.65rem;
  border-radius: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.app-nav-item {
  text-decoration: none;
  font-weight: 500;
  color: var(--nav-item-color);
  font-size: 0.88rem;
  transition: background 0.16s ease, color 0.16s ease;
  padding: 0.52rem 0.7rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  position: relative;
  min-height: 38px;
  box-shadow: none;
  width: 100%;
  justify-content: flex-start;
  white-space: nowrap;
  letter-spacing: 0;
}

.app-nav-item .material-icons {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  font-size: 1.15rem;
  color: currentColor;
  border-radius: 0;
  background: transparent;
  flex-shrink: 0;
  opacity: 0.7;
  transition: color 0.16s ease, opacity 0.16s ease;
}

.app-nav-item::before {
  content: none;
}

.app-nav-item::after {
  content: none;
}

.app-nav-item:hover:not(.is-active) {
  background: var(--nav-item-hover-bg);
  color: var(--text-primary);
}

.app-nav-item:hover:not(.is-active) .material-icons {
  opacity: 1;
}

.app-nav-item.is-active {
  background: var(--nav-item-active-bg);
  color: var(--nav-item-active-color);
  font-weight: 600;
  border-color: transparent;
  box-shadow: none;
}

.app-nav-item.is-active .material-icons {
  color: var(--nav-item-active-color);
  background: transparent;
  opacity: 1;
}

/* Kein Pfeil-Dreieck mehr (war horizontal) */
.app-nav-item.is-active::after {
  content: none;
}

/* ── Spacer (drueckt Footer nach unten) ────────────────────── */
.nav-spacer {
  display: block;
  flex: 1 1 auto;
}

/* ── Footer (unten in der Sidebar) ─────────────────────────── */
.nav-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-left: 0;
  padding: 0.65rem 0.65rem 0.8rem;
  border-top: 1px solid var(--border-default);
}

.nav-quick-icons {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0 0.55rem;
}

.nav-quick-icons i {
  font-size: 1.1rem;
  color: var(--nav-item-color);
  transition: color 0.2s;
  cursor: default;
  user-select: none;
}

.nav-quick-icons i:hover {
  color: var(--text-primary);
}

/* ── Sprachpicker ──────────────────────────────────────────── */
.nav-lang {
  position: relative;
  display: inline-block;
}

.nav-lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border-default);
  background: var(--bg-surface-alt);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  font-family: inherit;
}

.nav-lang-trigger:hover,
.nav-lang-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.nav-lang-flag {
  width: 22px;
  height: 16px;
  border-radius: 2px;
  display: block;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.lang-dropdown .lang-flag-wrap {
  display: inline-flex;
  align-items: center;
}

.nav-lang-chevron {
  font-size: 1rem;
  color: var(--text-tertiary);
  transition: transform 0.18s ease;
}

.nav-lang-trigger[aria-expanded="true"] .nav-lang-chevron {
  transform: rotate(180deg);
}

.nav-lang-list {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  list-style: none;
  padding: 0.35rem;
  margin: 0;
  z-index: 200;
  display: none;
}

.nav-lang-list.open {
  display: block;
}

.nav-lang-list li {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-primary);
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-lang-list li:hover {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.nav-lang-list li.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.nav-lang-list li .lang-check {
  margin-left: auto;
  font-size: 1rem;
  color: var(--accent-text);
}

.nav-lang-list li img {
  width: 22px;
  height: 16px;
  border-radius: 2px;
  display: block;
  object-fit: cover;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.08);
  flex-shrink: 0;
}

/* ── User-Karte (unten in Sidebar, Name + Rolle sichtbar) ── */
.nav-user-card {
  position: relative;
}

.nav-user-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.18s ease;
  width: 100%;
}

.nav-user-trigger:hover {
  background: var(--nav-item-hover-bg);
}

.nav-user-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-user-avatar {
  width: 34px;
  height: 34px;
  background: var(--bg-surface-alt);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.85rem;
  border: 1px solid var(--border-default);
  box-shadow: none;
  transition: border-color 0.18s ease;
  flex-shrink: 0;
}

.nav-user-trigger:hover .nav-user-avatar,
.nav-user-trigger.is-open .nav-user-avatar {
  border-color: var(--accent);
}

.nav-user-initials {
  color: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0;
}

.nav-user-status {
  display: none;
}

/* Name + Rolle neben Avatar anzeigen */
.nav-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.nav-user-meta #navUserName {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-user-meta #navUserRole {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── User-Dropdown ────────────────────────────────────────── */
.user-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  min-width: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem 0;
  z-index: 200;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.user-menu[data-open="true"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.user-menu[hidden] {
  display: none;
}

.user-menu-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0.65rem 1rem 0.85rem;
  border-bottom: 1px solid var(--border-default);
}

.user-menu-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-role {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-menu-list {
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0;
}

.user-menu-item {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 1rem;
  background: transparent;
  border: 0;
  width: 100%;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.user-menu-item .material-icons {
  font-size: 1.1rem;
  color: var(--text-secondary);
  transition: color 0.14s ease;
}

.user-menu-item:hover {
  background: var(--bg-surface-alt);
}

.user-menu-item:hover .material-icons {
  color: var(--text-primary);
}

.user-menu-item.is-danger {
  color: var(--signal-red);
}

.user-menu-item.is-danger .material-icons {
  color: var(--signal-red);
}

.user-menu-item.is-danger:hover {
  background: var(--signal-red-light);
}

.user-menu-item[hidden] {
  display: none;
}

.user-menu-divider {
  height: 1px;
  background: var(--border-default);
  margin: 0.35rem 0;
}

/* ── Sub-Menü (Flyout bei Hover) ─────────────────────────── */
.user-menu-sub {
  position: relative;
}

.user-menu-sub-trigger {
  justify-content: flex-start;
}

.user-menu-sub-chevron {
  margin-left: auto;
  font-size: 1rem;
  color: var(--text-tertiary);
}

.user-menu-sub-list {
  position: fixed;
  min-width: 170px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0.35rem 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
}

.user-menu-sub-list[hidden] {
  display: none;
}

.user-menu-sub-list .user-menu-item {
  font-size: 0.84rem;
  padding: 0.48rem 0.85rem;
  gap: 0.55rem;
}

.user-menu-sub-list .user-menu-item .material-icons {
  font-size: 1rem;
}

.user-menu-check {
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--accent);
}

.user-menu-check[hidden] {
  display: none;
}

/* ── Sidebar Collapse (Desktop) ───────────────────────────── */
.app-sidebar.collapsed {
  display: none;
}

.nav-toggle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-default);
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
  margin: 0 0.55rem;
}

.nav-toggle .material-icons {
  font-size: 1rem;
}

.nav-toggle:hover {
  color: var(--text-primary);
  background: var(--nav-item-hover-bg);
}

.nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-restore-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.8rem);
  left: 1rem;
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.52rem 0.84rem;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--nav-bg);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 85;
}

.nav-restore-toggle .material-icons {
  font-size: 1rem;
}

.nav-restore-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.nav-restore-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.nav-collapsed .nav-restore-toggle {
  display: inline-flex;
}

/* ── Firma-Switch-Modal ───────────────────────────────────── */
.firma-switch-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.firma-switch-modal[hidden] {
  display: none;
}

.firma-switch-backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.firma-switch-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.firma-switch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  background: var(--modal-header-bg);
  border-bottom: 1px solid var(--modal-border);
}

.firma-switch-header h2 {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--modal-header-text);
}

.firma-switch-close-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.firma-switch-close-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.firma-switch-close-btn .material-icons {
  font-size: 20px;
}

.firma-switch-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 60vh;
  overflow-y: auto;
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.firma-switch-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.firma-switch-item:hover:not(.is-current):not(:disabled) {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  background: var(--bg-surface-hover);
}

.firma-switch-item.is-current {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
  cursor: default;
}

.firma-switch-item-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
}

.firma-switch-item-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.firma-switch-item-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.firma-switch-item.is-current .firma-switch-item-meta {
  color: var(--accent-text);
}

.firma-switch-item-current-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  flex-shrink: 0;
}

body.modal-open {
  overflow: hidden;
}

/* ── Mobile Sidebar Backdrop ──────────────────────────────── */
.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 90;
}

.app-sidebar-backdrop.is-open {
  display: block;
}

/* ══════════════════════════════════════════════════════════════
   Mobile (<860px): Sidebar wird Off-Canvas-Drawer
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .app-sidebar.is-open {
    transform: translateX(0);
  }

  /* Collapsed-State auf Mobile ignorieren – Drawer uebernimmt */
  .app-sidebar.collapsed {
    display: flex;
    transform: translateX(-100%);
  }

  .app-sidebar.collapsed.is-open {
    transform: translateX(0);
  }

  .nav-toggle {
    display: none;
  }

  body.nav-collapsed .nav-restore-toggle {
    display: none;
  }
}

@media (max-width: 480px) {
  .firma-switch-modal {
    padding: 0;
    align-items: stretch;
  }

  .firma-switch-card {
    border-radius: 0;
    max-width: 100%;
    max-height: 100dvh;
  }

  .firma-switch-list {
    max-height: none;
    flex: 1;
  }
}
