/* ==========================================================================
   海若心语 · 温润海洋人文风 全局样式表 (Warm Ocean & Editorial Zen)
   ========================================================================== */

:root {
  /* 品牌核心色彩体系 (拒绝赛博荧光，回归静谧深海与人文纸感) */
  --primary: #1E3A5F;            /* 深海靛青：主色调、沉稳、信任 */
  --primary-hover: #152C47;      /* 悬浮深色 */
  --primary-light: #2C5E8A;      /* 治愈海蓝：用户气泡、高亮 */
  --primary-soft: #EBF3FA;       /* 浅海浪花：轻量背景衬底 */
  --primary-subtle: #F0F6FB;     /* 极柔海风底色 */
  
  --accent: #0D9488;             /* 润玉青翠：强调点缀、状态正常 */
  --accent-soft: #CCFBF1;
  --danger: #E11D48;             /* 珊瑚玫瑰：警示、删除、停止 */
  --danger-soft: #FFE4E6;
  --warning: #D97706;
  --warning-soft: #FEF3C7;

  /* 背景与纸质感表面 */
  --bg-canvas: #F8FAFC;          /* 主视口晨雾白纸质背景 */
  --bg-surface: #FFFFFF;         /* 卡片洁白表面 */
  --bg-sidebar: #F1F5F9;         /* 侧边栏冷灰蓝纸面 */
  --bg-input: #FFFFFF;           /* 输入框纯白 */
  
  /* 边框与阴影 */
  --border: #E2E8F0;             /* 标准边框 */
  --border-subtle: #EDF2F7;      /* 极浅分割线 */
  --border-focus: #2C5E8A;       /* 聚焦高亮边框 */
  
  --shadow-sm: 0 1px 3px rgba(30, 58, 95, 0.04);
  --shadow-md: 0 4px 14px rgba(30, 58, 95, 0.07);
  --shadow-lg: 0 12px 32px rgba(30, 58, 95, 0.11);
  --shadow-float: 0 8px 24px rgba(30, 58, 95, 0.09);

  /* 文字排版系统 */
  --text-main: #1E293B;          /* 正文炭墨色：柔和高对比，保护视力 */
  --text-muted: #64748B;         /* 次要文本灰 */
  --text-light: #94A3B8;         /* 占位符与微弱注释 */
  --text-inverse: #FFFFFF;       /* 反白文字 */

  /* 圆角 */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 9999px;

  /* 尺寸与过渡 */
  --sidebar-width: 270px;
  --header-height: 58px;
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 全局 Reset */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--text-main);
  background-color: var(--bg-canvas);
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 按钮与输入框基类 */
button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

input, textarea {
  font-family: inherit;
  border: none;
  background: none;
  outline: none;
  color: inherit;
}

/* ==========================================================================
   全屏主布局体系 (App Shell)
   ========================================================================== */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

/* 遮罩层（用于移动端侧边抽屉呼出时） */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.35);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}
.drawer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   左侧沉浸侧边栏 (Sidebar)
   ========================================================================== */
.app-sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 侧边栏头部品牌 */
.sidebar-header {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-info {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 4px 10px rgba(30, 58, 95, 0.2);
  color: #fff;
}

.brand-title-wrap {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.5px;
}

.brand-slogan {
  font-size: 11px;
  color: var(--text-muted);
}

/* 关闭侧边栏按钮（仅移动端展示） */
.btn-close-drawer {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  align-items: center;
  justify-content: center;
}
.btn-close-drawer:hover {
  background: var(--border);
  color: var(--text-main);
}

/* 新建对话按钮 */
.sidebar-action-area {
  padding: 16px 18px 8px;
}

.btn-new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--primary);
  font-weight: 600;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.btn-new-chat:hover {
  background-color: var(--primary-soft);
  border-color: #B8D3EB;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* 会话历史列表区域 */
.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar-conversations::-webkit-scrollbar {
  width: 4px;
}
.sidebar-conversations::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 13.5px;
  transition: var(--transition);
  cursor: pointer;
  position: relative;
  user-select: none;
}
.conv-item:hover {
  background-color: var(--bg-surface);
  color: var(--primary);
}
.conv-item.active {
  background-color: var(--bg-surface);
  color: var(--primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--primary);
}

.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}

.conv-delete-btn {
  opacity: 0;
  color: var(--text-light);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  transition: var(--transition);
}
.conv-item:hover .conv-delete-btn {
  opacity: 1;
}
.conv-delete-btn:hover {
  color: var(--danger);
  background-color: var(--danger-soft);
}

.empty-conv-tip {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-light);
  font-size: 12.5px;
}

/* 侧边栏底部用户信息 */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
}

.user-profile-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-info-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.user-avatar-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #E2E8F0 0%, #CBD5E1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--primary);
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background-color: var(--primary-soft);
  color: var(--primary);
  font-weight: 500;
}
.role-tag.admin {
  background-color: #FEF3C7;
  color: #B45309;
}

.user-phone-text {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* 底部功能快捷操作 (设置/退出) */
.user-actions-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-sidebar-icon {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.btn-sidebar-icon:hover {
  background-color: var(--bg-sidebar);
  color: var(--text-main);
}
.btn-sidebar-icon.admin-btn:hover {
  color: var(--primary);
  background-color: var(--primary-soft);
}
.btn-sidebar-icon.logout-btn:hover {
  color: var(--danger);
  background-color: var(--danger-soft);
}

/* 未登录状态卡片 */
.unauth-card {
  padding: 8px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-login-open {
  width: 100%;
  padding: 8px 14px;
  background-color: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.btn-login-open:hover {
  background-color: var(--primary-hover);
}

/* ==========================================================================
   右侧主对话视口 (Main Chat Area)
   ========================================================================== */
.app-main {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-canvas);
  overflow: hidden;
}

/* 顶部导航栏 */
.main-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-subtle);
  background-color: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 10;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-menu {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-xs);
  align-items: center;
  justify-content: center;
  color: var(--text-main);
}
.btn-menu:hover {
  background-color: var(--bg-sidebar);
}

.active-conv-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

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

.btn-header-action {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  border: 1px solid var(--border);
}
.btn-header-action:hover {
  color: var(--primary);
  border-color: #CBD5E1;
  background: #FFF;
}

/* ==========================================================================
   通用 Toast 消息提示组件
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  background: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(6px);
  color: #FFF;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastFadeIn 0.25s ease-out;
  pointer-events: auto;
}
.toast.success { background: #065F46; }
.toast.error { background: #9F1239; }
.toast.warning { background: #92400E; }

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   移动端响应式断点适配 (max-width: 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .btn-close-drawer {
    display: flex;
  }
  .btn-menu {
    display: flex;
  }
  .main-header {
    padding: 0 16px;
  }
  .active-conv-title {
    max-width: 180px;
  }
}
