:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --border: #e4e8f2;
  --text: #1c2333;
  --muted: #6f7789;
  --accent: #4f7cff;
  --accent-hover: #3f6cf0;
  --accent-soft: #eaf0ff;
  --ok: #1d9d66;
  --ok-soft: #e6f6ee;
  --warn: #dd8500;
  --warn-soft: #fdf2df;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --input-bg: #ffffff;
  --hover: #eef1f8;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.05);
  --shadow-lg: 0 12px 40px rgba(16,24,40,.18);
  --sidebar-from: #22304f;
  --sidebar-to: #141f36;
}
[data-theme="dark"] {
  --bg: #11141c;
  --card: #1a1e2a;
  --border: #2a2f42;
  --text: #e9ebf4;
  --muted: #98a0b5;
  --accent: #6b8dff;
  --accent-hover: #85a2ff;
  --accent-soft: #232c47;
  --ok: #3ecf8e;
  --ok-soft: #173327;
  --warn: #f5b14c;
  --warn-soft: #3a2c14;
  --danger: #ff6b6f;
  --danger-soft: #3d1e21;
  --input-bg: #141824;
  --hover: #222839;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.5);
  --sidebar-from: #1a2338;
  --sidebar-to: #0e1424;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  user-select: none;
}
input, textarea, select { user-select: text; font-family: inherit; }
button { font-family: inherit; cursor: pointer; }
svg { flex: none; }

#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 216px; flex: none;
  background: linear-gradient(180deg, var(--sidebar-from), var(--sidebar-to));
  color: #dbe2f2;
  display: flex; flex-direction: column;
  padding: 20px 14px 16px;
}
.logo { display: flex; align-items: center; gap: 11px; padding: 2px 8px 20px; }
.logo-badge {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(135deg, #5b8cff, #7c5cff);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(91,140,255,.45);
}
.logo-badge svg { width: 20px; height: 20px; }
.logo-name { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: .5px; }
.logo-sub { font-size: 11px; color: #8fa0c2; margin-top: 1px; }

#nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border: none; border-radius: 10px;
  background: transparent; color: #b9c4dd; font-size: 14px;
  text-align: left; transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(91,140,255,.35), rgba(124,92,255,.25)); color: #fff; font-weight: 600; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 19px; height: 19px;
  border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.nav-badge.hidden { display: none; }

.sidebar-foot { margin-top: auto; }
.theme-btn {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.05); color: #cdd7ec; font-size: 13px;
  transition: background .15s;
}
.theme-btn:hover { background: rgba(255,255,255,.11); }
.theme-btn svg { width: 17px; height: 17px; }
.foot-note { font-size: 11px; color: #71809f; text-align: center; margin-top: 12px; }

/* ---------- main ---------- */
#main { flex: 1; overflow-y: auto; }
#view { max-width: 960px; margin: 0 auto; padding: 26px 28px 40px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.view-title { font-size: 21px; font-weight: 700; }
.view-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.head-spacer { flex: 1; }

.search-box { position: relative; width: 240px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-box input { padding-left: 32px !important; }

/* ---------- controls ---------- */
input[type="text"], input[type="password"], input[type="date"], input[type="number"], textarea, select {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--input-bg); color: var(--text); font-size: 14px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.55; }
label.f-label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.f-group { margin-bottom: 14px; }
.f-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.f-hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.5; }
.f-hint a { color: var(--accent); text-decoration: none; cursor: pointer; }
.f-hint a:hover { text-decoration: underline; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 14px; font-weight: 500;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #d13a3f; }
.btn-ghost-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-ghost-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: .55; cursor: default; transform: none; }

/* switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 12px;
  background: var(--border); transition: background .2s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  left: 3px; top: 3px; background: #fff; transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.switch-row .sw-text { flex: 1; }
.switch-row .sw-title { font-weight: 500; }
.switch-row .sw-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- cards & lists ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.section-card { padding: 20px 22px; margin-bottom: 16px; }
.section-title { display: flex; align-items: center; gap: 9px; font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.section-title svg { width: 18px; height: 18px; color: var(--accent); }
.section-desc { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.6; }

.memo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.memo-card { padding: 16px 17px 12px; cursor: pointer; transition: transform .12s, box-shadow .12s; display: flex; flex-direction: column; }
.memo-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.memo-title { font-weight: 600; font-size: 15px; margin-bottom: 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.memo-snippet {
  color: var(--muted); font-size: 13px; line-height: 1.6; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-wrap; word-break: break-word;
}
.memo-foot { display: flex; align-items: center; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.memo-time { font-size: 12px; color: var(--muted); }
.memo-actions { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.memo-card:hover .memo-actions { opacity: 1; }

.cred-card { display: flex; gap: 15px; padding: 16px 18px; margin-bottom: 12px; align-items: flex-start; }
.avatar {
  width: 44px; height: 44px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 700;
}
.cred-main { flex: 1; min-width: 0; }
.cred-site { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.cred-url { font-size: 12px; color: var(--accent); cursor: pointer; display: inline-flex; align-items: center; gap: 3px; }
.cred-url:hover { text-decoration: underline; }
.cred-url svg { width: 11px; height: 11px; }
.cred-line { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: 13px; }
.cred-line .k { color: var(--muted); width: 34px; flex: none; }
.cred-line .v { font-family: Consolas, "Courier New", monospace; word-break: break-all; }
.cred-notes { font-size: 12.5px; color: var(--muted); margin-top: 8px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.cred-actions { display: flex; gap: 2px; flex: none; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card { padding: 16px 18px; }
.stat-num { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat-card.warn .stat-num { color: var(--warn); }
.stat-card.danger .stat-num { color: var(--danger); }

.sub-card { display: flex; padding: 0; overflow: hidden; margin-bottom: 12px; }
.sub-bar { width: 5px; flex: none; }
.sub-bar.ok { background: var(--ok); }
.sub-bar.warn { background: var(--warn); }
.sub-bar.danger { background: var(--danger); }
.sub-body { flex: 1; padding: 15px 18px; min-width: 0; }
.sub-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sub-name { font-weight: 600; font-size: 15px; }
.sub-meta { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }
.sub-meta b { color: var(--text); font-weight: 500; }
.sub-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.sub-notes { font-size: 12.5px; color: var(--muted); margin-top: 8px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.sub-actions { display: flex; gap: 2px; align-items: flex-start; padding: 12px 12px 0 0; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px;
  border-radius: 20px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.plain { background: var(--accent-soft); color: var(--accent); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
  border-radius: 20px; font-size: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); cursor: pointer; transition: all .13s;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip.static { cursor: default; }
.chip .chip-x { font-weight: 700; opacity: .7; }
.chip .chip-x:hover { opacity: 1; }

.empty-state { text-align: center; padding: 56px 20px; }
.empty-state .es-icon {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.empty-state .es-icon svg { width: 32px; height: 32px; }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; }
.empty-state p { color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.6; }

/* lock screen */
.lock-wrap { display: flex; justify-content: center; padding-top: 40px; }
.lock-card { width: 420px; max-width: 100%; padding: 34px 34px 28px; text-align: center; }
.lock-icon {
  width: 68px; height: 68px; margin: 0 auto 16px; border-radius: 50%;
  background: linear-gradient(135deg, #5b8cff, #7c5cff); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(91,140,255,.4);
}
.lock-icon svg { width: 30px; height: 30px; }
.lock-card h2 { font-size: 19px; margin-bottom: 8px; }
.lock-card .lock-desc { color: var(--muted); font-size: 13px; line-height: 1.65; margin-bottom: 20px; }
.lock-card .f-group { text-align: left; }
.lock-warn {
  background: var(--warn-soft); color: var(--warn); border-radius: 10px;
  padding: 10px 13px; font-size: 12.5px; line-height: 1.6; text-align: left; margin-bottom: 16px;
}
.shake { animation: shake .35s; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,14,24,.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: 540px; max-width: calc(100vw - 40px); max-height: calc(100vh - 60px);
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; animation: popIn .16s;
}
@keyframes popIn { from { transform: scale(.96) translateY(6px); opacity: 0 } to { transform: none; opacity: 1 } }
.modal-head { display: flex; align-items: center; padding: 18px 22px 0; }
.modal-title { font-size: 16.5px; font-weight: 700; flex: 1; }
.modal-body { padding: 16px 22px 6px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px 20px; }
.modal-foot .spacer { flex: 1; }

/* ---------- toast ---------- */
#toast-root { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: 11px;
  padding: 11px 16px; font-size: 13.5px; box-shadow: var(--shadow-lg);
  max-width: 360px; line-height: 1.55; animation: toastIn .2s; white-space: pre-wrap;
}
.toast.success { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes toastIn { from { transform: translateX(16px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.out { opacity: 0; transform: translateX(16px); transition: all .25s; }

.result-text { font-size: 13px; margin-top: 10px; line-height: 1.6; white-space: pre-wrap; }
.result-text.ok { color: var(--ok); }
.result-text.err { color: var(--danger); }
.save-bar {
  position: sticky; bottom: 0; padding: 14px 0 4px;
  background: linear-gradient(transparent, var(--bg) 35%);
  display: flex; justify-content: flex-end;
}
.mono { font-family: Consolas, "Courier New", monospace; }
.hidden { display: none !important; }
