#app { min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}
.app-logo { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 8px; white-space: nowrap; flex-shrink: 0; }
.app-logo .logo-mark { color: var(--accent); font-size: 18px; }
.sidebar-toggle-btn {
  display: none; background: none; border: 1px solid var(--border); color: var(--text-primary);
  border-radius: var(--radius-sm); padding: 6px 10px; font-size: 15px; flex-shrink: 0;
}
.search-box { position: relative; flex: 1; min-width: 0; max-width: 420px; }
#search-input {
  width: 100%; min-width: 0; background: var(--surface-alt); border: 1px solid var(--border); color: var(--text-primary);
  padding: 8px 12px; border-radius: var(--radius-md); font-size: 14px;
}
#search-input:focus { border-color: var(--accent); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; display: none;
  max-height: 340px; overflow-y: auto; box-shadow: 0 12px 28px rgba(0,0,0,0.45); z-index: 60;
}
.search-results.open { display: block; }
.header-actions { margin-left: auto; display: flex; gap: 10px; flex-shrink: 0; }
.header-fav-link {
  display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 14px;
  padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap;
}
.header-fav-link:hover { background: var(--surface-hover); color: var(--text-primary); }

/* Body / sidebar / main */
.app-body { flex: 1; display: flex; min-height: 0; }

.app-sidebar {
  width: var(--sidebar-width); flex-shrink: 0; border-right: 1px solid var(--border);
  background: var(--surface); padding: 16px 10px 40px; overflow-y: auto;
}

.app-main { flex: 1; padding: 28px 32px 60px; overflow-y: auto; max-width: 1440px; }

/* Demo workspace grid */
.demo-workspace { display: grid; grid-template-columns: 1fr 300px; gap: 20px; margin-top: 18px; align-items: start; }
.demo-sim {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  min-height: 480px; height: 480px; position: relative; overflow: hidden;
}
/* Used by demos that stack a visualization and a graph in the same sim area (PID
   controller, double pendulum, circuit oscillations) — the default 480px leaves each
   only ~200px, too cramped to read a multi-line chart clearly. */
.demo-sim.demo-sim-tall { height: 760px; min-height: 760px; }
@media (max-width: 980px) {
  .demo-sim.demo-sim-tall { height: 640px; min-height: 640px; }
}
.demo-sim canvas { width: 100%; height: 100%; display: block; }
.demo-controls-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px; position: sticky; top: calc(var(--header-height) + 16px);
  max-height: calc(100vh - var(--header-height) - 32px); overflow-y: auto;
}
.controls-toggle { display: none; }
.demo-stats {
  margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 22px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 14px 26px;
}
.demo-explanation { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--border); max-width: 800px; }

.breadcrumb { margin-bottom: 10px; }
.breadcrumb a { color: var(--text-secondary); font-size: 13px; }
.breadcrumb a:hover { color: var(--accent); }
.demo-title-row { display: flex; align-items: center; gap: 12px; }
.demo-title-row h1 { margin: 0; font-size: 26px; }
.demo-description-lg { max-width: 720px; margin-top: 4px; font-size: 15px; }

@media (max-width: 980px) {
  .app-sidebar {
    position: fixed; left: -270px; top: var(--header-height); bottom: 0; z-index: 45;
    transition: left 0.2s ease; box-shadow: 10px 0 30px rgba(0,0,0,0.5); width: 260px;
  }
  body.sidebar-open .app-sidebar { left: 0; }
  .sidebar-toggle-btn { display: inline-flex; }
  .demo-workspace { grid-template-columns: 1fr; }
  .demo-controls-panel { position: static; max-height: none; }
  .demo-sim { height: 380px; min-height: 380px; }
  .app-main { padding: 20px 16px 40px; }
  .search-box { max-width: none; }
}

@media (max-width: 560px) {
  .app-logo .logo-text { display: none; }
  .header-fav-label { display: none; }
  .app-header { padding: 0 12px; gap: 10px; }
  .header-fav-link { padding: 6px 8px; }
}

body.sidebar-open::after {
  content: ''; position: fixed; inset: 0; top: var(--header-height); background: rgba(0,0,0,0.55); z-index: 40;
}
