:root {
  --bg: #edf3f7;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.18);
  --text: #14202b;
  --muted: #5e6b77;
  --accent: #0f172a;
  --accent-soft: #dce6ee;
  --danger: #b94b5d;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(156, 201, 255, 0.28), transparent 34%),
    radial-gradient(circle at bottom right, rgba(172, 233, 221, 0.22), transparent 30%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

.hidden {
  display: none;
}

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
}

.confirm-dialog.hidden {
  display: none;
}

.confirm-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.22);
  backdrop-filter: blur(4px);
}

.confirm-dialog-card {
  position: relative;
  width: min(100%, 360px);
  padding: 18px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: var(--radius-lg);
  background: rgba(252, 254, 255, 0.96);
  box-shadow: 0 22px 48px rgba(15, 23, 42, 0.16);
}

.confirm-dialog-card h2 {
  margin: 0;
  font-size: 18px;
}

.confirm-dialog-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.confirm-dialog-hint {
  font-size: 12px;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.admin-shell {
  width: min(100%, 1600px);
  max-width: 1600px;
  margin: 0 auto;
  padding: 12px 24px 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel-head {
  margin-bottom: 10px;
}

.panel-head h1,
.tool-card h2 {
  margin: 0;
  font-size: 20px;
}

.panel-head p,
.tool-card p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
}

.app-panel > .panel-head {
  margin-bottom: 14px;
}

.panel-head-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.auth-panel,
.app-panel {
  padding: 16px;
}

.auth-panel {
  max-width: 440px;
  margin: 10vh auto 0;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.group-card,
.tool-card {
  display: grid;
  gap: 8px;
}

.auth-form span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

input:focus {
  border-color: var(--line-strong);
}

button,
.file-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  padding: 0 10px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:disabled,
.file-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--text);
}

.danger-button {
  background: rgba(185, 75, 93, 0.14);
  color: var(--danger);
}

.visibility-toggle {
  position: relative;
  width: 32px;
  min-width: 32px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  overflow: hidden;
}

.visibility-toggle::before {
  content: "";
  width: 16px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-radius: 999px / 75%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.visibility-toggle::after {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.visibility-toggle:focus-visible {
  outline: 2px solid rgba(79, 136, 184, 0.26);
  outline-offset: 1px;
}

.visibility-toggle.is-hidden {
  color: var(--soft);
  background: rgba(220, 230, 238, 0.72);
  background-image: linear-gradient(135deg, transparent 42%, currentColor 42%, currentColor 50%, transparent 50%);
  background-size: 18px 18px;
  background-repeat: no-repeat;
  background-position: center;
}

.header-actions,
.tool-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: stretch;
}

.header-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(248, 251, 254, 0.96), rgba(238, 245, 250, 0.92));
  color: var(--text);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.header-nav-link:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: linear-gradient(180deg, rgba(252, 254, 255, 0.98), rgba(243, 248, 252, 0.96));
}

.header-nav-link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 7px;
  background: rgba(220, 230, 238, 0.9);
  color: var(--accent);
}

.header-nav-link-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.header-nav-link-copy {
  display: grid;
  gap: 1px;
  line-height: 1.1;
}

.header-nav-link-title {
  font-size: 13px;
  font-weight: 600;
}

.header-nav-link-subtitle {
  font-size: 11px;
  color: var(--muted);
}

.layout-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.toolbar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.tool-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(250, 253, 255, 0.76));
  padding: 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.tool-card h2 {
  font-size: 16px;
}

.tool-card-password .password-form {
  margin-top: 4px;
}

.file-button input {
  display: none;
}

.status,
.error {
  min-height: 18px;
  margin: 0 0 8px;
}

.error {
  color: var(--danger);
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.72fr);
  gap: 12px;
  align-items: start;
}

.groups-panel {
  display: grid;
  gap: 8px;
  min-height: 24px;
}

.outline-panel {
  position: sticky;
  top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(247, 251, 254, 0.96), rgba(238, 246, 252, 0.92));
  padding: 14px 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.outline-panel-head {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.outline-panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.outline-panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.outline-panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.outline-tree {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding-right: 4px;
}

.outline-group {
  display: grid;
  gap: 6px;
  position: relative;
}

.outline-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: grab;
}

.outline-group-head:active {
  cursor: grabbing;
}

.outline-toggle {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  position: relative;
}

.outline-toggle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translate(-50%, -65%) rotate(45deg);
}

.outline-toggle:hover {
  background: rgba(216, 232, 244, 0.72);
  color: var(--accent);
}

.outline-group-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.outline-group-order,
.outline-link-order {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--muted);
}

.outline-link-list {
  margin: 0;
  padding: 0 12px 0 34px;
  display: grid;
  gap: 4px;
  min-height: 10px;
  color: var(--muted);
  border-radius: var(--radius-md);
  transition: background 0.18s ease;
  position: relative;
  list-style-position: outside;
}

.outline-link-list.is-empty {
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.outline-group.is-collapsed .outline-link-list {
  display: none;
}

.outline-group.is-collapsed .outline-toggle::before {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.outline-link-list.is-drop-target {
  background: rgba(216, 232, 244, 0.56);
}


.outline-link-list.drop-at-end::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 8px;
  bottom: 0;
  height: 2px;
  border-radius: 999px;
  background: rgba(79, 136, 184, 0.9);
}

.outline-link-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  line-height: 1.35;
  cursor: grab;
  user-select: none;
  position: relative;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding-right: 6px;
  padding: 4px 6px;
  margin-left: -6px;
  margin-right: -2px;
  border-radius: 6px;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.outline-group-title:hover,
.outline-link-item:hover {
  color: var(--accent);
}

.outline-link-label {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.outline-name-input {
  min-width: 0;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  padding: 2px 6px;
  border-radius: 6px;
}

.outline-name-input:hover {
  background: rgba(216, 232, 244, 0.52);
}

.outline-name-input:focus {
  background: rgba(255, 255, 255, 0.88);
  border-color: rgba(79, 136, 184, 0.36);
  outline: none;
}

.outline-delete {
  flex: 0 0 auto;
  min-height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: rgba(185, 75, 93, 0.12);
  color: var(--danger);
  cursor: pointer;
}

.outline-delete:hover {
  background: rgba(185, 75, 93, 0.18);
}

.outline-link-item:has(.outline-link-delete:hover) {
  background: rgba(185, 75, 93, 0.12);
  box-shadow: inset 0 0 0 1px rgba(185, 75, 93, 0.24);
  color: var(--danger);
}

.outline-group-head:has(.outline-group-delete:hover) {
  background: rgba(185, 75, 93, 0.12);
  border-radius: var(--radius-md);
  box-shadow: inset 0 0 0 1px rgba(185, 75, 93, 0.24);
}

.outline-group-head:has(.outline-group-delete:hover) .outline-group-title {
  color: var(--danger);
}

.outline-link-item:hover {
  background: rgba(216, 232, 244, 0.72);
  box-shadow: inset 0 0 0 1px rgba(79, 136, 184, 0.22);
}

.group-card.is-hidden,
.link-card.is-hidden,
.outline-group.is-hidden,
.outline-link-item.is-hidden {
  opacity: 0.64;
}

.outline-link-item.is-dragging {
  opacity: 0.55;
  pointer-events: none;
}

.outline-group.is-dragging {
  opacity: 0.55;
  pointer-events: none;
}

.outline-group.drop-before-group::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -5px;
  height: 2px;
  border-radius: 999px;
  background: rgba(79, 136, 184, 0.9);
}

.outline-link-item.drop-before::before {
  content: "";
  position: absolute;
  left: -14px;
  right: 0;
  top: -4px;
  height: 2px;
  border-radius: 999px;
  background: rgba(79, 136, 184, 0.9);
}

.outline-link-item:active {
  cursor: grabbing;
}

.group-card.is-jumping,
.link-card.is-jumping {
  animation: jumpHighlight 1.2s ease;
}

@keyframes jumpHighlight {
  0% {
    box-shadow: 0 0 0 0 rgba(79, 136, 184, 0);
    border-color: rgba(15, 23, 42, 0.1);
  }

  20% {
    box-shadow: 0 0 0 4px rgba(79, 136, 184, 0.14);
    border-color: rgba(79, 136, 184, 0.48);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(79, 136, 184, 0);
    border-color: rgba(15, 23, 42, 0.1);
  }
}

.outline-empty {
  margin: 0;
  color: var(--muted);
}

.group-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(232, 241, 248, 0.92), rgba(244, 249, 253, 0.88));
  padding: 12px;
  transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.group-card.is-dragging {
  opacity: 0.72;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.12);
}

.group-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 10px;
  background: rgba(219, 233, 243, 0.72);
}

.group-title-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 8px;
  align-content: center;
}

.group-card-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.group-card-head:has(.delete-group-button:hover) {
  background: rgba(185, 75, 93, 0.12);
  box-shadow: inset 0 0 0 1px rgba(185, 75, 93, 0.24);
}

.group-body {
  display: grid;
  gap: 6px;
  padding-top: 8px;
}

.group-card.is-collapsed .group-body {
  display: none;
}

.link-list {
  display: grid;
  gap: 8px;
  min-height: 18px;
  padding: 2px;
  border-radius: 10px;
  transition: border-color 0.18s ease;
}

.link-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 0.95fr) minmax(0, 1.2fr) minmax(0, 0.9fr) auto;
  gap: 5px;
  align-items: center;
  padding: 6px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.96);
  transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.link-card:has(.delete-link-button:hover) {
  background: rgba(255, 240, 243, 0.96);
  border-color: rgba(185, 75, 93, 0.28);
  box-shadow: inset 0 0 0 1px rgba(185, 75, 93, 0.16);
}

.link-card:hover {
  border-color: rgba(15, 23, 42, 0.16);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.password-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.order-input {
  width: 48px;
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-left: 4px;
  padding-right: 4px;
  appearance: textfield;
  -moz-appearance: textfield;
}

.link-card > .delete-link-button,
.link-card > .open-link-button {
  min-width: 52px;
  padding-left: 8px;
  padding-right: 8px;
  white-space: nowrap;
}

.link-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  justify-self: end;
}

.link-card-actions > .delete-link-button,
.link-card-actions > .open-link-button,
.link-card-actions > .visibility-link-button {
  min-width: 32px;
  white-space: nowrap;
}

.link-card-actions > .delete-link-button {
  order: 3;
}

.order-input::-webkit-outer-spin-button,
.order-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.password-form {
  margin-top: 2px;
  align-items: stretch;
}

.password-form input {
  min-width: 0;
  flex: 1 1 132px;
}

.group-title-input {
  font-size: 15px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.88);
}

.collapse-group-button {
  min-width: 54px;
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .toolbar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .outline-panel {
    order: -1;
    margin-bottom: 4px;
  }

  .groups-panel {
    order: 1;
  }

  .outline-panel {
    position: static;
  }

  .link-card {
    grid-template-columns: 1fr;
  }

  .group-card-head {
    grid-template-columns: 1fr;
  }

  .group-title-row {
    grid-template-columns: 48px minmax(0, 1fr);
  }
}

@media (max-width: 720px) {
  .admin-shell {
    width: 100%;
    max-width: none;
    padding: 10px 14px;
  }

  .app-panel,
  .auth-panel {
    padding: 14px;
  }

  .toolbar-grid {
    grid-template-columns: 1fr;
  }

  .panel-head-row {
    flex-direction: column;
  }

  .group-title-row,
  .password-form {
    flex-direction: column;
  }

  .group-title-row {
    grid-template-columns: 1fr;
  }

  .group-card-actions {
    justify-content: flex-start;
  }
}
