/* App Shell Layout */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

.app-sidebar {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 20px;
  height: 100dvh;
  padding: 20px 16px 88px;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  z-index: 100;
}

.sidebar-header {
  display: grid;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo,
.payment-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 12px;
  padding: 6px;
  background: var(--surface);
}

.sidebar-title {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.sidebar-new-button {
  width: 100%;
  min-height: 46px;
}

.sidebar-conversations {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.sidebar-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 4px 0;
}

.sidebar-account-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.sidebar-account-button:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.sidebar-account-label {
  font-size: 14px;
  font-weight: 600;
}

.sidebar-account-hint {
  font-size: 12px;
  color: var(--muted);
}

/* App Main Layout */
.app-main {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  height: 100dvh;
  padding: 20px 24px 20px 20px;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

.home-view,
.chat-view {
  min-height: 0;
}

.home-view {
  display: grid;
  place-items: center;
  overflow: auto;
  padding-right: 4px;
}

.chat-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}

.chat-view.is-empty {
  grid-template-rows: minmax(0, 1fr);
}

.chat-view.is-empty .chat-header,
.chat-view.is-empty .chat-scroll-region {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 6px 0;
}

.chat-heading h1 {
  margin-top: 6px;
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

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

.chat-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  overflow: hidden;
}

.chat-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 14px;
  overflow: hidden;
}

.chat-scroll-region {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.chat-view.is-empty .chat-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 24px;
  padding-top: clamp(48px, 10vh, 120px);
  overflow-y: auto;
}

.action-rail {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

/* Mobile Sidebar Drawer Adjustments */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-top-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
}

.mobile-brand-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-strong);
}

.mobile-spacer {
  flex: 1 1 auto;
}

.mobile-account-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background 200ms ease, border-color 200ms ease;
}

.mobile-account-button:hover {
  background: var(--surface-strong);
  border-color: var(--primary);
}

.mobile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0;
}

.mobile-menu-toggle::before {
  content: "\2630";
  font-size: 18px;
  line-height: 1;
}
.mobile-menu-toggle:hover {
  background: var(--surface);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  /* Make sidebar off-canvas */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    max-width: 85vw;
    padding-bottom: 20px;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-xl);
    background: var(--bg);
  }

  .app-shell.sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }

  .app-shell.sidebar-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-main {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mobile-top-bar {
    display: flex;
    padding-bottom: 0;
  }

  .desktop-brand {
    display: none;
  }

  .chat-layout {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-right: 0;
  }

  .chat-column {
    flex: 1 1 0;
    min-height: 0;
  }

  .chat-scroll-region {
    min-height: 0;
  }

  .chat-view.is-empty .chat-column {
    padding-top: clamp(32px, 6vh, 80px);
    gap: 20px;
  }

  .chat-view.is-empty .composer {
    align-self: stretch;
    width: 100%;
  }

  .home-view {
    display: block;
    overflow-y: auto;
  }

  .chat-view {
    overflow: hidden;
  }
}

@media (max-width: 720px) {
  .app-main {
    padding: 12px;
  }

  .chat-view {
    gap: 10px;
  }

  .chat-header {
    flex-direction: row;
    align-items: center;
    padding: 2px 4px;
    gap: 8px;
  }

  .chat-heading .eyebrow {
    display: none;
  }

  .chat-heading h1 {
    font-size: 20px;
    margin-top: 0;
    line-height: 1.2;
    letter-spacing: -0.02em;
  }

  .chat-header-actions {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
  }

  .chat-column {
    gap: 10px;
  }

  .chat-view.is-empty .chat-column {
    padding-top: 24px;
    gap: 16px;
  }
}
