/* ===== APP SHELL ===== */
.app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width); background: #1e293b; color: #e2e8f0;
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 200; transition: transform var(--transition);
}
.sidebar-logo {
  padding: 1.1rem 1.2rem; border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 700; font-size: 1rem; color: #fff; display: flex; align-items: center; gap: 0.5rem;
}
.sidebar-logo .logo-icon { font-size: 1.4rem; }
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.nav-section { padding: 0.4rem 1rem; font-size: 0.7rem; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 0.75rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 1.2rem; font-size: 0.875rem; color: #94a3b8;
  cursor: pointer; transition: var(--transition); border-radius: 0;
  user-select: none;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: #e2e8f0; }
.nav-item.active { background: rgba(37,99,235,0.3); color: #fff; border-left: 3px solid var(--color-primary); padding-left: calc(1.2rem - 3px); }
.nav-item .nav-icon { font-size: 1.1rem; width: 1.3rem; text-align: center; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.nav-icon svg, .bn-icon svg { width: 1.2rem; height: 1.2rem; stroke-width: 1.75; }
.nav-badge {
  margin-left: auto; background: var(--color-danger);
  color: #fff; border-radius: 999px; font-size: 0.7rem;
  padding: 0.1rem 0.45rem; font-weight: 700; min-width: 18px; text-align: center;
}

/* ===== SIDEBAR COLLAPSED ===== */
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .sidebar-logo-text { display: none; }
.sidebar.collapsed #sidebarCollapseBtn { transform: rotate(180deg); }
.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .nav-section { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 0.65rem 0; }
.sidebar.collapsed .nav-icon { width: auto; font-size: 1.3rem; }
.sidebar.collapsed .nav-badge { display: none; }
.main.sidebar-collapsed { margin-left: 60px; }

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1; display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  height: var(--topbar-height); background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

/* Global Search */
.global-search-wrapper { position: relative; }
.global-search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  max-height: 320px; overflow-y: auto; z-index: 500;
}
.global-search-results.hidden { display: none; }
.search-result-item {
  padding: 0.5rem 0.85rem; cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem;
}
.search-result-item:hover { background: var(--color-bg); }
.search-result-type { font-size: 0.72rem; padding: 0.1rem 0.35rem; border-radius: 3px; background: var(--color-bg); color: var(--color-text-muted); flex-shrink: 0; }
.search-result-label { font-weight: 500; }
.search-result-sub { color: var(--color-text-muted); font-size: 0.8rem; }
.search-group-header { padding: 0.4rem 0.85rem; font-size: 0.72rem; font-weight: 600; color: var(--color-text-muted); background: var(--color-bg); text-transform: uppercase; letter-spacing: 0.05em; }

.content { padding: 1.5rem; flex: 1; }

/* ===== MOBILE TOGGLE ===== */
.sidebar-toggle {
  display: none; background: none; border: none; cursor: pointer;
  padding: 0.4rem; color: var(--color-text);
}

/* ===== RESPONSIVE ===== */
/* ===== CHART GRID (Dashboard) ===== */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ===== TABLET (769px – 1024px): Sidebar auto-collapsed ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar:not(.tablet-expanded) {
    width: 60px;
  }
  .sidebar:not(.tablet-expanded) .sidebar-logo-text { display: none; }
  .sidebar:not(.tablet-expanded) .nav-label { display: none; }
  .sidebar:not(.tablet-expanded) .nav-section { display: none; }
  .sidebar:not(.tablet-expanded) .nav-item { justify-content: center; padding: 0.65rem 0; }
  .sidebar:not(.tablet-expanded) .nav-icon { width: auto; font-size: 1.3rem; }
  .sidebar:not(.tablet-expanded) .nav-badge { display: none; }
  .main:not(.tablet-sidebar-expanded) { margin-left: 60px; }
  .sidebar:not(.tablet-expanded) #sidebarCollapseBtn { transform: rotate(180deg); }
}

/* ===== MOBILE (<= 768px) ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .main { margin-left: 0; }
  .content { padding: 1rem; padding-bottom: calc(var(--bottom-nav-height) + 1rem); }
  .table-wrapper { max-width: 100%; -webkit-overflow-scrolling: touch; }
  .form-row { grid-template-columns: 1fr; }
  .form-row.three { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header > div:last-child { display: flex; flex-wrap: wrap; gap: 0.4rem; width: 100%; }
  .page-header .btn { flex-shrink: 0; }
  .chart-grid { grid-template-columns: 1fr !important; }
  /* Fix 1: Topbar komprimieren */
  .global-search-wrapper { display: none; }
  #topbarUser { display: none; }
  #btnLogout { font-size: 0; padding: 0.35rem 0.55rem; }
  #btnLogout::after { content: '↪'; font-size: 1rem; }
  .topbar { padding: 0 0.75rem; }
  .topbar-right { gap: 0.4rem; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  /* Filter-Row: vertikal stapeln auf kleinen Screens */
  .filter-row { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .filter-row select, .filter-row input { min-width: 0; font-size: 0.9rem; width: 100%; }
}

/* ===== MOBILE BOTTOM NAV ===== */
#mobileBottomNav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  z-index: var(--z-bottom-nav);
  align-items: stretch;
  justify-content: space-around;
}

@media (max-width: 768px) {
  #mobileBottomNav { display: flex; }
}

.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; gap: 0.2rem; padding: 0.3rem 0.25rem;
  color: var(--color-text-muted); font-size: 0.65rem; font-weight: 500;
  cursor: pointer; border: none; background: none;
  transition: color var(--transition); position: relative;
  min-height: 44px;
}
.bottom-nav-item .bn-icon { font-size: 1.3rem; line-height: 1; }
.bottom-nav-item.active { color: var(--color-primary); }
.bottom-nav-item.active::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 32px; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--color-primary);
}
.bottom-nav-item .bn-badge {
  position: absolute; top: 4px; right: calc(50% - 18px);
  background: var(--color-danger); color: #fff;
  border-radius: 999px; font-size: 0.6rem; padding: 0.05rem 0.3rem;
  min-width: 16px; text-align: center; font-weight: 700;
}
.bottom-nav-item .bn-badge.hidden { display: none; }

/* ===== SIDEBAR OVERLAY (mobile) ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 199;
}
.sidebar-overlay.visible { display: block; }
