/* ===== Layout ===== */
.app-layout {
  display: flex;
  height: 100dvh; height: 100vh;
  overflow: hidden;
}

/* 页面切换淡入淡出（非上浮） */
#app {
  transition: opacity .2s ease;
  width: 100%;
}
#app.is-leaving {
  opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
  #app { transition: none; }
  #app.is-leaving { opacity: 1; }
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--acrylic-sidebar);
  -webkit-backdrop-filter: blur(26px);
  backdrop-filter: blur(24px);
  border-right: 1px solid var(--border);
  padding: calc(16px + env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom)) 12px;
  transition: width .25s ease;
}
.sidebar.collapsed {
  width: 0; padding-left: 0; padding-right: 0;
  border-right: none; overflow: hidden;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; position: relative; z-index: 2;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 18px;
  color: var(--brand);
  user-select: none;
}
.logo-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* 品牌 logo 图片（替换 GooseBlog 文字） */
.brand-logo {
  height: 26px; width: auto; display: block;
  user-select: none;
  position: relative; z-index: 2;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,.65));
}
.brand-logo-top { height: 22px; }

/* 侧栏横幅图（背景图 + 透明一言 overlay） */
.sidebar-banner {
  margin: -56px -12px -8px; width: calc(100% + 24px);
  height: 150px;
  border-radius: 6px;
  overflow: hidden;
  position: relative; z-index: 1;
  background-size: cover; background-repeat: no-repeat; background-position: center center;
  -webkit-mask-image:
    linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%),
    linear-gradient(to bottom, transparent 0, #000 8px, #000 calc(100% - 8px), transparent 100%);
  mask-composite: intersect;
}
.banner-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end;
  padding: 12px 14px;
  background: linear-gradient(to top, rgba(0,0,0,.6), rgba(0,0,0,.12) 55%, transparent);
}
.banner-subtitle {
  font-size: 12.5px; line-height: 1.55;
  color: #fff; font-family: var(--ui-font);
  text-shadow: 0 1px 4px rgba(0,0,0,.7);
  word-break: break-word;
}
.typing-cursor {
  color: #fff; margin-left: 1px; font-weight: 400;
  animation: typing-blink 1s step-end infinite;
}
@keyframes typing-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.96); }

.nav-list {
  position: relative; z-index: 2;
  flex: 1;
  overflow-y: auto;
  margin-top: 4px;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  overflow: hidden;
}
.nav-item:hover { background: var(--surface-hover); }
.nav-item.active { background: var(--surface); color: var(--brand); }
.nav-item-icon { margin-right: 8px; color: var(--text-secondary); flex-shrink: 0; }
.nav-item.active .nav-item-icon { color: var(--brand); }
.nav-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }

.user-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 6px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.user-bar:hover { background: var(--surface-hover); }

/* 侧栏开关（落叶飘落等） */
.sidebar-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 6px; margin-top: auto;
  font-size: 13px; color: var(--text-secondary);
  font-family: var(--ui-font);
}
.sidebar-toggle .toggle-label { user-select: none; }
.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 999px;
  transition: background .2s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 14px; width: 14px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.user-name { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--acrylic-header);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.mobile-header .logo { flex: 1; display: flex; justify-content: center; font-size: 16px; }

/* 顶部操作栏 */
.chat-header {
  display: flex;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  font-size: 15px;
  color: var(--text);
  background: var(--acrylic-header);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.chat-header-actions { margin-left: auto; display: flex; gap: 4px; }
.header-actions-left { margin-left: 0; }
.header-icon-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none;
  color: var(--text-secondary); border-radius: 6px;
  cursor: pointer; font-size: 15px;
  transition: background .15s, color .15s;
}
.header-icon-btn:hover { background: var(--surface); color: var(--text); }
.header-icon-btn.active { color: var(--brand); background: var(--surface); }
.header-icon-btn:disabled { opacity: .3; cursor: default; pointer-events: none; }

/* 自定义右键菜单 */
.ctx-menu {
  position: fixed; z-index: 9999; display: none;
  min-width: 168px; padding: 6px;
  background: var(--acrylic-bar); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0,0,0,.28);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.ctx-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: none; background: transparent;
  color: var(--text); font-size: 13px; text-align: left;
  border-radius: 6px; cursor: pointer;
}
.ctx-item i { width: 16px; text-align: center; color: var(--text-secondary); }
.ctx-item:hover { background: var(--surface-hover); color: var(--text); }
.ctx-item:hover i { color: var(--brand); }
.ctx-item.disabled { opacity: .35; pointer-events: none; }
.ctx-sep { height: 1px; margin: 5px 4px; background: var(--border); }
.chat-header-title {
  font-weight: 500; max-width: 320px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-mode {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-secondary);
}

/* 首页视图模式切换 */
.view-mode-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.tool-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--acrylic-bar);
  color: var(--text-secondary); font-size: 13px; cursor: pointer;
  font-family: var(--ui-font);
  transition: background .15s, color .15s, border-color .15s;
}
.tool-chip:hover { color: var(--text); }
.tool-chip.active { color: var(--brand); background: var(--brand-soft); border-color: var(--brand); }

/* 文章卡片上的标签胶囊 */
.post-card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.post-card-tag {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill);
  border: 1px solid rgba(249,115,22,.35); background: rgba(249,115,22,.10);
  color: #e8590c; font-size: 12px;
  font-family: var(--ui-font);
}

.chat-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom)) 24px;
  scrollbar-width: none;
  background: var(--acrylic-panel);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.chat-center::-webkit-scrollbar { display: none; }

/* ===== Overlay ===== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 30;
  opacity: 0;
  transition: opacity .25s ease;
}
.overlay.show { opacity: 1; }

/* 隐藏的写文章入口（彩蛋：主题按钮连点 4 次触发导航到 /admin） */
.nav-admin-hidden { display: none !important; }

/* 禁用双击缩放/点击延迟，避免连按（如主题按钮彩蛋）被识别为放大手势 */
button, a, .nav-item, .icon-btn, .header-icon-btn { touch-action: manipulation; }

/* 第三方装饰特效画布（花瓣飘落 + 点击爆炸）不拦截鼠标点击 */
#canvas_sakura, body > canvas { pointer-events: none !important; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .mobile-header { display: flex; }
  .chat-header { display: none; }
  .chat-center { padding: 16px; }
}

/* ===== 浅色主题（照 gooseAI 主题切换） ===== */
:root[data-theme="light"] {
  --bg: #f4f2fa;
  --bg-gradient: linear-gradient(135deg, #ece8f7 0%, #f4f2fa 50%, #e8eef7 100%);
  --sidebar-bg: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f0ecf8;
  --border: #e3ddf0;
  --text: #211d30;
  --text-secondary: #6b6385;
  --acrylic-sidebar: rgba(255,255,255,0.72);
  --acrylic-panel: rgba(255,255,255,0.6);
  --acrylic-header: rgba(255,255,255,0.75);
  --acrylic-bar: rgba(255,255,255,0.55);
  --acrylic-input: rgba(255,255,255,0.75);
}
:root[data-theme="light"] body::before { opacity: 0.22; }
