/* ==========================================================================
   Grundlagen & App-Rahmen (Sidebar, Navigationsleiste, Tab-Leiste)
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
@media (pointer: coarse) {
  html { font-size: 106.25%; }                       /* 17 px */
}
/* iPad/iPhone: Grundschrift folgt der Systemeinstellung „Textgröße“ (Dynamic Type) */
@supports (font: -apple-system-body) {
  @media (pointer: coarse) {
    html { font: -apple-system-body; }
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font-text);
  font-size: var(--text-body);
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern";
}

h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
img, svg { display: block; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--accent-ring);
  outline-offset: 2px;
  border-radius: 8px;
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }
.icon-xl { width: 52px; height: 52px; stroke-width: 1.4; }

.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--label-2); }

/* ---------------------------------------------------------------- Rahmen */

.app {
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.main {
  min-width: 0;
  padding-bottom: calc(108px + env(safe-area-inset-bottom));
  transition: padding-left var(--dur-slow) var(--ease-sheet);
}

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------------------------------------------------------------- Navigationsleiste */

.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-3);
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
}
/* Scroll-Edge-Effekt: Glas erscheint erst, wenn Inhalt darunter scrollt */
.navbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border-bottom: 0.5px solid var(--separator);
  opacity: 0;
  transition: opacity var(--dur) var(--ease-out);
}
.navbar.is-scrolled::before { opacity: 1; }

.navbar-leading, .navbar-trailing {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.navbar-trailing { justify-content: flex-end; }

.navbar-title {
  font-family: var(--font-display);
  font-size: var(--text-body);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}
.navbar.has-title .navbar-title { opacity: 1; transform: none; }

/* ---------------------------------------------------------------- Großer Titel */

.view-header {
  padding: var(--space-2) 0 var(--space-4);
}
.large-title {
  font-family: var(--font-display);
  font-size: var(--text-large-title);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.15;
}
.view-subtitle {
  margin-top: var(--space-1);
  color: var(--label-2);
  font-size: var(--text-subhead);
}
.title-sentinel { height: 1px; margin-bottom: -1px; }

/* ---------------------------------------------------------------- Sidebar (breite Fenster) */

.sidebar { display: none; }

@media (min-width: 900px) {
  .sidebar {
    position: fixed;
    z-index: 30;
    top: calc(10px + env(safe-area-inset-top));
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: calc(10px + env(safe-area-inset-left));
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    padding: var(--space-4) var(--space-3);
    border-radius: var(--radius-xl);
    background: var(--glass);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
    box-shadow: var(--shadow-glass), inset 0 0.5px 0 var(--glass-highlight);
    outline: 0.5px solid var(--glass-edge);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: transform var(--dur-slow) var(--ease-sheet), opacity var(--dur) var(--ease-out);
  }
  .main { padding-left: calc(var(--sidebar-w) + 20px); }

  .app.sidebar-collapsed .sidebar {
    transform: translateX(calc(-100% - 24px));
    opacity: 0;
    pointer-events: none;
  }
  .app.sidebar-collapsed .main { padding-left: 0; }

  .tabbar { display: none !important; }
  .main { padding-bottom: var(--space-10); }
  .compact-only { display: none !important; }
}
@media (max-width: 899.98px) {
  .regular-only { display: none !important; }
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2) var(--space-4);
}
.app-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  flex: none;
  box-shadow: 0 2px 8px rgba(196, 22, 28, 0.35);
}
.app-name {
  font-family: var(--font-display);
  font-size: var(--text-title3);
  font-weight: 700;
  line-height: 1.15;
}
.app-org {
  color: var(--label-2);
  font-size: var(--text-footnote);
  line-height: 1.25;
}

.side-section + .side-section { margin-top: var(--space-5); }
.side-label {
  padding: 0 var(--space-3) var(--space-2);
  color: var(--label-2);
  font-size: var(--text-footnote);
  font-weight: 600;
}
.side-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--control-h-lg);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--label);
  font-size: var(--text-body);
  transition: background-color var(--dur-fast) ease;
}
.side-item .icon { color: var(--accent); }
.side-item .count {
  margin-left: auto;
  color: var(--label-2);
  font-size: var(--text-subhead);
  font-variant-numeric: tabular-nums;
}
.side-item-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) {
  .side-item:hover { background: var(--fill-4); }
}
.side-item.is-active { background: var(--fill-2); font-weight: 600; }
.side-item:active { background: var(--fill-1); }

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  flex: none;
  box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.5);
  animation: live-pulse 2s var(--ease-out) infinite;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(52, 199, 89, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

.sidebar-foot {
  margin-top: auto;
  padding: var(--space-4) var(--space-3) var(--space-1);
  color: var(--label-2);
  font-size: var(--text-caption);
}
.kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--fill-3);
  font-family: var(--font-text);
  font-size: 0.9em;
  font-weight: 600;
  text-align: center;
}

/* ---------------------------------------------------------------- Tab-Leiste (schmale Fenster) */

.tabbar {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 5px;
  border-radius: var(--radius-pill);
  background: var(--glass-strong);  /* dichter: Beschriftung bleibt über bewegtem Inhalt lesbar */
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  box-shadow: var(--shadow-glass), inset 0 0.5px 0 var(--glass-highlight);
  outline: 0.5px solid var(--glass-edge);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 92px;
  min-height: 54px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  color: var(--label);
  font-size: var(--text-caption);
  font-weight: 600;
  transition: background-color var(--dur) var(--ease-out), color var(--dur) var(--ease-out);
}
.tab .icon { width: 24px; height: 24px; }
.tab.is-active { color: var(--accent); background: var(--fill-3); }
.tab:active { transform: scale(0.96); }

@media (max-width: 420px) {
  .tab { min-width: 0; flex: 1; padding: 6px 10px; }
  .tabbar { left: 12px; right: 12px; transform: none; }
}

/* ---------------------------------------------------------------- Lade-Bildschirm */

.boot {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--label-2);
}
