/* ============================================================
   Nav - 设计 token
   风格参考 Metronic 9 (Tailwind) 的 dark-sidebar 布局:
   近黑色固定侧栏 + 白色内容区 + 克制的浅灰分割线 + 较大圆角
   中性色取自 zinc 色板, 主色取自 blue-500
   ============================================================ */

:root {
  --primary:        #2B7FFF; /* blue-500 */
  --primary-dark:   #155DFC; /* blue-600 */
  --primary-light:  #EFF6FF;

  --success:  #17C653;
  --warning:  #F6B100;
  --danger:   #F8285A;
  --info:     #78829F;

  --text-primary:   #18181B;
  --text-regular:   #3F3F46;
  --text-secondary: #71717B;
  --text-placeholder: #A1A1AA;

  --border-base:    #D4D4D8;
  --border-light:   #E4E4E7;
  --border-lighter: #EBEBEE;
  --border-extra:   #F1F1F4;

  --bg:          #FFFFFF;
  --bg-page:     #F9F9FB;
  --bg-hover:    #F4F4F5;
  --bg-disabled: #F4F4F5;

  --radius: 20px;
  --shadow-base:  0 1px 2px rgba(16, 24, 40, .05);
  --shadow-light: 0 4px 16px rgba(16, 24, 40, .08);

  --header-h: 60px;
  --sidebar-w: 240px;
  --sidebar-collapsed-w: 60px; /* 侧栏收起后只剩图标时的宽度 */
  --scroll-gap: 8px; /* 锚点跳转时 header 下方留的呼吸位 */

  /* 侧栏默认近黑(Metronic dark sidebar); 后台「外观设置」可以覆盖这三项 */
  --sidebar-bg:     #09090B;
  --sidebar-text:   #A1A1AA;
  --sidebar-active: #2B7FFF;

  /* 主题色的 rgb 分量, 供 rgba() 生成半透明背景(通透高亮用)。
     由后台注入实际值; 这里的默认值对应 --primary: #2B7FFF */
  --primary-rgb: 43, 127, 255;
}

/* 深色模式 */
[data-theme="dark"] {
  --text-primary:   #E5EAF3;
  --text-regular:   #CFD3DC;
  --text-secondary: #A3A6AD;
  --text-placeholder: #6C6E72;

  --border-base:    #4C4D4F;
  --border-light:   #414243;
  --border-lighter: #363637;
  --border-extra:   #2B2B2C;

  --bg:          #1D1E1F;
  --bg-page:     #141414;
  --bg-hover:    #262727;
  --bg-disabled: #262727;

  --primary-light: #18222c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  /* Inter 优先(与 Metronic 一致); 未安装时回退到系统字体 */
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-regular);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ============================ 顶部栏 ============================ */
.header {
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header .brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: var(--font-brand, 17px);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.header .brand .sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

.header .spacer { flex: 1; }

/* header 里的纯图标按钮(收起/展开菜单) */
.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-regular);
  cursor: pointer;
  transition: .2s;
}

.icon-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 右侧用户区: 头像占位 + 用户名 + 角色 */
.user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  margin-right: 4px;
}

.user-meta b {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-meta small {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ============================ 右上角用户下拉 ============================ */
.user-menu {
  position: relative; /* 下拉的定位基准 */
  flex: 0 0 auto;
}

.user-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background .18s;
}

.user-trigger:hover { background: var(--bg-hover); }

.caret {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .18s;
}

.user-menu.open .caret { transform: rotate(180deg); }

/* 下拉面板: 贴住触发器右下角展开 */
.user-drop {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: var(--shadow-light);
  z-index: 300;

  /* 关闭态: 不占布局也不接收点击 */
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .16s, transform .16s, visibility .16s;
}

.user-menu.open .user-drop {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.drop-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.drop-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border-lighter);
}

/* 菜单项: 链接与按钮共用一套外观(退出是 form 里的 button) */
.drop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-regular);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.drop-item:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.drop-item svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .8;
}

/* ============================ 页脚 ============================ */
.footer {
  border-top: 1px solid var(--border-light);
  background: var(--bg);
  padding: 14px 28px;
  font-size: 12px;
  color: var(--text-secondary);
}

.footer-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 14px;
  margin-left: auto;
}

.footer-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.footer-links a:hover { color: var(--primary); }

/* 前台副标题(紧跟搜索框之后) */
.brand-sub {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 后台取色控件 */
.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border-base);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .15s;
}

.swatch:hover { transform: scale(1.1); }

.swatch.sel {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--primary);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-row input[type="text"] { max-width: 140px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 20px;
}

.search-box {
  position: relative;
  width: 260px;
  max-width: 40vw;
}

.search-box input {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-regular);
  font-size: 13px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), .12);
}

.search-box .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--text-placeholder);
  stroke-width: 2;
  pointer-events: none;
}

/* ============================ 按钮 ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  padding: 0 15px;
  border: 1px solid var(--border-base);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-regular);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: .2s;
}

.btn:hover {
  color: var(--primary);
  border-color: var(--primary-light);
  background: var(--primary-light);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }

/* ============================ 主体布局 ============================ */
/* 左侧菜单: 固定定位, 通顶通底(不随内容滚动) */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg, var(--bg));
  border-right: 1px solid var(--border-light);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: width .2s ease;

  /* 深色底上的分隔线: 用半透明白, 而不是浅色主题那套灰线 */
  --sidebar-line: rgba(255, 255, 255, .08);
}

/* 品牌区与右侧 header 等高 —— 左右两栏顶部在同一条线上 */
.sidebar-brand {
  height: var(--header-h);
  flex: 0 0 var(--header-h);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--sidebar-line);
  font-size: var(--font-brand, 17px);
  font-weight: 600;
  color: #FAFAFA;
}

.brand-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Logo: 显示高度固定 24px, 宽度自适应 */
.brand-logo {
  flex: 1;
  height: 24px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
}

.brand-collapse {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #A1A1AA;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.brand-collapse:hover {
  background: rgba(255, 255, 255, .08);
  color: #FFFFFF;
}

/* ============================ 手风琴菜单 ============================ */
.nav {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
}

.nav-item,
.nav-mine { margin: 2px 0; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-text, var(--text-regular));
  font-size: var(--font-sidebar, 13px);
  line-height: 1.4;
  text-decoration: none;
  transition: background .18s, color .18s;
}

.nav-link:hover {
  background: rgba(255, 255, 255, .06);
  color: #FAFAFA;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .9;
}

.nav-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 展开箭头: 默认朝右, 展开后朝下 */
.nav-arrow {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: rotate(-90deg);
  transition: transform .18s;
  opacity: .7;
}

.nav-item.open > .nav-link .nav-arrow { transform: rotate(0deg); }

.nav-sub {
  list-style: none;
  margin: 2px 0 4px;
  padding: 0;
}

.nav-sub .nav-link {
  padding-left: 38px;
  gap: 8px;
  font-size: calc(var(--font-sidebar, 13px) - 1px);
}

.nav-dot {
  width: 4px;
  height: 4px;
  flex: 0 0 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: .45;
}

/* 「我的链接」置顶, 与下方公共分类隔开 */
.nav-mine {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--sidebar-line);
}

.nav-mine .nav-link {
  font-weight: 600;
  color: #FAFAFA;
}

/* ---------- 侧栏收起态: 只留图标 ---------- */
body.nav-collapsed .sidebar { width: var(--sidebar-collapsed-w, 60px); }

/* 注意 .user-meta 只隐藏 header 触发器里的那份:
   下拉面板里也用了同样的类名, 一并隐藏会让菜单里的用户名消失 */
body.nav-collapsed .nav-text,
body.nav-collapsed .nav-arrow,
body.nav-collapsed .nav-sub,
body.nav-collapsed .brand-text,
body.nav-collapsed .user-trigger .user-meta,
body.nav-collapsed .caret { display: none; }

body.nav-collapsed .brand-logo { max-width: 34px; }

body.nav-collapsed .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* 收起后按钮箭头掉头, 提示"点这里展开" */
body.nav-collapsed .brand-collapse svg { transform: rotate(180deg); }

/* 右侧主区: 让出左侧固定菜单的宽度 */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .2s ease;
}

body.nav-collapsed .main-wrap { margin-left: var(--sidebar-collapsed-w, 60px); }

/* 内容区撑开, 把页脚顶到页面底部 */
.content { flex: 1; }

.content {
  /* width:100% 不能省: .main-wrap 是 flex 容器, 而 flex item 一旦在交叉轴上
     有 auto 外边距(margin:0 auto), align-items:stretch 就会失效, 宽度退化成
     fit-content —— 内容区会缩到卡片内容的宽度, 网格只剩两列。必须显式撑满。 */
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px;
  min-width: 0;
}

/* ============================ 分组与卡片 ============================ */
.group {
  margin-bottom: 24px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--font-group, 15px);
  font-weight: 600;
  color: var(--text-primary);
  padding: 6px 0 12px;
}

.group-title::before {
  content: "";
  width: 3px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

.group-sub {
  font-size: var(--font-sub, 13px);
  font-weight: 500;
  color: var(--text-secondary);
  margin: 12px 0 8px;
  padding-left: 2px;
}

/* 卡片网格: 列宽由后台「卡片列宽」配置注入 --card-min-w。
   基准值取得比较小(200px), 因为侧栏+内边距会吃掉不少宽度,
   基准稍大一点就会在常见窗口宽度下整整掉一列, 右侧空出一大片。 */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-w, 200px), 1fr));
  gap: 12px;
}

[data-density="compact"] .card-grid {
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--card-min-w, 200px) - 40px), 1fr));
  gap: 8px;
}

/* 点击左侧菜单锚点跳转时, 顶部 sticky header 会盖住标题, 故给目标预留偏移。
   只在这里加一次: 若同时在 html 上加 scroll-padding-top, 两者会叠加成双倍空白。
   偏移量必须与 app.js 里判断高亮的阈值保持一致, 否则会高亮到上一个分类。 */
.group,
.sub-group {
  scroll-margin-top: calc(var(--header-h) + var(--scroll-gap, 8px));
}

.card {
  position: relative; /* 供 .card-tip 定位 */
  z-index: 1; /* 悬浮置顶前的基础层级 */
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px 8px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 5px;
  box-shadow: var(--shadow-base);
  transition: border-color .2s, box-shadow .2s, transform .2s;
  min-width: 0;
}

.card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 14px rgba(16, 24, 40, .10);
  transform: translateY(-2px);
}

.card .icon,
.card .icon-text {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card .icon {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  background: var(--primary-light);
  padding: 6px;
}

.card .icon-text {
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.card-body { min-width: 0; flex: 1; }

.card-title {
  font-size: var(--font-card, 14px);
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 第二行展示完整地址, 超宽用省略号 */
.card-url {
  display: block;
  font-size: var(--font-url, 11px);
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 悬浮提示: 有描述显示描述, 无描述显示完整地址。
   用 pre-wrap 保证内容较多时按块换行, 而不是挤成一行 */
.card-tip {
  display: none;
  position: absolute;
  left: 8px;
  top: calc(100% + 6px);
  z-index: 300;
  max-width: 320px;
  padding: 8px 10px;
  background: rgba(48, 49, 51, .96);
  color: #fff;
  font-size: 12px;
  line-height: 1.7;
  border-radius: var(--radius);
  box-shadow: var(--shadow-base);
  white-space: pre-wrap;
  word-break: break-word;
  text-align: left;
  pointer-events: none;
}

/* 悬浮时把整张卡片抬到同层之上, 否则悬浮块会被下一行的卡片盖住 */
.card:hover,
.card:focus-visible {
  z-index: 30;
  border-color: var(--primary);
}

.card:hover .card-tip { display: block; }

/* ============================ 后台: 拖拽排序 ============================ */
.sort-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sort-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-lighter);
  background: var(--bg);
}

.sort-item:last-child { border-bottom: none; }
.sort-item:hover { background: var(--bg-hover); }
.sort-item.dragging { opacity: .4; background: var(--primary-light); }

/* 子级缩进, 体现层级 */
.sort-item.level-1 { padding-left: 34px; }
.sort-item.level-1 .sort-name::before {
  content: "└ ";
  color: var(--text-secondary);
}

.drag-handle {
  flex: 0 0 auto;
  width: 18px;
  text-align: center;
  color: var(--text-secondary);
  cursor: grab;
  user-select: none;
  font-size: 13px;
  line-height: 1;
}

.drag-handle:active { cursor: grabbing; }

.sort-item .sort-main { flex: 1; min-width: 0; }
.sort-tag { font-size: 12px; }

.sort-hint {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 0 0;
}

.empty {
  padding: 40px;
  text-align: center;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius);
}

/* ============================ 后台 ============================ */
.admin-layout {
  display: flex;
  align-items: flex-start;
  gap: 0;
  min-height: calc(100vh - var(--header-h));
}

.admin-nav {
  width: 180px;
  flex: 0 0 180px;
  background: var(--bg);
  border-right: 1px solid var(--border-light);
  padding: 16px 8px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.admin-nav a {
  display: block;
  padding: 9px 14px;
  border-radius: var(--radius);
  color: var(--text-regular);
  font-size: 13px;
  margin-bottom: 2px;
}

.admin-nav a:hover { background: var(--bg-hover); color: var(--primary); }

.admin-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.admin-main {
  flex: 1;
  padding: 20px 24px;
  min-width: 0;
  background: var(--bg-page);
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 16px;
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-lighter);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-body { padding: 16px; }

/* 统计卡片 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px;
}

.stat .num {
  font-size: 26px;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.2;
}

.stat .label { font-size: 12px; color: var(--text-secondary); }

/* 表格 */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-lighter);
  vertical-align: middle;
}

th {
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--bg-page);
  white-space: nowrap;
}

tbody tr:hover { background: var(--bg-hover); }

td .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* 表单 */
.form-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

label { font-size: 13px; color: var(--text-regular); }

input[type="text"], input[type="password"], input[type="number"],
input[type="url"], input[type="search"], select, textarea {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-base);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-regular);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .2s;
}

textarea {
  height: auto;
  padding: 8px 10px;
  line-height: 1.5;
  resize: vertical;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 500; color: var(--text-primary); }
.field .hint { font-size: 12px; color: var(--text-secondary); }

/* 输入 + 行内小按钮(如密码框旁的「生成 / 显示」) */
.field-row { display: flex; align-items: center; gap: 8px; }
.field-row input { flex: 1; min-width: 0; }
.field-row .btn { flex: 0 0 auto; }

/* 提示条 */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}

.alert-error   { background: #fef0f0; color: #f56c6c; border: 1px solid #fde2e2; }
.alert-success { background: #f0f9eb; color: #67c23a; border: 1px solid #e1f3d8; }
.alert-info    { background: var(--primary-light); color: var(--primary); border: 1px solid #d9ecff; }

[data-theme="dark"] .alert-error   { background: #2b1d1d; border-color: #423; }
[data-theme="dark"] .alert-success { background: #1d2b1a; border-color: #243; }
[data-theme="dark"] .alert-info    { background: #18222c; border-color: #234; }

/* 角色标签 */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 12px;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #d9ecff;
  margin-right: 4px;
}

.tag-muted {
  background: var(--bg-page);
  color: var(--text-secondary);
  border-color: var(--border-light);
}

/* 登录 */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
}

.login-box {
  width: 340px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  box-shadow: var(--shadow-light);
  padding: 28px;
}

.login-box h2 {
  margin: 0 0 20px;
  font-size: 18px;
  color: var(--text-primary);
  text-align: center;
}

.login-box input { width: 100%; }
.login-box .field { margin-bottom: 16px; }
.login-box .btn { width: 100%; }

/* ============================ 后台: 列表页(工具栏 / 弹窗 / 批量) ============================ */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.page-head .page-title { margin: 0; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-lighter);
}

.toolbar-left { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar-count { font-size: 12px; color: var(--text-secondary); }

.bulk-tip {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-lighter);
  background: var(--bg-page);
}

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 14px;
  font-size: 13px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border-lighter);
}

.table-wrap { overflow-x: auto; }

/* 表格行内的内容单元 */
.cell-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cell-main.indent { padding-left: 16px; }
.cell-main.indent::before { content: "└"; color: var(--text-secondary); }
.cell-title {
  display: block;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-sub {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-icon { width: 16px; height: 16px; flex: 0 0 auto; color: var(--text-secondary); }
.cell-url {
  display: inline-block;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.muted { color: var(--text-secondary); }

/* 拖拽 */
tbody tr.dragging { opacity: .45; background: var(--primary-light); }
td .drag-handle { display: inline-block; }
.drag-handle.locked { cursor: not-allowed; color: var(--text-placeholder); }

/* 弹窗 */
.modal {
  width: min(560px, 94vw);
  padding: 0;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  color: var(--text-primary);
  box-shadow: var(--shadow-light);
}

.modal::backdrop { background: rgba(9, 9, 11, .45); }

.modal > form {
  display: flex;
  flex-direction: column;
  max-height: 86vh;
}

.modal-head {
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-lighter);
}

.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-body .field:last-child { margin-bottom: 0; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-lighter);
  background: var(--bg-page);
  border-radius: 0 0 12px 12px;
}

.confirm-text { margin: 0; font-size: 13px; color: var(--text-regular); line-height: 1.6; }

/* 弹窗内的图标选择与角色多选 */
.icon-field { display: flex; align-items: center; gap: 10px; }
.icon-preview { width: 22px; height: 22px; flex: 0 0 auto; color: var(--text-secondary); }

.check-list { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-regular);
  cursor: pointer;
}
.check input { width: 14px; height: 14px; margin: 0; }

/* 响应式 */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .admin-nav { display: none; }
  .layout, .admin-main { padding: 12px; }
  .search-box { width: 160px; }
}

/* 中等宽度窗口(笔记本 / 带缩放): 收紧内边距, 并把列宽再压一档,
   保证一行至少能放下 3 个卡片。用 min() 取"配置值"与"180px"里更小的那个,
   这样手动调大的配置不会被这条规则反向拉宽。 */
@media (max-width: 1200px) {
  .content { padding: 20px 16px; }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(var(--card-min-w, 200px), 180px), 1fr));
  }

  /* 侧栏也收窄一档, 把宽度让给内容区。
     用 min() 而不是直接改 --sidebar-w: 那个变量由后台注入在内联 <style> 里,
     优先级高于本文件的 :root, 在这里重定义无效; min() 则能同时尊重后台配置
     (配得比 200 小就保持用户的值)。 */
  .sidebar   { width: min(var(--sidebar-w, 240px), 200px); }
  .main-wrap { margin-left: min(var(--sidebar-w, 240px), 200px); }
}
