.app-shell {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 24px;
}

.sidebar-brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
  flex-shrink: 0;
}

.sidebar-brand-title {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.sidebar-brand-subtitle {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 1px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-muted);
  border: 1px solid transparent;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: var(--overlay-5); color: var(--text); }

.nav-item.active {
  background: var(--surface);
  color: var(--text);
  border-color: rgba(76, 141, 255, 0.35);
  box-shadow: 0 4px 14px rgba(76, 141, 255, 0.15);
}

.nav-item-icon-box {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--overlay-4);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-item.active .nav-item-icon-box { background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan)); }
.nav-item.active .nav-item-icon-box .nav-item-icon { color: var(--bg); }

.nav-item-icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-faint); }
.nav-item.active .nav-item-icon, .nav-item:hover .nav-item-icon { color: inherit; }

.nav-item-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  justify-content: flex-end;
}
.sidebar-toggle-btn {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--overlay-4);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.sidebar-toggle-btn:hover { background: var(--overlay-9); color: var(--text); }
.sidebar-toggle-icon { width: 15px; height: 15px; transition: transform 0.2s ease; }

/* ---------- Sidebar: collapsed state (html[data-sidebar="collapsed"], see sidebar-toggle.js) ---------- */

html[data-sidebar="collapsed"] .sidebar { width: var(--sidebar-width-collapsed); padding-left: 0; padding-right: 0; align-items: center; }
html[data-sidebar="collapsed"] .sidebar-brand,
html[data-sidebar="collapsed"] .nav-list,
html[data-sidebar="collapsed"] .sidebar-footer { width: 100%; }
html[data-sidebar="collapsed"] .sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
html[data-sidebar="collapsed"] .sidebar-brand-title,
html[data-sidebar="collapsed"] .sidebar-brand-subtitle,
html[data-sidebar="collapsed"] .nav-item-text { display: none; }
html[data-sidebar="collapsed"] .nav-list { align-items: center; }
html[data-sidebar="collapsed"] .nav-item { justify-content: center; width: 44px; padding-left: 0; padding-right: 0; }
html[data-sidebar="collapsed"] .sidebar-footer { justify-content: center; }
html[data-sidebar="collapsed"] .sidebar-toggle-icon { transform: rotate(180deg); }

/* ---------- Main column ---------- */

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  height: var(--header-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
}

.app-topbar-title { margin: 0; font-size: 18px; font-weight: 600; }
.app-topbar-subtitle { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

.app-topbar-right { display: flex; align-items: center; gap: 16px; }

.theme-toggle-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.theme-toggle-btn:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle-icon { display: none; width: 16px; height: 16px; }
:root:not([data-theme="light"]) .theme-toggle-icon-sun { display: flex; }
:root[data-theme="light"] .theme-toggle-icon-moon { display: flex; }

.app-content {
  flex: 1;
  overflow: auto;
  padding: 26px 28px;
}

.content-max {
  max-width: 1440px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Grid utilities ---------- */

.grid { display: grid; gap: 14px; }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid-cols-6 { grid-template-columns: repeat(6, 1fr); }
.grid-2fr-1fr { grid-template-columns: 2fr 1fr; align-items: start; gap: 20px; }

.row { display: flex; gap: 16px; }
.row-wrap { flex-wrap: wrap; }
.row-3 > * { flex: 1; min-width: 0; }
.row-align-start { align-items: flex-start; }

/* ---------- Dashboard: main column + Executive Summary side panel ---------- */

.dashboard-layout { display: flex; align-items: flex-start; gap: 20px; }
.dashboard-layout > .content-max { flex: 1; min-width: 0; }
.dashboard-summary-panel {
  width: 340px; flex-shrink: 0; position: sticky; top: 0;
  display: flex; flex-direction: column; gap: 16px;
}

/* ---------- Delikt-Explorer: search workbench + persistent 3-column grid (Hierarchie | Treffer | Profil) ---------- */

/* .content-max caps every other page at 1440px so long-form content stays
   readable; the Explorer is a dense data workbench, not a text page, so it
   opts out of that cap and uses the full width .app-content leaves after
   the sidebar (230px/72px collapsed) and its own 28px side padding. */
.explorer-page { max-width: none; width: 100%; }

.explorer-search-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 12px;
}
.explorer-search-row { display: flex; align-items: center; gap: 14px; }
.explorer-mode-row { flex-shrink: 0; margin: 0; }
.explorer-search-input { flex: 1; min-width: 0; height: 42px; font-size: 15px; }
.explorer-search-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.explorer-advanced-chips { display: flex; flex-direction: column; gap: 8px; }

.explorer-main-grid {
  display: grid; grid-template-columns: minmax(390px, 1.15fr) minmax(350px, 0.95fr) minmax(560px, 1.55fr);
  gap: 16px; align-items: stretch;
}
.explorer-panel {
  min-width: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden;
  /* Viewport-based, not a fixed px height: 100vh minus the fixed app chrome
     above the panels (62px topbar + 26px top/bottom .app-content padding =
     114px) and a reasoned estimate for the search card, the context-preview
     bar and the two 22px gaps between .content-max's children above/below
     the grid (~226px). min-height is the floor on short viewports; if the
     estimate runs a little generous, .app-content (overflow:auto) simply
     scrolls a bit rather than breaking - not pixel-measured in a real
     browser, see ADR. */
  height: calc(100vh - 340px);
  min-height: 560px;
}
.explorer-panel-header {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.explorer-panel-title { font-size: 13px; font-weight: 600; color: var(--text); }
.explorer-panel-subtitle { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.explorer-panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; }
.explorer-panel-body-flex { display: flex; flex-direction: column; padding: 16px 18px; }
.profile-breadcrumb { margin-bottom: 6px; }
.profile-tab-pills { margin-top: 14px; flex-shrink: 0; }
.profile-tab-content { flex: 1; min-height: 0; overflow-y: auto; margin-top: 14px; }
.explorer-profile-actions {
  flex-shrink: 0; display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}

.explorer-context-preview {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 20px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
}
.explorer-context-preview-label { font-size: 12px; font-weight: 600; color: var(--text-faint); white-space: nowrap; }
.explorer-context-preview-fields { display: flex; gap: 22px; flex-wrap: wrap; flex: 1; }
.explorer-context-preview-note { font-size: 12px; color: var(--text-muted); max-width: 340px; line-height: 1.4; }

@media (max-width: 1200px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-6 { grid-template-columns: repeat(3, 1fr); }
  .grid-2fr-1fr { grid-template-columns: 1fr; }
  .row-3 { flex-direction: column; }
  .dashboard-layout { flex-direction: column; }
  .dashboard-summary-panel { width: 100%; position: static; }
  .explorer-main-grid { grid-template-columns: 1fr 1fr; }
  .explorer-profile-panel { grid-column: 1 / -1; height: 460px; }
}

@media (max-width: 800px) {
  .explorer-search-row { flex-wrap: wrap; }
  .explorer-main-grid { grid-template-columns: 1fr; }
  .explorer-profile-panel { grid-column: auto; }
  .explorer-panel { height: 420px; min-height: 420px; }
}

@media (max-width: 760px) {
  .grid-cols-3, .grid-cols-4, .grid-cols-6 { grid-template-columns: repeat(2, 1fr); }
  .sidebar { display: none; }
}
