/* ==========================================================================
   骨架：应用三区（侧边栏 / 主区 / 输入区）与自适应
   ========================================================================== */

.app {
  display: flex;
  height: 100dvh;
  background: var(--bg);
}

/* ============================ 侧边栏 ============================ */
.sidebar {
  position: relative;
  flex: none;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(180%) blur(var(--blur-chrome));
  backdrop-filter: saturate(180%) blur(var(--blur-chrome));
  border-right: 1px solid var(--hairline);
  transition: margin-left var(--dur-base) var(--ease-spring);
  z-index: 30;
}

.app[data-sidebar='collapsed'] .sidebar {
  margin-left: calc(-1 * var(--sidebar-w));
}

.sidebar-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-3) 0 var(--sp-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1;
  min-width: 0;
}

.brand-mark {
  width: 22px;
  height: 22px;
  flex: none;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 7px;
  background: linear-gradient(160deg, #4aa8ff 0%, var(--blue) 55%, #0059c8 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 2px rgba(0, 0, 0, 0.18);
}

.brand-mark .icon {
  width: 13px;
  height: 13px;
  stroke-width: 2;
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-subhead);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sidebar-body {
  flex: 1;
  min-height: 0;
  padding: 0 var(--sp-2) var(--sp-2);
}

.list-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
  font-size: var(--fs-caption);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-4);
}

/* 会话行 */
.conv {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 36px;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
  transition: background-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.conv:hover {
  background: var(--hover);
  color: var(--text-1);
}

.conv[aria-current='true'] {
  background: var(--selected);
  color: var(--text-1);
  font-weight: 500;
}

.conv-title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-footnote);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  flex: none;
  font-size: var(--fs-caption2);
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
}

.conv[aria-current='true'] .conv-time {
  display: none;
}

.conv-actions {
  display: none;
  flex: none;
  gap: 2px;
}

.conv:hover .conv-actions,
.conv[aria-current='true'] .conv-actions {
  display: flex;
}

.conv-act {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: var(--r-xs);
  color: var(--text-3);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.conv-act:hover {
  background: var(--pressed);
  color: var(--text-1);
}

.conv-act .icon {
  width: 13px;
  height: 13px;
}

/* 会话重命名输入 */
.conv-rename {
  flex: 1;
  min-width: 0;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--blue);
  border-radius: var(--r-xs);
  background: var(--surface);
  font-size: var(--fs-footnote);
  outline: none;
}

.sidebar-foot {
  flex: none;
  padding: var(--sp-2);
  border-top: 1px solid var(--hairline);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-footnote);
  color: var(--text-2);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.sidebar-link:hover {
  background: var(--hover);
  color: var(--text-1);
}

.sidebar-link .icon {
  width: 16px;
  height: 16px;
  color: var(--text-3);
}

.sidebar-link:hover .icon {
  color: var(--text-2);
}

.mode-dot {
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent);
}

.mode-dot[data-mode='mock'] {
  background: var(--orange);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 18%, transparent);
}

/* ============================ 主区 ============================ */
.main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: relative;
  z-index: 20;
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-3);
  background: var(--chrome);
  -webkit-backdrop-filter: saturate(180%) blur(var(--blur-chrome));
  backdrop-filter: saturate(180%) blur(var(--blur-chrome));
  border-bottom: 1px solid var(--hairline);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 var(--sp-2);
}

.topbar-title h1 {
  font-size: var(--fs-footnote);
  font-weight: 600;
  letter-spacing: -0.005em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-meta {
  font-size: var(--fs-caption2);
  line-height: 1.3;
  color: var(--text-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.app[data-sidebar='expanded'] .btn-sidebar-toggle {
  display: none;
}

@media (min-width: 861px) {
  .btn-sidebar-toggle {
    display: none;
  }
}

/* ============================ 舞台：滚动区 + 输入区 ============================ */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scroll-area {
  flex: 1;
  min-height: 0;
}

/* 欢迎态与消息流互斥显示，二者都占据滚动区 */
.welcome-scroll {
  background: var(--bg);
}

[hidden] {
  display: none !important;
}

.thread {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-7) var(--sp-6) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

/* ============================ 输入区 ============================ */
.dock {
  position: relative;
  z-index: 15;
  flex: none;
  padding: 0 var(--sp-6) var(--sp-5);
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.composer {
  width: 100%;
  max-width: var(--composer-max);
  margin: 0 auto;
}

/* 顶部滚动渐隐遮罩 */
.stage::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 24px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(to bottom, var(--bg), transparent);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

.stage[data-scrolled='true']::before {
  opacity: 1;
}

/* ============================ 窄屏 ============================ */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    margin-left: 0;
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-spring);
    background: var(--chrome-strong);
    box-shadow: none;
  }

  .app[data-sidebar='expanded'] .sidebar {
    transform: none;
    box-shadow: var(--shadow-lg);
  }

  .app[data-sidebar='expanded'] .scrim {
    opacity: 1;
    pointer-events: auto;
  }

  .thread {
    padding: var(--sp-6) var(--sp-4) var(--sp-4);
    gap: var(--sp-5);
  }

  .dock {
    padding: 0 var(--sp-3) var(--sp-3);
  }

  .btn-sidebar-toggle {
    display: inline-flex;
  }
}

@media (min-width: 861px) {
  .btn-sidebar-toggle {
    display: none;
  }
}

/* 侧边栏遮罩（仅窄屏生效） */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 25;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}

@media (min-width: 861px) {
  .scrim {
    display: none;
  }
}

/* 顶部拖拽条（视觉上呼应 macOS 窗口，仅在桌面显示） */
@media (min-width: 861px) {
  .sidebar-head::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
  }
}
