/* ===== 个人导航 · 样式 ===== */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e6e8ec;
  --line-2: #d5d8de;
  --text: #1f2328;
  --muted: #6b7280;
  --muted-2: #9aa1ab;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --primary-soft: #eef3ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

/* 关键：.lock / .app 使用 flex 布局，会覆盖 hidden 属性的默认 display:none */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: 14px; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }

/* ---------- 通用按钮 ---------- */
.btn {
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--text);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #b9bec7; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); border-color: var(--primary-d); }
.btn.danger { color: var(--danger); border-color: #f0c2c2; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-style: dashed; color: var(--muted); }
.btn.ghost:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.block { display: block; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 解锁层 ---------- */
.lock {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #f0f3f8, #e9edf4);
  padding: 20px;
}
.lock-card {
  width: 100%; max-width: 360px;
  background: #fff; border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 30px 28px 22px;
  text-align: center;
}
.lock-logo {
  width: 48px; height: 48px; margin: 0 auto 14px;
  border-radius: 13px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600;
}
.lock-card h1 { font-size: 17px; font-weight: 600; margin: 0 0 6px; }
.lock-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 18px; }
.lock-card input {
  width: 100%; padding: 11px 13px; margin-bottom: 10px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--panel-2); outline: none;
}
.lock-card input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.lock-err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-bottom: 4px; }
.lock-tip { font-size: 11.5px; color: var(--muted-2); margin: 14px 0 0; line-height: 1.6; }

/* ---------- 主布局 ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 216px; flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px 16px; font-weight: 600; }
.brand .logo {
  width: 26px; height: 26px; border-radius: 7px; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.groups { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.group-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text); border: none; background: transparent; text-align: left; width: 100%;
}
.group-item:hover { background: var(--panel-2); }
.group-item.active { background: var(--primary-soft); color: var(--primary-d); font-weight: 500; }
.group-item .gname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-item .gcount { font-size: 11.5px; color: var(--muted-2); flex: 0 0 auto; }
.group-del { font-size: 12px; color: var(--muted-2); border: none; background: none; padding: 0 2px; visibility: hidden; }
.group-item:hover .group-del { visibility: visible; }
.group-item:hover .gcount { display: none; }
.group-del:hover { color: var(--danger); }

/* ---------- 两级分组树 ---------- */
.group-item.level2 { padding-left: 26px; }
.group-item.level2 .gname { color: var(--muted); }
.group-item.level2.active .gname { color: var(--primary-d); }
.gfold {
  flex: 0 0 14px; text-align: center; cursor: pointer;
  color: var(--muted-2); font-size: 11px; transition: transform .15s;
  display: inline-block; user-select: none;
}
.gfold.collapsed { transform: rotate(-90deg); }
.gfold:hover { color: var(--primary); }
.gindent { flex: 0 0 14px; display: inline-block; }

/* ---------- 拖拽排序 / 行内改名 ---------- */
.group-item[data-gid] { cursor: grab; }
.group-item[data-gid].dragging { opacity: .4; cursor: grabbing; }
.group-item.fixed { cursor: pointer; }
/* 固定在最下方的「未分组」，与上方真实分组用分隔线区分 */
.group-item.fixed-bottom { margin-top: 10px; border-top: 1px solid var(--line); }
.gname-input {
  flex: 1 1 auto; min-width: 0; margin-right: 4px;
  padding: 2px 6px; font-size: 13.5px;
  border: 1px solid var(--primary); border-radius: 5px;
  background: #fff; outline: none;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.search {
  flex: 1; min-width: 180px; padding: 9px 13px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--panel-2); outline: none;
}
.search:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { flex: 1; overflow-y: auto; padding: 20px; }
.sec-title { font-size: 13px; color: var(--muted); margin: 0 0 12px; font-weight: 500; }
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  transition: .15s; display: flex; flex-direction: column; gap: 12px;
  cursor: grab;
}
.card.dragging { opacity: .4; cursor: grabbing; }
.card.dragging:hover { transform: none; box-shadow: none; }
.card:hover { border-color: var(--line-2); box-shadow: var(--shadow); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.favicon {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 600; overflow: hidden;
}
.favicon img { width: 100%; height: 100%; object-fit: cover; }
.card-title { min-width: 0; }
.card-title .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title .host { font-size: 12px; color: var(--muted-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-user { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-height: 18px; }
.card-user .u { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: 11.5px;
  background: var(--primary-soft); color: var(--primary-d); margin-right: 4px;
}
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card-actions .btn { padding: 4px 9px; font-size: 12.5px; }
.pwd-view {
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
  background: var(--panel-2); border: 1px dashed var(--line-2);
  border-radius: 6px; padding: 5px 8px; word-break: break-all;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.empty { text-align: center; color: var(--muted-2); padding: 60px 20px; font-size: 13.5px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 200; background: rgba(17, 24, 39, .38);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 460px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(16, 24, 40, .2);
  padding: 20px 22px;
}
.modal.wide { max-width: 620px; }
.modal h2 { font-size: 15.5px; font-weight: 600; margin: 0 0 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--panel-2); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; min-height: 58px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); margin-bottom: 8px; }
.check input { width: auto; }
.hint { font-size: 12px; color: var(--muted-2); line-height: 1.6; margin: 6px 0 0; }
.gen-out {
  font-family: ui-monospace, Consolas, monospace; font-size: 15px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  padding: 12px; word-break: break-all; text-align: center; margin-bottom: 12px;
  min-height: 44px; display: flex; align-items: center; justify-content: center;
}
input[type=range] { width: 100%; padding: 0; }

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(12px);
  background: #1f2328; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; z-index: 300; opacity: 0; transition: .22s; pointer-events: none;
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 左侧标签区 ---------- */
.sidebar { overflow-y: auto; }
.groups { flex: 0 0 auto; overflow: visible; margin-bottom: 10px; }

.side-title { font-size: 12px; color: var(--muted); margin: 0 0 8px; font-weight: 500; }
.tag-panel { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px; font-size: 12px;
  border: 1px solid var(--line-2); background: #fff; color: var(--text);
  transition: .15s; line-height: 1.5;
}
.tag-chip:hover { border-color: var(--primary); color: var(--primary-d); }
.tag-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag-chip.active .tag-n { color: rgba(255, 255, 255, .78); }
.tag-chip.clear { border-style: dashed; color: var(--muted); }
.tag-n { font-size: 11px; color: var(--muted-2); }
.tag-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hint.tiny { font-size: 11.5px; margin: 6px 0 0; }

/* ---------- 批量操作条 ---------- */
.batch-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: var(--primary-soft);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.batch-bar #batchCount { font-size: 13px; font-weight: 500; color: var(--primary-d); }
.batch-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 卡片批量选择态 ---------- */
.card.picking { cursor: pointer; padding-left: 40px; position: relative; }
.card.picking:hover { transform: none; }
.card.picked { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.card-cb {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary);
}

/* ---------- 账号区（卡片上，一个站点多个账号） ---------- */
.cred-list { display: flex; flex-direction: column; gap: 4px; }
.cred-item { border-left: 2px solid var(--line-2); padding-left: 8px; }
.cred-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; min-height: 20px; }
.cred-label {
  flex: 0 0 auto; padding: 1px 6px; border-radius: 4px; font-size: 11px;
  background: var(--primary-soft); color: var(--primary-d);
}
.cred-user { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cred-btns { display: flex; gap: 4px; flex: 0 0 auto; }
.cred-btns .btn { padding: 1px 7px; font-size: 11.5px; }

/* ---------- 编辑器里的账号行 ---------- */
.cred-editor { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.cred-edit-row {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px; background: var(--panel-2);
  display: flex; flex-direction: column; gap: 6px;
}
.cred-edit-row input {
  padding: 7px 9px; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: #fff; outline: none;
}
.cred-edit-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.cred-edit-row .ci-label { flex: 0 0 96px; }
.cred-edit-row .ci-user { flex: 1; min-width: 0; }
.cred-edit-row .ci-pwd { flex: 1; min-width: 0; }
.cred-edit-row .inline { display: flex; gap: 6px; align-items: center; }
.cred-edit-row .inline input { min-width: 0; }

/* ---------- 窄屏 ---------- */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: 0 0 auto; border-right: none; border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }
  .brand { padding-bottom: 8px; }
  .groups { flex-direction: row; overflow-x: auto; margin-bottom: 8px; }
  .group-item { width: auto; white-space: nowrap; }
  .group-del { display: none; }
  .topbar { padding: 10px 12px; }
  .content { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
