/* ==========================================================================
   APEX - MAIN CSS & TWITTER/X RESPONSIVE LAYOUT
   Optimized for Desktop, Tablet, and iOS / iPhone 13 Pro Max (Safe Areas)
   ========================================================================== */

:root {
  /* Fonts */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Theme Accents (Default: Twitter Premium Orange) */
  --color-accent: #ff7a00;
  --color-accent-hover: #e06c00;
  --color-accent-light: rgba(255, 122, 0, 0.12);
  --color-accent-glow: rgba(255, 122, 0, 0.3);

  /* Default "Lights Out" (Pure Black OLED) */
  --bg-primary: #000000;
  --bg-secondary: #16181c;
  --bg-tertiary: #202327;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.1);
  --bg-modal-overlay: rgba(91, 112, 131, 0.4);

  /* Borders & Dividers */
  --border-color: #2f3336;
  --border-subtle: #1e2124;

  /* Typography Colors */
  --text-primary: #e7e9ea;
  --text-secondary: #71767b;
  --text-muted: #536471;
  --text-link: var(--color-accent);

  /* Status & Action Colors */
  --color-like: #f91880;
  --color-like-bg: rgba(249, 24, 128, 0.1);
  --color-retweet: #00ba7c;
  --color-retweet-bg: rgba(0, 186, 124, 0.1);
  --color-reply: #1d9bf0;
  --color-reply-bg: rgba(29, 155, 240, 0.1);
  --color-badge-gold: #ffd700;
  --color-danger: #f4212e;

  /* Layout Dimensions */
  --sidebar-width: 275px;
  --main-width: 600px;
  --widgets-width: 350px;
  --nav-height-mobile: 60px;
  --header-height-mobile: 54px;

  /* iPhone Safe Areas */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

/* Base Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.4;
  overflow-x: hidden;
  user-select: text;
  -webkit-font-smoothing: antialiased;
}

/* App Container Layout */
#app {
  display: flex;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding-left: var(--sal);
  padding-right: var(--sar);
  position: relative;
}

/* ==========================================================================
   LEFT NAVIGATION SIDEBAR (Desktop)
   ========================================================================== */
.sidebar-left {
  width: var(--sidebar-width);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px;
  border-right: 1px solid var(--border-color);
  flex-shrink: 0;
  z-index: 100;
}

.brand-logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 9999px;
  cursor: pointer;
  width: fit-content;
  transition: background-color 0.2s ease;
}

.brand-logo-container:hover {
  background-color: var(--bg-hover);
}

.brand-logo-icon {
  width: 32px;
  height: 32px;
  fill: var(--color-accent);
}

.brand-name {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.nav-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-radius: 9999px;
  font-size: 19px;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
  position: relative;
}

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

.nav-item.active {
  font-weight: 800;
  color: var(--color-accent);
}

.nav-item.active .nav-icon svg {
  stroke: var(--color-accent);
  fill: var(--color-accent-light);
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-icon svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.nav-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background-color: var(--color-accent);
  color: #000;
  font-size: 11px;
  font-weight: 800;
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-primary);
}

.btn-compose-large {
  margin-top: 16px;
  background-color: var(--color-accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 0;
  border-radius: 9999px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px var(--color-accent-glow);
  transition: background-color 0.2s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.btn-compose-large:hover {
  background-color: var(--color-accent-hover);
  transform: translateY(-1px);
}

.user-quick-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin-bottom: 8px;
}

.user-quick-profile:hover {
  background-color: var(--bg-hover);
}

.user-avatar-sm {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  max-width: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  border-radius: 50% !important;
  object-fit: cover !important;
  aspect-ratio: 1 / 1 !important;
  flex-shrink: 0 !important;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  display: block;
}

.user-quick-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin: 0 10px;
  overflow: hidden;
}

.user-quick-name {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-quick-handle {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   CENTER MAIN CONTENT FEED (600px Fixed, 990px on DMs)
   ========================================================================== */
.main-feed-container,
#main-content-view {
  width: 600px !important;
  min-width: 600px !important;
  max-width: 600px !important;
  min-height: 100vh;
  border-right: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* In Messages view, main feed container expands to exactly 990px (390px convo list + 600px chat window) */
#app.view-dms .main-feed-container,
#app.view-dms #main-content-view {
  width: 990px !important;
  min-width: 990px !important;
  max-width: 990px !important;
  border-right: 1px solid var(--border-color);
}

#app.view-dms .sidebar-right {
  display: none !important;
}

/* Top Sticky Header */
.feed-header {
  position: sticky;
  top: 0;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 90;
  padding-top: var(--sat);
}

.header-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  height: 52px;
}

.header-title {
  font-size: 20px;
  font-weight: 800;
}

.universe-badge-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.universe-badge-header:hover {
  border-color: var(--color-accent);
  background-color: var(--bg-hover);
}

.universe-icon {
  font-size: 16px;
}

/* Header Tabs */
.header-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.header-tab {
  flex: 1;
  text-align: center;
  padding: 14px 0;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.header-tab:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
}

.header-tab.active {
  color: var(--text-primary);
  font-weight: 800;
}

.header-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 4px;
  background-color: var(--color-accent);
  border-radius: 9999px;
}

/* ==========================================================================
   RIGHT WIDGETS & TRENDING SIDEBAR
   ========================================================================== */
.sidebar-right {
  width: var(--widgets-width);
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex-shrink: 0;
}

.search-bar-box {
  position: sticky;
  top: 12px;
  background-color: var(--bg-secondary);
  border-radius: 9999px;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  border: 1px solid transparent;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  z-index: 80;
}

.search-bar-box:focus-within {
  background-color: var(--bg-primary);
  border-color: var(--color-accent);
}

.search-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  width: 100%;
}

.widget-card {
  background-color: var(--bg-secondary);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.widget-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ==========================================================================
   MOBILE BOTTOM NAVIGATION & FLOATING COMPOSE BUTTON
   Optimized for iPhone 13 Pro Max
   ========================================================================== */
.mobile-nav-bottom {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  height: calc(var(--nav-height-mobile) + var(--sab));
  padding-bottom: var(--sab);
  justify-content: space-around;
  align-items: center;
  z-index: 200;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 10px;
  font-weight: 600;
  gap: 3px;
  padding: 6px 12px;
  border-radius: 8px;
  position: relative;
  flex: 1;
}

.mobile-nav-item.active {
  color: var(--color-accent);
}

.mobile-nav-item.active svg {
  stroke: var(--color-accent);
}

.fab-compose-mobile {
  display: none;
  position: fixed;
  bottom: calc(var(--nav-height-mobile) + var(--sab) + 16px);
  right: calc(var(--sar) + 18px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--color-accent);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px var(--color-accent-glow);
  align-items: center;
  justify-content: center;
  z-index: 190;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.2s ease;
}

.fab-compose-mobile:active {
  transform: scale(0.92);
}

/* ==========================================================================
   RESPONSIVE MEDIA QUERIES
   ========================================================================== */
@media (max-width: 1200px) {
  .sidebar-right {
    display: none;
  }
}

@media (max-width: 992px) {
  .sidebar-left {
    width: 80px;
    align-items: center;
    padding: 12px 8px;
  }
  .brand-name, .nav-item span, .user-quick-info, .btn-compose-large span {
    display: none;
  }
  .btn-compose-large {
    width: 50px;
    height: 50px;
    padding: 0;
  }
}

@media (max-width: 680px) {
  .sidebar-left {
    display: none;
  }
  .main-feed-container {
    width: 100%;
    border-right: none;
    padding-bottom: calc(var(--nav-height-mobile) + var(--sab) + 20px);
  }
  .mobile-nav-bottom {
    display: flex;
  }
  .fab-compose-mobile {
    display: flex;
  }
}
