/* F1: 左侧导航样式
   固定左栏 220px，分组可折叠，当前路由高亮
   I4（2026-09-29）：顶栏 _nav.html 已删，本侧栏成为唯一导航外壳 ——
   布局改成 flex 纵向三段（品牌 / 可滚动菜单 / 固定的底部区），
   底部区收纳原来的用户菜单、部门告警、余额条、新手引导。 */

.if-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 滚动交给 .if-sidebar-nav，底部区固定在下面 */
  z-index: 50;
  font-size: 14px;
  box-sizing: border-box;
}

.if-sidebar-brand {
  padding: 16px 16px 12px;
  border-bottom: 1px solid #e5e7eb;
}

.if-sidebar-brand a {
  color: #1f2937;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  display: block;
}

.if-sidebar-brand a:hover {
  color: var(--brand-strong, #5BC85A);
}

.if-sidebar-nav {
  padding: 8px 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.if-sidebar-loading {
  color: #6b7280;
  padding: 12px 16px;
  font-size: 13px;
}

.if-sidebar-group {
  margin-bottom: 8px;
}

.if-sidebar-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  user-select: none;
}

.if-sidebar-group-head[data-toggleable="true"] {
  cursor: pointer;
}

.if-sidebar-group-head[data-toggleable="true"]:hover {
  color: #4b5563;
}

.if-sidebar-group-head .if-sidebar-caret {
  font-size: 10px;
  transition: transform 0.15s ease;
}

.if-sidebar-group[data-open="false"] .if-sidebar-caret {
  transform: rotate(-90deg);
}

.if-sidebar-group[data-open="false"] .if-sidebar-group-body {
  display: none;
}

.if-sidebar-group-body {
  display: flex;
  flex-direction: column;
}

.if-sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 8px 24px;
  color: #4b5563;
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.1s ease, color 0.1s ease;
}

.if-sidebar-item:hover {
  background: #f8fafc;
  color: #1f2937;
}

.if-sidebar-item.active {
  background: #f8fafc;
  color: var(--brand-strong, #5BC85A);
  border-left-color: var(--brand-strong, #5BC85A);
}

.if-sidebar-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.if-sidebar-mark {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--brand, #71DC68);
  color: var(--brand-ink, #14331B);
  margin-left: 6px;
  font-weight: 600;
}

/* I4：旧功能页的「旧版」小标 —— 灰色，别用蓝色（蓝色是 NEW 的语义） */
.if-sidebar-mark.if-mark-legacy {
  background: #6b7280;
  color: #fff;
}

/* ---------- I4：侧栏底部区（用户 / 告警 / 余额 / 引导） ---------- */

.if-sidebar-foot {
  flex: 0 0 auto;
  border-top: 1px solid #e5e7eb;
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.if-sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #4b5563;
}

.if-sidebar-user span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.if-sidebar-user a,
.if-sidebar-user button {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  text-decoration: none;
  cursor: pointer;
}

.if-sidebar-user a:hover,
.if-sidebar-user button:hover {
  background: #f3f4f6;
}

/* 部门预算告警（D15 起是"用量参考"提示，不是限制） */
.if-sidebar-alert {
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fef3c7;
  border: 1px solid #facc15;
  color: #854d0e;
}

.if-sidebar-alert.is-over {
  background: #fee2e2;
  border-color: #dc2626;
  color: #991b1b;
}

/* AI 服务余额告警（仅 admin，渲染在「管理」组里） */
.if-sidebar-item.if-sidebar-balance {
  gap: 6px;
  margin: 4px 8px 0;
  padding: 6px 10px;
  border-radius: 6px;
  border-left: none;
  font-size: 12px;
  font-weight: 500;
}

.if-sidebar-item.if-sidebar-balance .if-sidebar-balance-icon {
  flex: 0 0 auto;
}

.if-sidebar-item.if-sidebar-balance.is-ok {
  background: #ecfdf5;
  color: #047857;
}

.if-sidebar-item.if-sidebar-balance.is-warn {
  background: #fef3c7;
  color: #92400e;
}

.if-sidebar-item.if-sidebar-balance.is-danger {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 600;
}

/* 积分余额条：原本是顶栏下的全站横条（style.css 里 position:sticky / top:56px），
   这里覆盖成侧栏内的一块（不 sticky、不占满宽度） */
.if-sidebar .points-bar {
  position: static;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  font-size: 12px;
  z-index: auto;
}

.if-sidebar .points-bar .points-bar-track {
  display: none;
}

.if-sidebar .points-name {
  white-space: normal;
}

/* 新手引导：顶栏时代是全宽 banner，侧栏里收成一块卡片 */
.if-sidebar .onboarding-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  background: var(--brand-soft, rgba(113,220,104,.14));
  border: 1px solid var(--brand-line, #A9EFA4);
  color: var(--brand-strong, #5BC85A);
}

.if-sidebar .onboarding-banner.hidden {
  display: none;
}

.if-sidebar .onboarding-banner button {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid var(--brand-line, #A9EFA4);
  background: #fff;
  color: var(--brand-strong, #5BC85A);
  cursor: pointer;
}

.if-sidebar-item.soon {
  color: #5e6573;
}

.if-sidebar-item.soon:hover {
  background: transparent;
}

/* 把 main 内容向右推 220px（页面级覆盖） */
body.has-if-sidebar .container,
body.has-if-sidebar > main.container {
  margin-left: 220px !important;
  max-width: none !important;
  padding-left: 24px;
  padding-right: 24px;
}

/* 顶栏也要向右推 */
body.has-if-sidebar .topnav {
  padding-left: 220px !important;
}

/* admin_dashboard 等用 dashboard.css 的页面：让内部 grid 适配侧栏 */
@media (max-width: 900px) {
  .if-sidebar {
    width: 60px;
  }
  .if-sidebar-brand a {
    font-size: 0;
  }
  .if-sidebar-brand a::before {
    content: "🖼️";
    font-size: 18px;
  }
  .if-sidebar-item-name,
  .if-sidebar-group-head .if-sidebar-title,
  .if-sidebar-mark {
    display: none;
  }
  /* I4：窄屏侧栏只剩图标 —— 底部区里的长文案（引导/告警/余额）也收起，
     只留用户区（登录/登出）这一个可点的东西 */
  .if-sidebar-foot .onboarding-banner,
  .if-sidebar-foot .if-sidebar-alert,
  .if-sidebar-foot .points-bar {
    display: none;
  }
  .if-sidebar-user span {
    display: none;
  }
  .if-sidebar-user {
    justify-content: center;
  }
  body.has-if-sidebar .container,
  body.has-if-sidebar > main.container {
    margin-left: 60px !important;
  }
  body.has-if-sidebar .topnav {
    padding-left: 60px !important;
  }
}
