* { box-sizing: border-box; }
:root {
  --bg: #0b0e14;
  --panel-rgb: 21, 26, 38;
  --card-rgb: 20, 26, 37;
  --panel: rgba(var(--panel-rgb), calc(.82 * var(--ui-alpha, 1)));
  --card: rgba(var(--card-rgb), var(--ui-alpha, 1));
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #eaf0f8;
  --muted: #8d9aab;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --gradient: linear-gradient(135deg, #6366f1, #22d3ee);
  --danger: #f87171;
  --radius: 14px;
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  /* 外观设置（JS 动态覆盖） */
  --bg-image: none;
  --bg-blur: 0px;
  --bg-dim: 0;
  --ui-alpha: 1;
}
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(99, 102, 241, .16), transparent 60%),
    radial-gradient(800px 420px at 92% -4%, rgba(34, 211, 238, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.65 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
/* 自定义背景图层（外观设置），暗化层叠其上 */
body::before {
  content: ""; position: fixed; inset: -40px; z-index: -2;
  background-image: var(--bg-image);
  background-size: cover; background-position: center;
  filter: blur(var(--bg-blur));
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1;
  background: #05070c; opacity: var(--bg-dim);
}
.hidden { display: none !important; }
::selection { background: rgba(99, 102, 241, .4); }
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .12); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .2); }

/* ---- 登录 / 初始化 ---- */
.screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.panel {
  width: 100%; max-width: 440px;
  background: var(--panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px 32px;
  box-shadow: var(--shadow-lg);
  animation: rise .35s ease both;
}
.panel h1 { margin: 0 0 10px; font-size: 21px; letter-spacing: .2px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.hint b { color: var(--text); font-weight: 600; }
.err { color: var(--danger); font-size: 13px; min-height: 20px; margin: 12px 0 0; }

input, select {
  width: 100%;
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 14px;
  margin-top: 4px;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
input::placeholder { color: #5c6b7e; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, .06);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .18);
}
select option { background: #141a25; color: var(--text); }

.btn {
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all .18s ease;
}
.btn:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, .09);
  transform: translateY(-1px);
}
.btn:disabled { opacity: .5; cursor: wait; transform: none; }
.btn.primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border: 1px solid transparent;
  color: #fff; font-weight: 600;
  box-shadow: 0 4px 18px rgba(99, 102, 241, .35);
}
.btn.primary:hover {
  box-shadow: 0 6px 24px rgba(99, 102, 241, .5);
  background: linear-gradient(135deg, #6d70f4, #5b54f0);
}
.btn.danger { background: transparent; border-color: rgba(248, 113, 113, .35); color: var(--danger); }
.btn.danger:hover { background: rgba(248, 113, 113, .1); border-color: var(--danger); transform: translateY(-1px); }
.panel .btn { width: 100%; margin-top: 16px; padding: 11px; }

/* ---- 顶栏 ---- */
#app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 12px; align-items: center;
  padding: 14px 24px;
  background: rgba(11, 14, 20, calc(.72 * var(--ui-alpha, 1)));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.logo {
  font-weight: 800; font-size: 17px; white-space: nowrap; letter-spacing: .3px;
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.logo-icon { width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0; }
#search { margin: 0; max-width: 340px; border-radius: 999px; }
#lock-btn { margin-left: auto; border-radius: 999px; }
#menu { position: relative; }
#menu summary { list-style: none; border-radius: 999px; }
#menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: flex; flex-direction: column; min-width: 176px;
  box-shadow: var(--shadow-lg);
  animation: rise .18s ease both;
}
.menu-list button {
  background: none; border: none; color: var(--text); text-align: left;
  padding: 9px 14px; border-radius: 9px; font-size: 14px; cursor: pointer;
  transition: background .15s ease;
}
.menu-list button:hover { background: rgba(255, 255, 255, .07); }

/* ---- 分组与卡片 ---- */
#screen-app { max-width: 1200px; margin: 0 auto; padding: 26px 22px 60px; }
.group { margin-bottom: 32px; }
.group-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.group-head h2 {
  font-size: 16px; margin: 0; letter-spacing: .3px;
  display: flex; align-items: center;
}
.group-head h2::before {
  content: ""; width: 4px; height: 16px; border-radius: 2px;
  background: var(--gradient); margin-right: 10px;
}
.count { color: var(--muted); font-size: 12px; background: rgba(255, 255, 255, .06); border-radius: 999px; padding: 1px 9px; }
.icon {
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  padding: 3px 9px;
  border-radius: 8px;
  transition: all .15s ease;
}
.icon:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, .13);
  transform: translateY(-1px);
}
.icon[data-add-site] {
  color: var(--accent-2);
  border-color: rgba(34, 211, 238, .4);
  background: rgba(34, 211, 238, .08);
  font-weight: 700;
}
.icon[data-add-site]:hover {
  color: #fff;
  background: rgba(99, 102, 241, .25);
  border-color: var(--accent);
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }

.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), transparent 40%), var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation: rise .3s ease both;
}
.card:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, .55);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .4), 0 0 0 1px rgba(99, 102, 241, .12);
}
.card-top { display: flex; align-items: center; gap: 10px; }
.favicon {
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 8px; object-fit: contain;
  background: rgba(255, 255, 255, .07);
  padding: 2px;
}
.avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; font-weight: 700; font-size: 15px; color: #fff;
}
.hue-0 { background: #6366f1; } .hue-1 { background: #06b6d4; }
.hue-2 { background: #10b981; } .hue-3 { background: #f59e0b; }
.hue-4 { background: #f43f5e; } .hue-5 { background: #8b5cf6; }
.hue-6 { background: #3b82f6; } .hue-7 { background: #14b8a6; }
.hue-8 { background: #f97316; } .hue-9 { background: #ec4899; }
.hue-10 { background: #84cc16; } .hue-11 { background: #0ea5e9; }
.card-name { font-weight: 600; letter-spacing: .2px; }
.card-host {
  color: var(--muted); font-size: 12px; margin-left: auto; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-note { color: var(--muted); font-size: 13px; margin-top: 5px; word-break: break-all; }
.card-fields { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

.chip {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: all .15s ease;
}
.chip:hover {
  border-color: rgba(99, 102, 241, .6);
  background: rgba(99, 102, 241, .14);
  color: #fff;
}
.chip.edit { opacity: .65; }
.chip.edit:hover { opacity: 1; }
.chip.static { cursor: default; }
.chip.static:hover { border-color: var(--border); background: rgba(255, 255, 255, .05); color: var(--text); }

/* ---- 折叠 / 平铺视图 ---- */
.chevron { width: 28px; text-align: center; padding: 3px 0; font-size: 13px; }
.group-head h2[data-toggle-group] { cursor: pointer; }
.cards.flat { margin-top: 4px; }

/* ---- 外观设置 ---- */
#ap-modal label span { color: var(--accent-2); font-weight: 600; }
input[type="range"] {
  accent-color: var(--accent);
  padding: 0; margin-top: 8px; height: 22px;
  background: transparent; border: none;
}
input[type="range"]:focus { box-shadow: none; }

.empty-tip {
  color: var(--muted); font-size: 13px; padding: 14px 4px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  text-align: center;
}

/* ---- 拖拽排序 ---- */
.group-head { cursor: grab; }
.group-head:active { cursor: grabbing; }
.card.dragging, .group-head.dragging { opacity: .35; }
.card.drop-before { box-shadow: 0 -3px 0 0 var(--accent-2), 0 12px 32px rgba(0, 0, 0, .4); }
.card.drop-after { box-shadow: 0 3px 0 0 var(--accent-2), 0 12px 32px rgba(0, 0, 0, .4); }
.cards.drop-in { outline: 2px dashed rgba(34, 211, 238, .55); outline-offset: 5px; border-radius: var(--radius); }
.group.drop-before { box-shadow: inset 0 3px 0 0 var(--accent-2); }
.group.drop-after { box-shadow: inset 0 -3px 0 0 var(--accent-2); }

/* ---- 弹窗 ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 8, 14, .6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 20; padding: 16px;
}
.modal-box {
  background: var(--panel);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px;
  width: 100%; max-width: 460px; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: rise .22s ease both;
}
.modal-box h3 { margin: 0 0 16px; font-size: 17px; }
.modal-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 11px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.modal-actions #modal-del { margin-right: auto; }

/* ---- 提示条 ---- */
.toast {
  position: fixed; left: 50%; bottom: 30px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(var(--panel-rgb), calc(.9 * var(--ui-alpha, 1)));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 20px; border-radius: 999px;
  font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: all .25s ease; z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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