/* Streamlit-style sidebar navigation for Pump Trumps admin */

:root {
  --pt-sidebar-width: 260px;
  --pt-sidebar-collapsed-width: 0px;
  --pt-sidebar-z: 1000;
}

/* Global hyperlink color consistency across screens */
a,
a:visited {
  color: var(--accent, #5c9ead);
}

a:hover,
a:focus-visible {
  color: var(--focus, #6bb3c4);
}

/* Layout when sidebar is present (injected by sidebar.js) */
body.pt-with-sidebar {
  display: flex;
  flex-direction: row;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.pt-app-layout {
  display: flex;
  flex: 1;
  min-width: 0;
  min-height: 100vh;
}

/* Sidebar is fixed so collapsing it doesn't shift main content */
.pt-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--pt-sidebar-width);
  background: var(--surface, #252830);
  border-right: 1px solid var(--border, #3d424d);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s ease;
  z-index: var(--pt-sidebar-z);
}

.pt-sidebar.collapsed {
  transform: translateX(-100%);
  overflow: visible;
}

/* Main content offset when sidebar is visible; no offset when collapsed */
.pt-main {
  flex: 1;
  min-width: 0;
  padding: 1rem 1.5rem;
  margin-left: var(--pt-sidebar-width);
  transition: margin-left 0.2s ease;
}

body.pt-sidebar-collapsed .pt-main {
  margin-left: 0;
}

.pt-sidebar-header {
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border, #3d424d);
  flex-shrink: 0;
}

.pt-sidebar-header a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text, #e6e8ec);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
}

.pt-sidebar-header a:hover {
  color: var(--accent, #5c9ead);
}

.pt-sidebar-logo {
  width: auto;
  height: 32px;
  max-width: 140px;
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}

.pt-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem 0;
}

.pt-sidebar-section {
  padding: 0;
}

.pt-sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted, #8b909a);
  padding: 0.5rem 1rem;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}

.pt-sidebar-section-title:hover {
  color: var(--text, #e6e8ec);
  background: rgba(255, 255, 255, 0.04);
}

.pt-sidebar-section-chevron {
  display: inline-flex;
  transition: transform 0.2s ease;
  opacity: 0.8;
}

.pt-sidebar-section-title.collapsed .pt-sidebar-section-chevron {
  transform: rotate(-90deg);
}

.pt-sidebar-section-content {
  overflow: hidden;
}

.pt-sidebar-section-content[hidden] {
  display: none;
}

.pt-sidebar-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pt-sidebar-section li {
  margin: 0;
}

.pt-sidebar-section a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--text, #e6e8ec);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pt-sidebar-link-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.pt-sidebar-link-icon svg {
  width: 18px;
  height: 18px;
}

.pt-sidebar-section a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent, #5c9ead);
}

.pt-sidebar-section a:hover .pt-sidebar-link-icon {
  opacity: 1;
}

.pt-sidebar-section a.active {
  background: rgba(92, 158, 173, 0.15);
  color: var(--accent, #5c9ead);
  border-left-color: var(--accent, #5c9ead);
  font-weight: 500;
}

.pt-sidebar-section a.active .pt-sidebar-link-icon {
  opacity: 1;
}

.pt-sidebar-footer {
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border, #3d424d);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pt-sidebar-logout {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 32px;
  padding: 0 0.75rem;
  border: 1px solid var(--border, #3d424d);
  border-radius: 6px;
  background: transparent;
  color: var(--text, #e6e8ec);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pt-sidebar-logout:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #ffb4b4;
  border-color: rgba(255, 100, 100, 0.55);
}

.pt-sidebar-logout:disabled {
  opacity: 0.7;
  cursor: progress;
}

.pt-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border, #3d424d);
  border-radius: 6px;
  background: var(--surface, #252830);
  color: var(--muted, #8b909a);
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.15s, color 0.15s;
}

.pt-sidebar-toggle:hover {
  background: var(--border, #3d424d);
  color: var(--text, #e6e8ec);
}

/* Hide legacy horizontal nav when sidebar is present */
body.pt-with-sidebar .nav.pt-legacy-nav {
  display: none;
}

body.pt-with-sidebar .nav.pt-legacy-nav + .nav-admin.pt-legacy-nav,
body.pt-with-sidebar p.nav-admin.pt-legacy-nav {
  display: none;
}

body.pt-with-sidebar .admin-nav-toggle {
  display: none;
}

/* Prevent top-nav flash while sidebar initializes on page load */
body.pt-sidebar-loading .nav,
body.pt-sidebar-loading .nav-admin {
  display: none;
}

/* Collapsed: show overlay toggle so user can reopen */
.pt-sidebar.collapsed .pt-sidebar-header,
.pt-sidebar.collapsed .pt-sidebar-nav,
.pt-sidebar.collapsed .pt-sidebar-footer {
  opacity: 0;
  pointer-events: none;
}

.pt-sidebar-expand {
  position: fixed;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: calc(var(--pt-sidebar-z) + 1);
  display: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 56px;
  padding: 0;
  border: 1px solid var(--border, #3d424d);
  border-left: none;
  border-radius: 0 8px 8px 0;
  background: var(--surface, #252830);
  color: var(--muted, #8b909a);
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.15s, color 0.15s;
}

.pt-sidebar-expand:hover {
  background: var(--border, #3d424d);
  color: var(--text, #e6e8ec);
}

body.pt-sidebar-collapsed .pt-sidebar-expand {
  display: flex;
}

.pt-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: calc(var(--pt-sidebar-z) - 1);
}

.pt-sidebar-overlay.visible {
  display: block;
}

/* Mobile: sidebar as overlay, same fixed + transform behavior */
@media (max-width: 768px) {
  .pt-sidebar {
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }

  .pt-main {
    padding-top: max(1rem, env(safe-area-inset-top, 0));
    padding-right: max(1rem, env(safe-area-inset-right, 0));
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0));
    padding-left: max(1rem, env(safe-area-inset-left, 0));
  }
}

/* Prevent wide images or embeds from forcing horizontal scroll in admin main */
.pt-main img {
  max-width: 100%;
  height: auto;
}
