/* 布局层：登录页、应用骨架、侧栏、顶栏、视图容器、响应式。
   禁止出现 hex / rgb 字面量。 */

/* ============================================================
   登录 / 注册
   ============================================================ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--sp-5);
  background: var(--canvas);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: var(--sp-6);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xl);
  background: var(--surface-1);
  box-shadow: var(--shadow-2);
  animation: rise var(--dur-slow) var(--ease-out);
}

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

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}
.auth-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  border-radius: var(--radius-lg);
  background: var(--primary-soft);
  color: var(--primary);
}
.auth-title { font-size: var(--fs-h1); }
.auth-sub { margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-muted); }

.seg {
  display: flex;
  gap: var(--sp-1);
  padding: var(--sp-1);
  margin-bottom: var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.seg-btn {
  flex: 1;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.seg-btn.is-active { background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow-1); }

.auth-form { display: flex; flex-direction: column; gap: var(--sp-4); }
/* 登录卡内的字段标签比正文更淡一档,避免与输入内容抢视觉 */
.auth-form .field-label { letter-spacing: .01em; }

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label { font-size: var(--fs-xs); font-weight: 500; color: var(--ink-muted); }
.field-wrap { position: relative; display: block; }
.field-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  color: var(--ink-subtle);
  pointer-events: none;
}
.field-wrap .input {
  /* 左侧留出图标位置,高度略高于普通输入框,配合登录卡的留白 */
  height: 42px;
  padding-left: 38px;
  font-size: var(--fs-body);
}
/* 右侧带操作按钮(例如显示密码)时,避免文字被按钮压住 */
.field-wrap-action .input { padding-right: 42px; }
.field-action {
  position: absolute;
  right: var(--sp-2);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-subtle);
  cursor: pointer;
}
.field-action:hover { color: var(--ink); background: var(--surface-2); }

.auth-hint { min-height: 18px; font-size: var(--fs-xs); color: var(--danger); }
.auth-hint.ok { color: var(--ok); }
.auth-foot {
  margin-top: var(--sp-5);
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--ink-subtle);
}
/* 联系管理员:用主色强调,与普通说明文字区分 */
.auth-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--primary-soft);
  padding-bottom: 1px;
}
.auth-link:hover { color: var(--primary-hover); border-bottom-color: var(--primary); }
/* 协议入口是 button 而不是 a:它要弹窗而不是跳转。
   用 button 保留键盘焦点与回车触发,比给 a 加 onclick 更无障碍友好。 */
.auth-link-btn {
  background: none;
  border: 0;
  border-bottom: 1px dashed transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* ============================================================
   应用骨架
   ============================================================ */
.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- 侧栏 ---------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--hairline);
  background: var(--surface-2);
  transition: transform var(--dur) var(--ease);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  height: var(--topbar-h);
  padding: 0 var(--sp-3) 0 var(--sp-4);
  border-bottom: 1px solid var(--hairline);
}
.side-brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.side-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary);
  flex: 0 0 auto;
}
.side-brand-text { display: flex; flex-direction: column; min-width: 0; }
.side-brand-text strong {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-brand-text small { font-size: var(--fs-xxs); color: var(--ink-subtle); }
.side-close { display: none; }

.side-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-2);
}

.nav-group-label {
  padding: var(--sp-3) var(--sp-2) var(--sp-1);
  font-size: var(--fs-xxs);
  font-weight: 600;
  color: var(--ink-subtle);
  letter-spacing: .04em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 8px var(--sp-2);
  margin-bottom: 2px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-body);
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-item > i { display: inline-flex; color: var(--ink-subtle); flex: 0 0 auto; }
.nav-item > span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item:hover > i { color: var(--ink-muted); }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 500; }
.nav-item.is-active > i { color: var(--primary); }

.nav-count {
  min-width: 20px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--surface-4);
  color: var(--ink-muted);
  font-size: var(--fs-xxs);
  font-weight: 500;
  text-align: center;
}
.nav-item.is-active .nav-count { background: var(--primary); color: var(--on-primary); }
.nav-count-alert:not([hidden]) { background: var(--warn-soft); color: var(--warn); }
.nav-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex: 0 0 auto;
}

/* 最近对话(置顶显示在导航上方) */
.side-recent {
  flex: 0 0 auto;
  max-height: 42%;
  display: flex;
  flex-direction: column;
  padding: var(--sp-2);
  border-bottom: 1px solid var(--hairline);
}
.side-recent-top { border-top: 0; }
.side-recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-1) var(--sp-2);
  font-size: var(--fs-xxs);
  font-weight: 600;
  color: var(--ink-subtle);
}
.recent-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.recent-item {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  width: 100%;
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
}
.recent-item:hover { background: var(--surface-3); color: var(--ink); }
.recent-item.is-active { background: var(--surface-1); color: var(--ink); }
.recent-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  font-size: var(--fs-xs);
  text-align: left;
  cursor: pointer;
}
.recent-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .icon-btn { opacity: 0; flex: 0 0 auto; margin-right: 2px; }
.recent-item:hover .icon-btn,
.recent-item:focus-within .icon-btn { opacity: 1; }
.recent-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  margin-top: var(--sp-1);
  padding: 5px var(--sp-2);
  border: 1px dashed var(--hairline-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-subtle);
  font-size: var(--fs-xxs);
  cursor: pointer;
}
.recent-more:hover { color: var(--primary); border-color: var(--primary); }
.recent-more.is-open i { transform: rotate(180deg); }
.recent-more i { display: inline-flex; transition: transform var(--dur-fast) var(--ease); }

/* 侧栏底部 */
.side-foot { flex: 0 0 auto; border-top: 1px solid var(--hairline); padding: var(--sp-2); }
.user-row { display: flex; align-items: center; gap: var(--sp-2); }
.user-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.user-meta strong {
  font-size: var(--fs-xs);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-meta small { font-size: var(--fs-xxs); color: var(--ink-subtle); }
.user-meta small.warn { color: var(--warn); }
.user-meta small.ok { color: var(--ok); }

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 29;
}

/* ---------------- 主区 ---------------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--canvas);
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--topbar-h);
  flex: 0 0 auto;
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--hairline);
  background: var(--canvas);
}
.topbar-menu { display: none; }
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title h2 { font-size: var(--fs-h2); }
.topbar-title p {
  font-size: var(--fs-xxs);
  color: var(--ink-subtle);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); flex: 0 0 auto; }

.view-root { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

.view {
  max-width: var(--view-max);
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-5) var(--sp-8);
  animation: fadeIn var(--dur) var(--ease-out);
}
.view-full { max-width: none; padding: 0; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.view-head-text h3 { font-size: var(--fs-h3); }
.view-head-text p { margin-top: 2px; font-size: var(--fs-xs); color: var(--ink-muted); }
.view-head-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* 网格 */
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.grid-stats { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }

/* ============================================================
   响应式：768 / 1024 / 1440
   ============================================================ */
@media (max-width: 1024px) {
  .view { padding: var(--sp-4) var(--sp-4) var(--sp-7); }
  .topbar { padding: 0 var(--sp-4); }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-100%);
    box-shadow: var(--shadow-3);
  }
  .sidebar.open { transform: none; }
  .side-close { display: inline-flex; }
  .topbar-menu { display: inline-flex; }
  .form-grid.two { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .side-recent { max-height: 32%; }
  /* 窄屏侧栏空间紧张:用户卡片收紧内距并把头像降一档,避免挤压导航与最近对话 */
  .side-user { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .side-user .avatar-xl { width: 52px; height: 52px; font-size: var(--fs-sm); }
}

@media (min-width: 1440px) {
  :root { --view-max: 1200px; }
}
