/* ============================================================
   Saylo Web Studio — Layout
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
}

.app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ---- Sidebar ---- */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  border-right: 1px solid var(--line-1);
  z-index: 30;
  min-width: 0;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--brand-gradient);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: var(--fs-18);
  box-shadow: var(--shadow-accent);
  flex: none;
}

.brand-name {
  font-weight: 800;
  font-size: var(--fs-18);
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand-sub {
  font-size: var(--fs-11);
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.sidebar-new {
  margin: var(--sp-2) var(--sp-3) var(--sp-3);
}
.sidebar-new .btn {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: var(--fs-14);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0 var(--sp-3);
  gap: 2px;
  margin-bottom: var(--sp-3);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px 12px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-weight: 500;
  font-size: var(--fs-14);
  transition: all 0.15s var(--ease);
  cursor: pointer;
  white-space: nowrap;
}
.nav-item:hover {
  background: var(--bg-3);
  color: var(--text-1);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--text-1);
}
.nav-item.active .icon {
  color: var(--accent-1);
}
.nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-count {
  font-size: var(--fs-11);
  color: var(--text-3);
  background: var(--bg-4);
  padding: 1px 7px;
  border-radius: var(--r-full);
}

.sidebar-chats {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-3);
  min-height: 0;
}
.sidebar-section-title {
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  font-size: var(--fs-11);
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s var(--ease);
  position: relative;
}
.chat-item:hover {
  background: var(--bg-3);
}
.chat-item.active {
  background: var(--accent-soft);
}
.chat-item-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: var(--fs-16);
  color: #fff;
  font-weight: 700;
}
.chat-item-body {
  flex: 1;
  min-width: 0;
}
.chat-item-name {
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-preview {
  font-size: var(--fs-12);
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item-time {
  font-size: var(--fs-11);
  color: var(--text-4);
  flex: none;
}

.sidebar-user {
  padding: var(--sp-3);
  border-top: 1px solid var(--line-1);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
}
.sidebar-user:hover {
  background: var(--bg-2);
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-grad-cool);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--fs-14);
  flex: none;
}
.user-info {
  flex: 1;
  min-width: 0;
}
.user-name {
  font-size: var(--fs-13);
  font-weight: 600;
  white-space: nowrap;
}
.user-sub {
  font-size: var(--fs-11);
  color: var(--text-3);
}

/* Collapsed sidebar */
.app.sidebar-collapsed .sidebar-brand,
.app.sidebar-collapsed .sidebar-new,
.app.sidebar-collapsed .sidebar-nav,
.app.sidebar-collapsed .sidebar-chats,
.app.sidebar-collapsed .sidebar-user {
  display: none;
}

/* ---- Main ---- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  background: var(--bg-glass);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line-1);
  z-index: 20;
  flex: none;
}

.topbar-title {
  font-weight: 700;
  font-size: var(--fs-16);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  overflow: hidden;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.content {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-6) var(--sp-8);
  scroll-behavior: smooth;
}

/* Desktop: constrain content width for readability */
.view:not(.view-chat) {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.view:not(.view-chat) > * {
  width: 100%;
  max-width: var(--content-max-w);
}

.view-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Chat view is special: no padding, full-bleed, centered */
.view-chat {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ---- Mobile ---- */
.mobile-menu-btn {
  display: none;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 82vw);
    transform: translateX(-105%);
    transition: transform 0.25s var(--ease);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .view {
    padding: var(--sp-4);
  }
  .view:not(.view-chat) {
    align-items: stretch;
  }
  .view:not(.view-chat) > * {
    max-width: 100%;
  }
  .mobile-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s var(--ease);
  }
  .mobile-scrim.show {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ---- Desktop: 1200px+ ---- */
@media (min-width: 1200px) {
  .app {
    grid-template-columns: var(--sidebar-w-wide) 1fr;
  }
  .view:not(.view-chat) > * {
    max-width: var(--content-max-w-wide);
  }
}

/* ---- Desktop: 1600px+ (ultrawide) ---- */
@media (min-width: 1600px) {
  .app {
    grid-template-columns: var(--sidebar-w-ultra) 1fr;
  }
  .view:not(.view-chat) > * {
    max-width: var(--content-max-w-wide);
  }
  .sidebar {
    border-right-width: 1px;
  }
  .nav-item {
    padding: 11px 14px;
    font-size: var(--fs-15);
  }
  .chat-item {
    padding: 11px 12px;
  }
  .sidebar-user {
    padding: var(--sp-4);
  }
}
