/* ═══════════════════════════════════════════════
   LAYOUT - Screen System, App Shell, Header, Tabs
   ═══════════════════════════════════════════════
   Controls the overall page structure: screen switching,
   the sticky header, tab bar, feed container, and
   responsive breakpoints.
   ══════════════════════════════════════════════════ */

/* ─── Screen System ─── */
.screen {
  display: none !important;
  flex-direction: column;
  min-height: 100dvh;
}

.screen.active {
  display: flex !important;
}

/* ─── App Screen (main layout) ─── */
#app-screen {
  background: var(--bg);
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  padding: 0 20px;
  min-height: 100dvh;
}

#app-screen.active {
  display: flex;
}

.main-wrapper {
  flex: 1;
  max-width: 680px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Compose sidebar (desktop only) */
.compose-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: transparent;
  margin: 94px 0 20px 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 94px;
  align-self: flex-start;
  height: calc(100vh - 114px);
}

.compose-sidebar-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 0 1 auto;
  overflow-y: hidden;
  min-height: 0;
}

/* Sidebar Navigation (below compose area) */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 10px 16px;
  gap: 4px;
  flex: 1;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  scrollbar-width: none;
  transition: all 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 800px;
  opacity: 1;
}

.sidebar-nav.hidden-for-compose {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  flex: 0;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.sidebar-nav-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
  padding-left: 4px;
  /* Align with icons */
  opacity: 0.6;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 8px 10px;
  margin-left: -10px;
  /* Pull left so icons align with content above while hover-pill is centered */
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
  border: none;
  width: calc(100% + 20px);
  /* Allow pill to breathe */
  text-align: left;
}

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

.sidebar-nav-item.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.sidebar-nav-item svg {
  color: var(--accent);
  opacity: 0.5;
  transition: all var(--trans);
  flex-shrink: 0;
}

.sidebar-notif-badge {
  margin-left: -6px;
  width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 1px; /* Optical centering fix for mono baseline */
  pointer-events: none;
  animation: badgePop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  flex-shrink: 0;
}

@keyframes badgePop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.sidebar-nav-item:hover svg {
  opacity: 1;
  transform: translateY(-1px);
}

.sidebar-nav-item.active svg {
  opacity: 1;
}

.sidebar-nav-item.danger {
  margin-top: 8px;
}

.sidebar-nav-item.danger:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-color: color-mix(in srgb, var(--danger) 20%, transparent);
}

.sidebar-nav-item.danger svg {
  color: var(--danger);
}

.sidebar-nav-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 34px;
  border-radius: 10px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--trans);
  margin: auto auto 10px 0;
}

.sidebar-nav-more-btn:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--text-dim);
}

.sidebar-more-wrapper {
  position: relative;
  margin-top: auto;
}

.sidebar-more-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: -10px;
  backdrop-filter: blur(16px) saturate(1.8);
  -webkit-backdrop-filter: blur(16px) saturate(1.8);
  background: rgba(var(--bg-rgb), 0.88);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 0;
  display: none;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 500;
  min-width: 210px;
  overflow: hidden;
  transform-origin: bottom left;
  animation: sidebarMenuAppear 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes sidebarMenuAppear {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.sidebar-more-dropdown.show {
  display: flex;
}

.sidebar-more-dropdown .sidebar-nav-item {
  width: 100%;
  margin: 0;
  padding: 10px 16px;
  gap: 12px;
  border-radius: 0;
  background: transparent;
}

.sidebar-more-dropdown .sidebar-nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.sidebar-more-dropdown .sidebar-nav-item.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.sidebar-more-dropdown .sidebar-nav-item svg {
  color: var(--accent);
  opacity: 0.5;
  width: 18px;
}

.sidebar-more-dropdown .sidebar-nav-item:hover svg {
  color: var(--accent);
  opacity: 1;
}

.sidebar-more-dropdown .sidebar-nav-header {
  padding: 8px 14px 6px;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  opacity: 0.7;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 10px 16px;
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: transparent;
  border-top: 1px solid var(--border);
  transition: all 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 200px;
  opacity: 1;
}

.sidebar-footer.hidden-for-compose {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  border-top: none;
}

.sidebar-footer-brand {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
}

.sidebar-footer-brand span {
  font-family: var(--font-mono);
  font-size: 10px;
  margin-left: 6px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.sidebar-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
}

.sidebar-footer-links a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  text-decoration: none;
  transition: color var(--trans);
}

.sidebar-footer-links a:hover {
  color: var(--accent);
}

.sidebar-footer-links a:not(:last-child)::after {
  content: "·";
  color: var(--text-dim);
}

.sidebar-footer-links a:hover::after {
  color: var(--text-dim);
}

/* Hide compose button in header when sidebar is visible */
#compose-btn {
  display: none;
}

@media (max-width: 900px) {

  .compose-sidebar,
  .sidebar-footer {
    display: none !important;
  }

  #compose-btn {
    display: flex;
  }

  #app-screen {
    flex-direction: column;
    gap: 0;
    height: 100dvh;
    overflow: hidden;
    align-items: unset;
  }

  .main-wrapper {
    min-height: 0;
    overflow: hidden;
  }

  .app-header {
    position: relative;
  }

  .feed-container {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
  }
}

@media (max-width: 500px) {
  .main-wrapper {
    max-width: 100%;
  }

  #app-screen {
    padding: 0;
  }
}

/* ─── Header (sticky) ─── */
.app-header {
  position: sticky;
  top: 0;
  flex-shrink: 0;
  z-index: 100;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 54px;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
}

.header-wordmark {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text);
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-wordmark span {
  color: var(--accent);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── Icon & Avatar Buttons (reused across header + elsewhere) ─── */
.icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  transition: all var(--trans);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

.icon-btn svg {
  pointer-events: none;
}

.avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--trans);
  background: var(--surface2);
  flex-shrink: 0;
}

.avatar-btn:hover {
  border-color: var(--accent);
}

.avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Tab Bar ─── */
.tab-bar {
  display: flex;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  padding: 0 12px;
}

.tab-btn {
  width: 100%;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 10px 0;
  text-align: center;
  transition: all var(--trans);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-btn:hover {
  color: var(--text-muted);
}

.tab-btn.active {
  color: var(--accent2);
  border-bottom-color: var(--accent);
}

.tab-btn-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.tab-btn-label {
  pointer-events: none;
}

.tab-chevron {
  display: inline-block;
  margin-left: 3px;
  font-size: 10px;
  opacity: 0.6;
  pointer-events: none;
  transition: transform 0.15s ease;
}

.tab-btn.active .tab-chevron {
  opacity: 0.8;
}

.tab-btn.dropdown-open .tab-chevron {
  transform: rotate(180deg);
}

/* ─── Tab Dropdown ─── */
.tab-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%) scale(0.96);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 0;
  display: none;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 300;
  min-width: 170px;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.tab-dropdown.show {
  display: flex;
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

.tab-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background var(--trans);
  white-space: nowrap;
}

.tab-dropdown-item:hover {
  background: var(--surface2);
}

.tab-dropdown-item.active {
  color: var(--accent2);
}

.tab-dropdown-item.active svg {
  color: var(--accent);
}

.tab-dropdown-item svg {
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ─── Tab Pill Badge ─── */
.tab-pill {
  display: none;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  margin-left: 5px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
  vertical-align: middle;
  pointer-events: none;
}

.tab-pill.visible {
  display: inline-block;
}

/* ─── Feed Container ─── */
.feed-container {
  flex: 1;
  max-width: 680px;
  margin: 0 auto;
  width: 100%;
  padding: 0 0 60px;
  display: flex;
  flex-direction: column;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ─── Mobile Responsive ─── */
@media (max-width: 500px) {
  .header-wordmark {
    font-size: 18px;
  }

  .header-actions {
    gap: 4px;
  }

  .tab-bar {
    padding: 0 6px;
  }

  .tab-btn {
    font-size: calc(var(--app-font-size, 14px) * 0.85);
    padding: 9px 0;
  }
}

/* ─── Zen Mode ─── */
#zen-btn {
  display: none !important;
}

body.zen-mode .post-footer,
body.zen-mode .sidebar-footer,
body.zen-mode .post-time {
  display: none !important;
}

/* Hide extra compose UI */
body.zen-mode .compose-toolbar-left,
body.zen-mode .compose-lang-btn,
body.zen-mode #compose-lang-btn,
body.zen-mode #compose-lang-btn-sidebar,
body.zen-mode .compose-char-count {
  display: none !important;
}

/* Ensure post button and visibility stay visible */
body.zen-mode .compose-header,
body.zen-mode .compose-toolbar {
  justify-content: flex-end;
}

.profile-dropdown-zen-active {
  color: var(--accent) !important;
}