/* Shared Ahrens Labs hamburger + site nav drawer (Classify / Tether / Link / Digest).
   Load AFTER css/style.css so drawer styles win over global header nav rules. */

:root {
  --th-ink: #0f172a;
  --th-line: #e2e8f0;
  --th-site-chrome-z: 40;
  --th-site-menu-backdrop-z: 25000;
  --th-site-menu-z: 25001;
}

header.th-app-header {
  position: sticky;
  top: 0;
  padding: 0 1rem;
  padding-top: env(safe-area-inset-top, 0px);
  background: #fff;
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  box-shadow: none;
  backdrop-filter: none;
  display: block;
  overflow: visible;
  flex-shrink: 0;
  z-index: var(--th-site-chrome-z);
}

header.th-app-header::before {
  display: none;
}

.dark header.th-app-header {
  background: #0f172a;
  border-bottom-color: rgba(51, 65, 85, 0.6);
}

.th-app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 12px;
  margin-bottom: 0;
}

.th-topbar-start {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.th-topbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.th-topbar-brand img {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  object-fit: contain;
}

.th-topbar-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  color: var(--th-ink);
}

.th-hamburger {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--th-line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
}

.th-hamburger:hover {
  border-color: #93c5fd;
  background: #f8fafc;
}

.th-hamburger span {
  display: block;
  height: 2px;
  width: 100%;
  border-radius: 1px;
  background: var(--th-ink);
}

.dark .th-hamburger {
  background: #1e293b;
  border-color: #334155;
}

.dark .th-hamburger:hover {
  border-color: #38bdf8;
  background: #0f172a;
}

.dark .th-hamburger span {
  background: #f1f5f9;
}

.th-topbar-auth {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: nowrap;
  margin-left: auto;
}

/* App chrome uses its own topbar — override global header auth rules from style.css */
header.th-app-header .th-topbar-auth,
header.th-app-header #header-auth-buttons {
  position: static !important;
  top: auto !important;
  right: auto !important;
  left: auto !important;
  width: auto !important;
  max-width: none;
  margin-top: 0 !important;
  grid-column: unset !important;
  grid-row: unset !important;
  justify-content: flex-end !important;
  flex-wrap: nowrap !important;
}

.th-topbar-auth-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
  line-height: 1.25;
}

.th-topbar-auth-login {
  background: #3498db;
  color: #fff;
}

.th-topbar-auth-signup {
  background: #2ecc71;
  color: #fff;
}

.th-topbar-username {
  display: none;
  padding: 6px 4px;
  color: var(--th-ink);
  font-weight: 700;
  font-size: 0.9rem;
}

.dark .th-topbar-username {
  color: #f1f5f9;
}

.th-settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--th-line);
  border-radius: 10px;
  background: #fff;
  color: #64748b;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.th-settings-btn:hover {
  border-color: #93c5fd;
  background: #f8fafc;
  color: #2563eb;
}

.th-settings-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dark .th-settings-btn {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

.dark .th-settings-btn:hover {
  border-color: #38bdf8;
  background: #0f172a;
  color: #38bdf8;
}

/* --- Site drawer (must override css/style.css global nav rules) --- */

.th-site-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: var(--th-site-menu-backdrop-z);
}

.th-site-menu {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--th-site-menu-z);
  width: min(320px, 88vw);
  max-width: 100%;
  background: linear-gradient(165deg, #1e293b 0%, #0f172a 100%);
  color: #fff;
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  display: flex;
  flex-direction: column;
  font-family: Inter, system-ui, sans-serif;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent;
}

.th-site-menu::-webkit-scrollbar {
  width: 10px;
}

.th-site-menu::-webkit-scrollbar-track {
  background: transparent;
}

.th-site-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.th-site-menu.open {
  transform: translateX(0);
}

.th-site-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 16px 16px 12px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: #1a2433;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
}

.th-site-menu-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.05rem;
}

.th-site-menu-brand img {
  width: 36px;
  height: auto;
}

.th-site-menu-close {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.th-site-menu-close:hover {
  background: rgba(255, 255, 255, 0.14);
}

.th-site-menu nav {
  padding: 12px 10px 24px;
  flex: 0 0 auto;
  position: relative;
  z-index: 0;
  overflow: visible;
  background: transparent;
}

.th-site-menu nav > ul {
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  justify-content: flex-start !important;
  gap: 6px !important;
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
}

.th-site-menu nav > ul > li {
  margin: 0 !important;
  width: 100% !important;
  position: static !important;
  z-index: 0 !important;
}

.th-site-menu nav ul li.nav-dropdown {
  position: static !important;
  z-index: 0 !important;
}

.th-site-menu nav > ul > li::after {
  display: none !important;
  content: none !important;
}

.th-site-menu nav .nav-caret {
  display: none !important;
}

.th-site-menu-footer {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 30;
  margin-top: auto;
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: #141c28;
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.22);
}

.th-site-menu-signout,
.th-site-menu nav > ul > li > a,
.th-site-menu nav > ul > li > .nav-dropdown-trigger {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box !important;
  padding: 0.65em 0.85em !important;
  border-radius: 12px !important;
  color: rgba(255, 255, 255, 0.92) !important;
  text-decoration: none !important;
  font-size: 0.92rem !important;
  font-weight: 600 !important;
  text-align: left !important;
  white-space: normal !important;
  position: static !important;
  overflow: visible !important;
  backdrop-filter: none !important;
  animation: none !important;
  transform: none !important;
  background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.1)) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease !important;
}

.th-site-menu-signout:hover,
.th-site-menu nav > ul > li > a:hover,
.th-site-menu nav > ul > li > .nav-dropdown-trigger:hover,
.th-site-menu nav a.active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.08)) !important;
  border-color: rgba(255, 255, 255, 0.34) !important;
  color: #fff !important;
  transform: none !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
}

.th-site-menu nav a::before,
.th-site-menu nav a::after {
  display: none !important;
  content: none !important;
}

.th-site-menu nav ul.nav-dropdown-menu {
  display: block !important;
  position: static !important;
  z-index: 0 !important;
  transform: none !important;
  min-width: 0 !important;
  margin: 0 0 4px !important;
  padding: 0 0 0 12px !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  top: auto !important;
  left: auto !important;
}

.th-site-menu nav ul.nav-dropdown-menu li {
  width: 100% !important;
}

.th-site-menu nav ul.nav-dropdown-menu a {
  display: block !important;
  font-size: 0.84rem !important;
  font-weight: 500 !important;
  color: rgba(255, 255, 255, 0.85) !important;
  padding: 0.5em 0.85em !important;
  background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.06)) !important;
  border: 1px solid rgba(255, 255, 255, 0.14) !important;
  border-radius: 10px !important;
  transform: none !important;
  animation: none !important;
}

.th-site-menu nav ul.nav-dropdown-menu a:hover,
.th-site-menu nav ul.nav-dropdown-menu a.active {
  background: rgba(255, 255, 255, 0.12) !important;
  border-color: rgba(255, 255, 255, 0.28) !important;
  color: #fff !important;
  box-shadow: none !important;
}

body.th-site-menu-open {
  overflow: hidden;
}

/* Drawer is portaled to body; keep it above fixed app footers on Classify / Tether / Link */
body.th-site-menu-open .th-bottom-nav,
body.th-site-menu-open .bottom-nav,
body.th-site-menu-open .cl-app-footer,
body.th-site-menu-open .sd-bottom-nav {
  z-index: var(--th-site-chrome-z);
}

/* Standalone app pages use their own footers — never the Ahrens Labs site footer */
body.th-page > footer,
body.classify-app > footer:not(.cl-app-footer),
body.link-app > footer,
body.digest-app > footer {
  display: none !important;
}

/* App pages are not centered marketing layouts — pin chrome to the top */
body.th-page,
body.classify-app,
body.digest-app {
  justify-content: flex-start;
}

body.classify-app,
body.digest-app,
body.th-page {
  min-height: 100dvh;
  overflow-x: hidden;
}

body.classify-app .classify-app-shell {
  flex: 1 1 auto;
  width: 100%;
}

body.th-page .wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
}

body.digest-app .wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex: none;
}

body.digest-app main.sd-main {
  flex: none;
  height: auto;
  min-height: 0;
  padding: 0;
  max-width: none;
  margin: 0;
  display: block;
  gap: 0;
}

body.th-page .push {
  display: none;
}

body.th-page main.th-main-wrap {
  gap: 0;
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

/* Narrow windows / tablets / phones */
@media (max-width: 900px) {
  body.th-page main.th-main-wrap {
    padding-left: max(10px, env(safe-area-inset-left, 0px));
    padding-right: max(10px, env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 768px) {
  header.th-app-header {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .th-app-topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 6px 0 10px;
    flex-wrap: nowrap;
  }

  .th-topbar-start {
    grid-column: 1;
    flex: none;
    min-width: 0;
    max-width: 100%;
    padding-right: 0;
  }

  .th-topbar-brand {
    min-width: 0;
    flex: 1 1 auto;
  }

  .th-topbar-title {
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .th-topbar-brand img,
  .th-topbar-brand .digest-logo {
    width: 34px;
    height: 34px;
  }

  .th-topbar-auth {
    grid-column: 2;
    justify-self: end;
    flex: 0 0 auto;
    margin-left: 0;
    max-width: none;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
  }

  .th-topbar-username,
  .th-topbar-auth .link-nav-user {
    display: inline-block;
    padding: 4px 0 !important;
    font-size: 0.78rem !important;
    line-height: 1.2;
    max-width: min(34vw, 132px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    flex-shrink: 0;
    color: var(--th-ink);
    font-weight: 700;
  }

  .dark .th-topbar-username,
  .dark .th-topbar-auth .link-nav-user {
    color: #f1f5f9;
  }

  .th-topbar-auth-btn {
    padding: 5px 8px;
    font-size: 0.72rem;
    flex-shrink: 0;
  }

  .th-settings-btn {
    flex-shrink: 0;
  }

  .th-hamburger,
  .th-settings-btn {
    width: 36px;
    height: 36px;
  }

  .th-site-menu {
    width: min(320px, 100vw);
    padding-left: env(safe-area-inset-left, 0px);
  }

  .th-site-menu-head,
  .th-site-menu nav,
  .th-site-menu-footer {
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .th-site-menu-brand {
    min-width: 0;
    flex: 1 1 auto;
  }

  .th-site-menu-brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  .th-topbar-username,
  .th-topbar-auth .link-nav-user {
    max-width: min(38vw, 120px);
    font-size: 0.74rem;
  }
}

@media (max-width: 360px) {
  .th-topbar-auth-btn.th-topbar-auth-signup {
    display: none;
  }

  .th-topbar-title {
    font-size: 0.98rem;
  }
}
