/* EchoLab global chrome — mobile-first; desktop persistent sidebar */

:root {
  --header-height: 52px;
  --echolab-accent: #6ea8fe;
  --echolab-accent-soft: rgba(110, 168, 254, 0.14);
  /* Slightly elevated vs drawer for depth */
  --echolab-chrome-bg: #16161a;
  --echolab-chrome-border: rgba(255, 255, 255, 0.06);
  --echolab-topbar-border: #1f2937;
  --echolab-drawer-bg: #0c0c0e;
  --echolab-text: #e8eaed;
  --echolab-muted: #8b919a;
  --echolab-top-h: 0px;
  --echolab-sidebar-w: 260px;
  --echolab-ease: cubic-bezier(0.25, 0.1, 0.25, 1);
}

#echolab-chrome {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--header-height, 52px);
  z-index: 9999;

  /* Match reading page background; divider matches footer/input bar (var(--border) from theme.css) */
  background: var(--bg-main, #f4ecd8);
  border-bottom: 1px solid var(--border, rgba(46, 46, 46, 0.12));
  isolation: isolate;

  --echolab-transition: 300ms var(--echolab-ease);
}

#echolab-chrome .echolab-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Backdrop (mobile) */
#echolab-chrome .echolab-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 998;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity var(--echolab-transition);
  pointer-events: none;
}

body.echolab-nav-open #echolab-chrome .echolab-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Drawer / sidebar */
#echolab-chrome .echolab-drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  width: min(80vw, 320px);
  height: 100dvh;
  background: var(--echolab-drawer-bg);
  border-right: 1px solid var(--echolab-chrome-border);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
  transform: translateX(-100%);
  transition: transform var(--echolab-transition);
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body.echolab-nav-open #echolab-chrome .echolab-drawer {
  transform: translateX(0);
}

#echolab-chrome .echolab-drawer-inner {
  padding: calc(var(--echolab-top-h) + 12px) 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
}

#echolab-chrome .echolab-drawer-tagline {
  font-size: 0.72rem;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.35;
  margin-top: 3px;
  color: var(--echolab-muted, var(--text-muted, #888));
}

#echolab-chrome .echolab-drawer-brand {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  color: var(--echolab-text);
  padding: 4px 12px 12px;
  border-bottom: 1px solid var(--echolab-chrome-border);
  margin-bottom: 8px;
}

#echolab-chrome .echolab-drawer-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#echolab-chrome .echolab-nav-link {
  display: block;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--echolab-muted);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

#echolab-chrome .echolab-nav-link:hover {
  color: var(--echolab-text);
  background: rgba(255, 255, 255, 0.04);
}

#echolab-chrome .echolab-nav-link.is-active {
  color: var(--echolab-accent);
  font-weight: 700;
  background: var(--echolab-accent-soft);
}

/* Top bar */
#echolab-chrome .echolab-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  height: 0;
  display: block;
  padding: 0;
  background: transparent;
  border-bottom: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
}

#echolab-chrome .echolab-burger {
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  left: 10px;
  z-index: 20;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-main, #2e2e2e);
  cursor: pointer;
  transition: background 0.15s ease;
  pointer-events: auto;
}

#echolab-chrome .echolab-logout {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 10px;
  z-index: 21;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--border, rgba(46, 46, 46, 0.15));
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg-main, #f4ecd8) 88%, transparent);
  color: var(--text-main, #2e2e2e);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  pointer-events: auto;
}

#echolab-chrome .echolab-logout:hover {
  background: color-mix(in srgb, var(--text-main, #2e2e2e) 8%, var(--bg-main, #f4ecd8));
}

#echolab-chrome .app-toolbar-title {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 17px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(52vw, 280px);
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main, #2e2e2e);
  white-space: nowrap;
  z-index: 19;
  pointer-events: none;
}

#echolab-chrome .app-toolbar-instruction {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 36px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 560px);
  margin: 0;
  text-align: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.25;
  color: color-mix(in srgb, var(--text-muted, #5a5548) 92%, transparent);
  pointer-events: none;
  user-select: none;
  z-index: 18;
}

#echolab-chrome .app-toolbar-hint {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 52px);
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 520px);
  margin: 0;
  text-align: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.2;
  color: color-mix(in srgb, var(--text-muted, #5a5548) 78%, transparent);
  pointer-events: none;
  user-select: none;
  z-index: 17;
}

#echolab-chrome .echolab-burger:hover {
  background: color-mix(in srgb, var(--text-main, #2e2e2e) 10%, transparent);
}

#echolab-chrome .echolab-burger-lines {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}

#echolab-chrome .echolab-topbar-brand {
  display: none;
}

#echolab-chrome .echolab-topbar-trail {
  display: none;
}

/* Horizontal inset for desktop sidebar; vertical offset lives on .main-content */
body.echolab-nav-ready {
  padding-top: 0;
}

/* Mobile: show backdrop when open */
@media (max-width: 899px) {
  body.echolab-nav-open #echolab-chrome .echolab-backdrop {
    display: block;
  }

  #echolab-chrome .echolab-drawer-brand {
    display: none;
  }
}

/* Desktop */
@media (min-width: 900px) {
  #echolab-chrome .echolab-backdrop {
    display: none !important;
  }

  #echolab-chrome .echolab-burger {
    display: none;
  }

  #echolab-chrome .app-toolbar-title { display: none; }
  #echolab-chrome .app-toolbar-instruction { display: none; }
  #echolab-chrome .app-toolbar-hint { display: none; }

  #echolab-chrome .echolab-drawer {
    width: var(--echolab-sidebar-w);
    transform: translateX(0);
    box-shadow: none;
    transition: none;
  }

  #echolab-chrome .echolab-drawer-inner {
    padding-top: 20px;
  }

  #echolab-chrome .echolab-drawer-brand {
    display: block;
  }

  #echolab-chrome .echolab-topbar {
    left: 0;
  }

  body.echolab-nav-ready {
    padding-left: var(--echolab-sidebar-w);
  }
}
