/* =====================================================================
   Page Columns & Responsive Layout (Nav | Feed | Rail)
   ===================================================================== */

:root {
  --nav-width: 240px;
  --nav-width-icons: 72px;
  --feed-width: 600px;
  --rail-width: 320px;
  --columns-gap: 32px;                          /* Slightly more breathing room */
  --bottom-nav-height: 56px;

  /* Harmonized Theme Tokens */
  --side-text: #16181b;
  --side-muted: #656f77;
  --side-border: var(--border-subtle, #edebe6);
  --side-hover: rgba(22, 24, 27, 0.04);
  --side-box: #ffffff;                          /* Crisp elevated cards */
  --side-accent: var(--accent, #4f46e5);         /* Brand indigo */
}

/* Header width matches column layout */
#menuBar {
  max-width: calc(var(--nav-width) + var(--feed-width) + var(--rail-width) + 2 * var(--columns-gap) + 32px);
}

/* =====================================================================
   Three-Column Grid
   ===================================================================== */

page-columns {
  display: grid;
  grid-template-columns: var(--nav-width) minmax(0, var(--feed-width)) var(--rail-width);
  justify-content: center;
  align-items: start;
  column-gap: var(--columns-gap);
  padding-inline: 16px;
}

page-columns > feed-section {
  min-width: 0;
  max-width: var(--feed-width);
  margin-inline: 0;
}

/* =====================================================================
   Navigation Icon Masks
   ===================================================================== */

.icon-home {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6H9v6H4a1 1 0 0 1-1-1z'/%3E%3C/svg%3E");
}

.icon-user {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c0-4 3.6-7 8-7s8 3 8 7'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c0-4 3.6-7 8-7s8 3 8 7'/%3E%3C/svg%3E");
}

.icon-gear {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
}

.icon-feather {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20.24 12.24a6 6 0 0 0-8.49-8.49L5 10.5V19h8.5z'/%3E%3Cpath d='M16 8 2 22M17.5 15H9'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20.24 12.24a6 6 0 0 0-8.49-8.49L5 10.5V19h8.5z'/%3E%3Cpath d='M16 8 2 22M17.5 15H9'/%3E%3C/svg%3E");
}

.icon-plus {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E");
}

/* =====================================================================
   Left Column: Sidebar Navigation
   ===================================================================== */

side-nav {
  position: sticky;
  top: var(--header-chrome-height);
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-chrome-height));
  padding-block: 16px;
  overflow-y: auto;
  color: var(--side-text);
}

side-nav .nav-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

side-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: fit-content;
  min-height: 44px;
  padding: 8px 18px 8px 12px;
  border: 0;
  border-radius: 12px;                          /* Modern subtle tile */
  background: none;
  color: var(--side-muted);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

side-nav .nav-item[aria-current="page"] {
  font-weight: 650;
  color: var(--side-text);
  background: rgba(0, 0, 0, 0.04);
}

side-nav .nav-item[aria-current="page"] .icon {
  color: var(--side-accent);
}

side-nav .nav-item:focus-visible,
side-nav .nav-post:focus-visible,
side-nav .nav-me:focus-visible,
bottom-nav .tab:focus-visible {
  outline: 2px solid var(--side-accent);
  outline-offset: 2px;
}

.nav-icon-wrap {
  position: relative;
  display: inline-flex;
}

.nav-badge {
  position: absolute;
  top: -6px;
  right: -9px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--side-accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
}

.nav-badge[hidden] { display: none; }

/* Primary Post Action Button */
side-nav .nav-post {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 95%;
  min-height: 48px;
  margin-top: 20px;
  border: 0;
  border-radius: 12px;
  background: var(--side-accent);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.25);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

side-nav .nav-post .icon { display: none; }

side-nav .nav-post:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35);
  filter: brightness(1.04);
}

side-nav .nav-post:active {
  transform: translateY(0);
}

/* User Account Dock (Bottom Left) */
side-nav .nav-me {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: inherit;
  text-decoration: none;
  transition: all 0.15s ease;
}

side-nav .nav-me:hover {
  background: #ffffff;
  border-color: var(--side-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

side-nav .nav-me img {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--side-border);
}

side-nav .nav-me-text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

side-nav .nav-me-text strong,
side-nav .nav-me-text span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

side-nav .nav-me-text span {
  color: var(--side-muted);
  font-size: 0.88rem;
}

/* Logged out state */
side-nav .nav-guest {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 16px;
  background: #ffffff;
  border: 1px solid var(--side-border);
  border-radius: 14px;
}

side-nav .nav-guest p { margin: 0; color: var(--side-muted); }

side-nav .nav-guest a {
  display: block;
  padding: 9px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  text-align: center;
  text-decoration: none;
}

side-nav .nav-guest-primary {
  background: var(--side-accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

side-nav .nav-guest-secondary {
  border: 1px solid var(--side-border);
  color: var(--side-text);
}

/* =====================================================================
   Right Column: Explore & Discovery Rail
   ===================================================================== */

side-rail {
  position: sticky;
  top: calc(var(--header-chrome-height) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100dvh - var(--header-chrome-height) - 24px);
  padding-bottom: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  color: var(--side-text);
}

rail-sheet-head { display: none; }

/* Elevated White Cards for Discovery */
rail-box {
  display: block;
  padding: 16px 0 8px;
  border-radius: 16px;
  background: var(--side-box);
  border: 1px solid var(--side-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02);
}

rail-box[hidden] { display: none; }

rail-box h2 {
  margin: 0 0 8px;
  padding: 0 16px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

rail-box ol,
rail-box ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

rail-box a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  color: inherit;
  text-decoration: none;
  transition: background 0.12s ease;
}

rail-box a:hover {
  background: var(--side-hover);
}

rail-box a:focus-visible {
  outline: 2px solid var(--side-accent);
  outline-offset: -2px;
}

/* Loading skeleton */
trending-tags[aria-busy="true"],
people-suggestions[aria-busy="true"],
trending-tags:empty,
people-suggestions:empty {
  display: block;
  min-height: 140px;
  margin: 8px 16px 12px;
  border-radius: 10px;
  background: repeating-linear-gradient(to bottom,
      rgba(22, 24, 27, 0.04) 0 14px, transparent 14px 34px);
}

.trend-rank {
  flex: none;
  width: 1.3em;
  color: var(--side-muted);
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0.65;
  text-align: right;
}

.trend-text,
.person-text {
  display: grid;
  min-width: 0;
  line-height: 1.3;
}

.trend-text strong,
.person-text strong,
.person-handle,
.person-shared {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.trend-text strong {
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.trend-meta,
.person-handle,
.person-shared {
  color: var(--side-muted);
  font-size: 0.82rem;
}

people-suggestions img {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--side-border);
  background: var(--side-border);
}

.person-text { flex: 1; }

.person-view {
  flex: none;
  padding: 5px 12px;
  border-radius: 8px;
  background: var(--side-hover);
  color: var(--side-text);
  border: 1px solid var(--side-border);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

rail-box a:hover .person-view {
  background: var(--side-text);
  color: #fff;
  border-color: var(--side-text);
}

.rail-empty {
  margin: 4px 16px 12px;
  color: var(--side-muted);
}

/* =====================================================================
   Medium Screen Layout (Tablets / Foldables)
   ===================================================================== */

@media (max-width: 1099px) {
  page-columns {
    grid-template-columns: var(--nav-width-icons) minmax(0, var(--feed-width));
  }

  side-nav { align-items: center; }
  side-nav .nav-items { align-items: center; }
  side-nav .nav-label,
  side-nav .nav-me-text { display: none; }
  side-nav .nav-item { padding: 12px; }

  side-nav .nav-post {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 12px;
  }

  side-nav .nav-post .icon { display: inline-block; }
  side-nav .nav-me { padding: 6px; }
  side-nav .nav-guest { display: none; }

  side-rail { display: none; }

  body.explore-open side-rail {
    position: fixed;
    inset: var(--header-chrome-height) 0 0 0;
    z-index: 14;
    display: flex;
    max-height: none;
    padding: 0 16px calc(16px + env(safe-area-inset-bottom));
    background: var(--bg-app, #fcfcfb);
  }

  body.explore-open rail-sheet-head {
    width: 100%;
    max-width: var(--feed-width);
    margin-inline: auto;
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    background: var(--bg-app, #fcfcfb);
    font-size: 1.15rem;
  }

  body.explore-open side-rail > rail-box {
    width: 100%;
    max-width: var(--feed-width);
    margin-inline: auto;
  }

  body.explore-open { overflow: hidden; }
}

/* =====================================================================
   Narrow Screen Layout (Phones)
   ===================================================================== */

bottom-nav { display: none; }

body.composing feed-panel[data-view="timeline"] composer-section {
  display: flex;
}

@media (max-width: 799px) {
  page-columns {
    display: block;
    padding-inline: 0;
  }

  page-columns > feed-section { max-width: none; }
  side-nav { display: none; }

  #menuControls { grid-column: 3; justify-self: end; }
  #directMessage { display: none !important; }

  body { padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)); }

  bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 15;
    display: block;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--side-border);
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
  }

  bottom-nav nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--bottom-nav-height);
  }

  bottom-nav .tab {
    display: grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--side-text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  bottom-nav .tab:active { background: var(--side-hover); }
  bottom-nav .tab .icon { width: 24px; height: 24px; }
  bottom-nav .tab[aria-current="page"] .icon { color: var(--side-accent); }

  bottom-nav .tab-post {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--side-accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  }

  bottom-nav .tab-post .icon { color: #fff; }

  bottom-nav .tab img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--side-border);
  }

  bottom-nav .tab[aria-current="page"] img {
    outline: 2px solid var(--side-accent);
    outline-offset: 1px;
  }

  bottom-nav .tab-login {
    padding: 0 16px;
    background: var(--side-accent);
    color: #fff;
    font-weight: 600;
  }

  body.explore-open side-rail {
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: 16px;
  }

  body.dm-open bottom-nav { display: none; }
}