:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-soft: #0c111c;
  --panel: rgba(16, 22, 35, 0.88);
  --panel-solid: #111827;
  --panel-hover: #151f31;
  --line: rgba(140, 169, 214, 0.14);
  --line-strong: rgba(99, 230, 255, 0.42);
  --text: #eef5ff;
  --muted: #8c9bb3;
  --subtle: #64748b;
  --cyan: #63e6ff;
  --cyan-rgb: 99, 230, 255;
  --violet: #9c7cff;
  --violet-rgb: 156, 124, 255;
  --danger: #ff6685;
  --success: #5ee6a8;
  --shadow: 0 24px 65px rgba(0, 0, 0, 0.34);
  --radius: 14px;
  --topbar: rgba(8, 11, 18, 0.76);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f9;
  --bg-soft: #e8eef7;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --panel-hover: #f8fbff;
  --line: rgba(36, 63, 98, 0.13);
  --line-strong: rgba(0, 148, 185, 0.42);
  --text: #172033;
  --muted: #5e6e84;
  --subtle: #8190a4;
  --cyan: #008eaf;
  --cyan-rgb: 0, 142, 175;
  --violet: #6749d7;
  --violet-rgb: 103, 73, 215;
  --danger: #d83f63;
  --success: #17895d;
  --shadow: 0 22px 60px rgba(46, 67, 96, 0.15);
  --topbar: rgba(238, 243, 249, 0.78);
}

* { box-sizing: border-box; }

html { min-height: 100%; scroll-behavior: smooth; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 220ms ease, color 220ms ease;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.ambient, .grid-texture { position: fixed; pointer-events: none; inset: 0; }
.ambient { filter: blur(1px); opacity: 0.8; }
.ambient-one {
  background: radial-gradient(circle at 18% -8%, rgba(var(--cyan-rgb), 0.13), transparent 34%);
}
.ambient-two {
  background: radial-gradient(circle at 91% 18%, rgba(var(--violet-rgb), 0.11), transparent 29%);
}
.grid-texture {
  opacity: 0.32;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 58px 58px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

.topbar {
  position: sticky;
  z-index: 30;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(18px) saturate(135%);
}

.topbar-inner {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(300px, 720px) minmax(180px, 1fr);
  align-items: center;
  gap: 24px;
  width: min(1600px, calc(100% - 48px));
  min-height: 76px;
  margin: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 12px;
  max-width: 100%;
  color: var(--text);
  font-size: 18px;
  font-weight: 720;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { position: relative; width: 27px; height: 27px; flex: none; transform: rotate(-6deg); }
.brand-mark i {
  position: absolute;
  display: block;
  width: 14px;
  height: 14px;
  border: 1px solid var(--cyan);
  border-radius: 4px;
  box-shadow: 0 0 14px rgba(var(--cyan-rgb), 0.22);
}
.brand-mark i:nth-child(1) { top: 0; left: 0; }
.brand-mark i:nth-child(2) { top: 4px; right: 0; border-color: var(--violet); }
.brand-mark i:nth-child(3) { left: 5px; bottom: 0; background: linear-gradient(135deg, rgba(var(--cyan-rgb), .65), rgba(var(--violet-rgb), .55)); border: 0; }

.search-shell {
  position: relative;
  display: flex;
  align-items: center;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(var(--cyan-rgb), 0.025);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.search-shell:focus-within {
  border-color: var(--line-strong);
  background: rgba(var(--cyan-rgb), 0.045);
  box-shadow: 0 0 0 3px rgba(var(--cyan-rgb), 0.08), 0 0 28px rgba(var(--cyan-rgb), 0.07);
}
.search-shell svg { width: 18px; margin-left: 15px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search-shell input {
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 42px 0 11px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.search-shell input::placeholder { color: var(--subtle); }
.search-shell kbd {
  position: absolute;
  right: 11px;
  display: grid;
  place-items: center;
  width: 23px;
  height: 23px;
  border: 1px solid var(--line);
  border-bottom-color: rgba(var(--cyan-rgb), .25);
  border-radius: 6px;
  color: var(--subtle);
  background: var(--panel);
  font: 12px/1 ui-monospace, monospace;
}

.top-actions, .toolbar-actions, .modal-actions, .dirty-actions { display: flex; align-items: center; gap: 9px; }
.top-actions { justify-self: end; }

.icon-button, .ghost-button, .primary-button, .danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
}
.icon-button:hover, .ghost-button:hover { border-color: rgba(var(--cyan-rgb), .28); background: var(--panel-hover); }
.icon-button svg, .primary-button svg { width: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.primary-button {
  border-color: rgba(var(--cyan-rgb), .42);
  background: linear-gradient(120deg, rgba(var(--cyan-rgb), .19), rgba(var(--violet-rgb), .18));
  box-shadow: inset 0 0 18px rgba(var(--cyan-rgb), .035);
}
.primary-button:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--cyan); box-shadow: 0 7px 24px rgba(var(--cyan-rgb), .10); }
.primary-button:disabled { cursor: default; opacity: .42; }
.danger-button { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); background: color-mix(in srgb, var(--danger) 8%, var(--panel)); }
.compact { min-height: 39px; }
.wide { width: 100%; min-height: 43px; margin-top: 6px; }

.edit-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1600px, calc(100% - 48px));
  min-height: 52px;
  margin: auto;
  border-top: 1px solid var(--line);
}
.edit-status { display: flex; align-items: center; gap: 9px; color: var(--violet); font-size: 13px; font-weight: 700; letter-spacing: .06em; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 0 5px rgba(var(--violet-rgb), .1), 0 0 14px var(--violet); animation: pulse 2s ease infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px rgba(var(--violet-rgb), .08), 0 0 5px var(--violet); } }

.page-shell { position: relative; z-index: 1; width: min(1600px, calc(100% - 48px)); margin: 0 auto; padding: 30px 0 64px; }
.result-meta { min-height: 20px; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.nav-root { display: flex; flex-direction: column; gap: 28px; }

.group-heading { display: flex; align-items: center; min-height: 36px; margin-bottom: 10px; }
.collapse-button {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 4px 7px 4px 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.group-accent { width: 3px; height: 17px; border-radius: 4px; background: linear-gradient(var(--cyan), var(--violet)); box-shadow: 0 0 12px rgba(var(--cyan-rgb), .26); }
.group-name { max-width: min(520px, 50vw); overflow: hidden; color: var(--text); font-size: 15px; font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.group-count { color: var(--subtle); font: 11px/1 ui-monospace, monospace; }
.chevron { width: 14px; height: 14px; margin-left: 2px; fill: none; stroke: var(--subtle); stroke-width: 2; transition: transform 180ms ease; }
.group.is-folded .chevron { transform: rotate(-90deg); }
.group-actions { display: flex; align-items: center; gap: 5px; margin-left: auto; }
.mini-button {
  display: inline-grid;
  place-items: center;
  min-width: 29px;
  height: 29px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: 140ms ease;
}
.mini-button:hover:not(:disabled) { color: var(--cyan); border-color: var(--line); background: var(--panel); }
.mini-button:disabled { opacity: .25; cursor: default; }
.mini-button.danger:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.mini-button.text { padding: 0 10px; font-size: 12px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.group.is-folded .card-grid { display: none; }
.nav-card {
  position: relative;
  display: flex;
  min-width: 0;
  height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(var(--cyan-rgb), .027), transparent 45%), var(--panel);
  box-shadow: inset 0 1px rgba(255,255,255,.018);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
  overflow: hidden;
}
.nav-card::after { content: ""; position: absolute; inset: auto 20% -1px 20%; height: 1px; opacity: 0; background: linear-gradient(90deg, transparent, var(--cyan), transparent); transition: opacity 160ms ease; }
.nav-card:hover { z-index: 2; transform: translateY(-2px); border-color: rgba(var(--cyan-rgb), .30); background: linear-gradient(145deg, rgba(var(--cyan-rgb), .065), transparent 50%), var(--panel-hover); box-shadow: 0 10px 28px rgba(0,0,0,.13), 0 0 25px rgba(var(--cyan-rgb), .035); }
.nav-card:hover::after { opacity: .7; }
.nav-card.dragging { opacity: .32; }
.nav-card.drop-target { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(var(--cyan-rgb), .12), 0 0 28px rgba(var(--cyan-rgb), .13); }
.card-main { display: flex; align-items: center; gap: 12px; min-width: 0; width: 100%; padding: 12px 14px; color: inherit; text-decoration: none; }
.card-main.no-link { cursor: default; }
.card-icon {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 43px;
  height: 43px;
  border: 1px solid rgba(var(--cyan-rgb), .13);
  border-radius: 11px;
  color: var(--icon-color, var(--cyan));
  background: var(--icon-bg, rgba(var(--cyan-rgb), .075));
  font-size: 18px;
  font-weight: 760;
  letter-spacing: -.04em;
  overflow: hidden;
}
.card-icon img { position: absolute; width: 26px; height: 26px; object-fit: contain; }
.card-icon img.manual { width: 100%; height: 100%; padding: 6px; }
.card-copy { min-width: 0; }
.card-title { overflow: hidden; color: var(--text); font-size: 14px; font-weight: 680; line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.card-title mark { color: var(--cyan); background: transparent; }
.card-secondary { overflow: hidden; margin-top: 4px; color: var(--muted); font-size: 11.5px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.card-controls { position: absolute; z-index: 4; top: 5px; right: 5px; display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-solid); box-shadow: var(--shadow); opacity: 0; transform: translateY(-3px); transition: 140ms ease; }
.nav-card:hover .card-controls, .card-controls:focus-within { opacity: 1; transform: none; }
.card-control { display: grid; place-items: center; width: 25px; height: 25px; padding: 0; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; }
.card-control:hover:not(:disabled) { color: var(--cyan); background: rgba(var(--cyan-rgb), .08); }
.card-control.danger:hover { color: var(--danger); }
.card-control:disabled { opacity: .25; cursor: default; }
.drag-handle { cursor: grab; }
.drag-handle:active { cursor: grabbing; }

.empty-state { display: grid; place-items: center; min-height: 310px; border: 1px dashed var(--line); border-radius: 18px; color: var(--muted); text-align: center; }
.empty-state-symbol { margin-bottom: 13px; color: var(--cyan); font: 28px/1 ui-monospace, monospace; text-shadow: 0 0 18px rgba(var(--cyan-rgb), .35); }
.empty-state h2 { margin: 0 0 7px; color: var(--text); font-size: 17px; }
.empty-state p { margin: 0; font-size: 13px; }
.add-group-button { width: 100%; min-height: 54px; margin-top: 24px; border: 1px dashed rgba(var(--cyan-rgb), .25); border-radius: var(--radius); color: var(--muted); background: rgba(var(--cyan-rgb), .025); cursor: pointer; transition: 150ms ease; }
.add-group-button:hover { color: var(--cyan); border-color: var(--cyan); background: rgba(var(--cyan-rgb), .055); }
.add-group-button span { color: var(--cyan); font-size: 18px; }

.loading-state { display: flex; justify-content: center; gap: 7px; padding: 140px 0; }
.loading-state span { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); animation: loading 900ms ease infinite alternate; }
.loading-state span:nth-child(2) { animation-delay: 160ms; background: color-mix(in srgb, var(--cyan), var(--violet) 50%); }
.loading-state span:nth-child(3) { animation-delay: 320ms; background: var(--violet); }
@keyframes loading { to { opacity: .25; transform: translateY(-6px); } }

.modal {
  width: min(94vw, 470px);
  max-height: 92vh;
  padding: 0;
  border: 0;
  border-radius: 17px;
  color: var(--text);
  background: transparent;
  box-shadow: var(--shadow);
  overflow: visible;
}
#cardDialog { width: min(94vw, 620px); }
.modal:modal { position: fixed; }
.modal::backdrop { background: rgba(2, 5, 11, .67); backdrop-filter: blur(7px); }
.modal-card { position: relative; padding: 30px; border: 1px solid var(--line-strong); border-radius: 17px; background: linear-gradient(145deg, rgba(var(--cyan-rgb), .055), transparent 35%), var(--panel-solid); }
.modal-card-wide { width: min(94vw, 620px); }
.modal-kicker { margin-bottom: 9px; color: var(--cyan); font: 700 10px/1 ui-monospace, monospace; letter-spacing: .16em; }
.modal h2 { margin: 0 32px 8px 0; font-size: 21px; letter-spacing: -.025em; }
.modal p { margin: 0 0 22px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.modal-close { position: absolute; top: 15px; right: 15px; display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: 22px; }
.modal-close:hover { color: var(--text); background: var(--panel-hover); }
.modal label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 12px; }
.field-label { display: flex; align-items: center; gap: 4px; }
.required-mark { color: var(--danger); }
.modal input, .modal textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  color: var(--text);
  background: var(--bg-soft);
  transition: 150ms ease;
}
.modal input { height: 42px; padding: 0 12px; }
.modal .check-row { flex-direction: row; align-items: center; gap: 9px; margin-top: 13px; cursor: pointer; }
.modal .check-row input { width: 16px; height: 16px; margin: 0; accent-color: var(--cyan); }
.modal .check-row span { color: var(--muted); }
.modal textarea { padding: 11px 12px; resize: vertical; }
.modal input:focus, .modal textarea:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(var(--cyan-rgb), .07); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.form-span { grid-column: 1 / -1; }
.form-error { min-height: 28px; padding-top: 7px; color: var(--danger); font-size: 12px; }
.modal-actions { justify-content: flex-end; margin-top: 23px; }
.dirty-actions { justify-content: flex-end; flex-wrap: wrap; }

.toast-region { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.toast { max-width: min(390px, calc(100vw - 32px)); padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--text); background: var(--panel-solid); box-shadow: var(--shadow); font-size: 13px; animation: toast-in 200ms ease both; }
.toast.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.toast.success { border-color: color-mix(in srgb, var(--success) 45%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 900px) {
  .topbar-inner { grid-template-columns: auto 1fr auto; gap: 13px; width: min(100% - 28px, 1600px); }
  .brand > span:last-child { display: none; }
  .top-actions .icon-button span, .compact span { display: none; }
  .icon-button, .compact { width: 39px; padding: 0; }
  .edit-toolbar, .page-shell { width: min(100% - 28px, 1600px); }
}

@media (max-width: 620px) {
  .topbar-inner { grid-template-columns: auto 1fr auto; min-height: 66px; gap: 9px; }
  .top-actions { gap: 5px; }
  .top-actions #themeButton { display: none; }
  .search-shell { height: 40px; }
  .search-shell kbd { display: none; }
  .search-shell input { padding-right: 10px; font-size: 13px; }
  .edit-toolbar { min-height: 57px; }
  .edit-status { font-size: 0; }
  .toolbar-actions { width: calc(100% - 24px); justify-content: flex-end; }
  .toolbar-actions button { min-height: 35px; padding: 0 10px; font-size: 12px; }
  .toolbar-actions #logoutButton { padding: 0 7px; }
  .page-shell { padding-top: 20px; padding-bottom: 40px; }
  .nav-root { gap: 23px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .nav-card { height: 72px; }
  .card-main { gap: 9px; padding: 10px; }
  .card-icon { width: 38px; height: 38px; border-radius: 9px; font-size: 16px; }
  .card-icon img { width: 23px; height: 23px; }
  .card-title { font-size: 13px; }
  .card-secondary { font-size: 10.5px; }
  .card-controls { top: 3px; right: 3px; opacity: 1; transform: none; }
  .editing .group-heading { flex-wrap: wrap; }
  .editing .group-actions { width: calc(100% - 12px); margin: 4px 0 0 12px; overflow-x: auto; scrollbar-width: thin; }
  .editing .card-main { align-items: flex-start; padding: 10px 10px 39px; }
  .editing .card-controls { top: auto; right: auto; bottom: 5px; left: 7px; flex-direction: row; }
  .editing .nav-card { min-height: 104px; height: auto; }
  .modal-card { padding: 25px 21px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-span { grid-column: auto; }
  .dirty-actions { align-items: stretch; flex-direction: column-reverse; }
  .dirty-actions button { width: 100%; }
}

@media (max-width: 360px) {
  .card-grid { grid-template-columns: 1fr; }
  .editing .nav-card { min-height: 82px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
