/* =============================================
   SQUARE — Base / Reset / Layout / Navigation
============================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--t-base) var(--ease), color var(--t-base) var(--ease);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, video { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button { font-family: var(--font-body); cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: var(--font-body); outline: none; border: none; background: none; color: inherit; }
ul, ol { list-style: none; }

/* =============================================
   ICONS (SVG img)
============================================= */
img.isax {
  display: inline-block;
  vertical-align: middle;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  pointer-events: none;
  user-select: none;
}
.isax-sm { width: 16px !important; height: 16px !important; }
.isax-md { width: 20px !important; height: 20px !important; }
.isax-lg { width: 24px !important; height: 24px !important; }
.isax-xl { width: 28px !important; height: 28px !important; }

/* White icons on colored/dark backgrounds (stories, chat send btn, nav fab, sidebar post btn) */
img.isax.isax-light { filter: invert(1); }

/* Dark mode: invert dark icons to near-white */
[data-theme="dark"] img.isax:not(.isax-light) { filter: invert(0.88); }
[data-theme="dark"] img.isax.isax-light        { filter: invert(1); }

/* Muted icon (chevrons, secondary indicators) */
img.isax.isax-muted { opacity: 0.45; }

/* Already-inverted icons in dark mode: don't double-invert */
[data-theme="dark"] .sidebar-post-btn img.isax,
[data-theme="dark"] .nav-fab-btn img.isax,
[data-theme="dark"] .profile-btn.btn-primary img.isax,
[data-theme="dark"] .chat-send-btn img.isax {
  filter: invert(1);
}

/* =============================================
   MOBILE LAYOUT (< 900px)
============================================= */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

.main-scroll {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + var(--s-4));
  overflow-y: auto;
  overflow-x: hidden;
  height: 100dvh;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.main-scroll::-webkit-scrollbar { display: none; }

/* =============================================
   DESKTOP LAYOUT (>= 900px)
============================================= */
@media (min-width: 900px) {
  body { background: var(--bg-alt); }

  .page { max-width: 100%; min-height: 100dvh; overflow: visible; }

  /* 3-column grid */
  .app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr var(--right-w);
    max-width: 1180px;
    margin: 0 auto;
    min-height: 100dvh;
  }

  .top-header  { display: none !important; }
  .bottom-nav  { display: none !important; }

  .main-scroll {
    padding-top: 0;
    padding-bottom: var(--s-6);
    height: 100dvh;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    background: var(--bg);
  }
}

@media (min-width: 1200px) {
  .app-shell { max-width: 1280px; }
}

/* =============================================
   DESKTOP SIDEBAR
============================================= */
.desktop-sidebar { display: none; }
.sq-portfolio-back { display: none; }

@media (min-width: 900px) {
  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    padding: var(--s-6) var(--s-5);
    position: sticky;
    top: 0;
    overflow-y: auto;
    scrollbar-width: none;
  }
  .desktop-sidebar::-webkit-scrollbar { display: none; }

  .sidebar-logo {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    padding: var(--s-2) 0 var(--s-6);
    user-select: none;
    display: block;
  }

  .sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

  .sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: 11px var(--s-4);
    border-radius: var(--r-lg);
    color: var(--text-2);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
    position: relative;
  }
  .sidebar-nav-item img.isax {
    width: 22px; height: 22px;
    flex-shrink: 0;
    transition: transform var(--t-base) var(--ease-spring);
  }
  .sidebar-nav-item:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-nav-item:hover img.isax { transform: scale(1.12); }
  .sidebar-nav-item.active { background: var(--primary-glow); color: var(--primary); font-weight: 700; }
  .sidebar-nav-item .notif-pill {
    margin-left: auto;
    background: var(--primary); color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 2px 7px; border-radius: var(--r-full); line-height: 1.6;
  }

  .sidebar-post-btn {
    display: flex; align-items: center; gap: var(--s-3);
    padding: 13px var(--s-5);
    background: var(--grad-primary);
    border-radius: var(--r-xl);
    color: #fff; font-size: 15px; font-weight: 700;
    margin: var(--s-4) 0; cursor: pointer;
    box-shadow: var(--shadow-primary);
    transition: transform var(--t-base) var(--ease-spring), box-shadow var(--t-fast) var(--ease);
    border: none; width: 100%; font-family: var(--font-body);
  }
  .sidebar-post-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 32px var(--primary-glow); }
  .sidebar-post-btn:active { transform: scale(0.97); }
  .sidebar-post-btn img.isax { width: 20px; height: 20px; filter: invert(1); }

  .sidebar-user {
    display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-3) var(--s-3);
    border-radius: var(--r-lg);
    cursor: pointer;
    transition: background var(--t-fast) var(--ease);
    margin-top: var(--s-4);
  }
  .sidebar-user:hover { background: var(--surface-2); }
  .sidebar-user .avatar { width: 40px; height: 40px; flex-shrink: 0; }
  .sidebar-user-info { flex: 1; min-width: 0; }
  .sidebar-user-name { font-size: 14px; font-weight: 700; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .sidebar-user-handle { font-size: 12px; color: var(--text-3); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .sidebar-user img.isax { opacity: 0.5; width: 18px; height: 18px; flex-shrink: 0; }

  .sq-portfolio-back {
    display: block;
    position: fixed;
    top: 14px;
    right: 20px;
    z-index: 9999;
    font-size: .62rem;
    letter-spacing: .05em;
    color: var(--text-3);
    opacity: .7;
    transition: color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
  }
  .sq-portfolio-back:hover { color: var(--text-2); opacity: 1; }
}

/* =============================================
   RIGHT PANEL
============================================= */
.right-panel { display: none; }

@media (min-width: 900px) {
  .right-panel {
    display: flex; flex-direction: column;
    height: 100dvh; padding: var(--s-6) var(--s-5);
    position: sticky; top: 0;
    overflow-y: auto; gap: var(--s-5);
    scrollbar-width: none;
  }
  .right-panel::-webkit-scrollbar { display: none; }

  .right-panel-search {
    background: var(--surface); border-radius: var(--r-full);
    border: 1.5px solid var(--border);
    display: flex; align-items: center; gap: var(--s-2);
    padding: 0 var(--s-4); height: 44px;
    transition: border-color var(--t-fast) var(--ease); flex-shrink: 0;
  }
  .right-panel-search:focus-within { border-color: var(--primary); }
  .right-panel-search img.isax { opacity: 0.5; width: 18px; height: 18px; }
  .right-panel-search input { flex: 1; font-size: 14px; color: var(--text); }
  .right-panel-search input::placeholder { color: var(--text-3); }

  .right-panel-card {
    background: var(--surface); border-radius: var(--r-xl);
    border: 1px solid var(--border); overflow: hidden; flex-shrink: 0;
  }
  .right-panel-title {
    font-family: var(--font-display); font-size: 16px; font-weight: 800;
    color: var(--text); padding: var(--s-4) var(--s-4) var(--s-3);
  }

  .trending-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--s-3) var(--s-4); cursor: pointer;
    transition: background var(--t-fast) var(--ease);
    border-top: 1px solid var(--border);
  }
  .trending-item:hover { background: var(--surface-2); }
  .trending-hashtag { font-size: 14px; font-weight: 700; color: var(--text); }
  .trending-count { font-size: 12px; color: var(--text-3); }
  .trending-rank { font-size: 11px; font-weight: 500; color: var(--text-3); margin-bottom: 2px; }

  .suggested-user {
    display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-3) var(--s-4); border-top: 1px solid var(--border);
  }
  .suggested-user .avatar { width: 40px; height: 40px; flex-shrink: 0; }
  .suggested-user-info { flex: 1; min-width: 0; }
  .suggested-user-name { font-size: 13px; font-weight: 700; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .suggested-user-handle { font-size: 12px; color: var(--text-3); }
  .follow-btn-small {
    font-size: 12px; font-weight: 700; color: var(--primary);
    background: var(--primary-glow); border: none;
    padding: 5px 14px; border-radius: var(--r-full); cursor: pointer;
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
    flex-shrink: 0; font-family: var(--font-body);
  }
  .follow-btn-small:hover { background: var(--primary); color: #fff; }
  .follow-btn-small.following { background: var(--surface-3); color: var(--text-2); }

  .right-panel-footer { font-size: 11px; color: var(--text-3); line-height: 1.8; padding: 0; }
  .right-panel-footer a { color: var(--text-3); margin-right: 4px; }
  .right-panel-footer a:hover { color: var(--primary); }
}

/* =============================================
   MOBILE TOP HEADER
============================================= */
.top-header {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-w); height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-4);
  background: var(--grad-glass);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  transition: background var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
[data-theme="dark"] .top-header { background: rgba(10,10,20,0.88); }

.top-header .logo {
  font-family: var(--font-display); font-size: 22px; font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--grad-primary);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  user-select: none;
}
.top-header .header-actions { display: flex; align-items: center; gap: var(--s-1); }

.header-icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  position: relative;
}
.header-icon-btn:hover, .header-icon-btn:active { background: var(--surface-2); color: var(--text); }
.header-icon-btn .notif-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; background: var(--primary);
  border-radius: var(--r-full); border: 2px solid var(--bg);
}

/* =============================================
   MOBILE BOTTOM NAV
============================================= */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-w); height: var(--nav-h);
  display: flex; align-items: center; justify-content: space-around;
  padding: 0 var(--s-3);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--grad-glass);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  z-index: 200;
  transition: background var(--t-base) var(--ease);
}
[data-theme="dark"] .bottom-nav { background: rgba(10,10,20,0.88); }

.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: var(--s-2) 0;
  color: var(--text-3);
  transition: color var(--t-fast) var(--ease);
  position: relative; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.nav-item img.isax { width: 22px; height: 22px; transition: transform var(--t-base) var(--ease-spring); opacity: 0.5; }
.nav-item .nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.2px; }
.nav-item.active { color: var(--primary); }
.nav-item.active img.isax { transform: scale(1.1); opacity: 1; }
.nav-item.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; background: var(--primary);
  border-radius: 0 0 var(--r-full) var(--r-full);
}

.nav-item.nav-fab { flex: 0 0 60px; }
.nav-fab-btn {
  width: 50px; height: 50px; border-radius: var(--r-lg);
  background: var(--grad-primary);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-primary); color: #fff;
  transition: transform var(--t-base) var(--ease-spring);
  border: none; cursor: pointer;
}
.nav-fab-btn img.isax { width: 22px; height: 22px; filter: invert(1); opacity: 1; }
.nav-fab-btn:active { transform: scale(0.9); }
.nav-item.nav-fab::before { display: none; }
.nav-item.nav-fab.active { color: var(--text-3); }

/* =============================================
   AVATAR
============================================= */
.avatar { border-radius: var(--r-full); object-fit: cover; flex-shrink: 0; display: block; background: var(--surface-2); }
.avatar-ring {
  padding: 4px; border-radius: var(--r-full);
  background: var(--grad-story);
  display: inline-flex; flex-shrink: 0;
}
.avatar-ring .avatar { border: 3px solid var(--bg); }
.avatar-ring.viewed { background: var(--surface-3); }

/* =============================================
   PAGE TRANSITION OVERLAY
============================================= */
.page-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 9999; pointer-events: none; opacity: 1; animation: sq-fade-in 0.15s ease-out forwards; }
@keyframes sq-fade-in { to { opacity: 0; } }

/* =============================================
   TOAST
============================================= */
.toast-container {
  position: fixed; bottom: calc(var(--nav-h) + var(--s-4)); left: 50%; transform: translateX(-50%);
  z-index: 500; pointer-events: none; max-width: 360px; width: calc(100% - var(--s-8));
}
@media (min-width: 900px) { .toast-container { bottom: var(--s-6); } }

.toast {
  background: var(--text); color: var(--bg);
  padding: 12px var(--s-5); border-radius: var(--r-lg);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(12px) scale(0.96); text-align: center; margin-top: var(--s-2);
}

/* =============================================
   SKELETON
============================================= */
@keyframes shimmer { 0%{background-position:-200% center} 100%{background-position:200% center} }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.6s ease infinite; border-radius: var(--r-sm);
}

/* =============================================
   UTILITIES
============================================= */
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reveal { opacity: 0; transform: translateY(20px); }
.font-display { font-family: var(--font-display); }

/* Custom cursor disabled — native cursor used */

/* Centered page for medium screens (tablets) */
@media (min-width: 520px) and (max-width: 899px) {
  body { background: var(--bg-alt); }
  .page { box-shadow: var(--shadow-lg), 0 0 0 1px var(--border); border-radius: var(--r-xl); overflow: hidden; }
}
