:root {
  color-scheme: light;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-muted: #f0f1f6;
  --text: #17181c;
  --muted: #767984;
  --line: #e7e8ee;
  --accent: #5b5bd6;
  --accent-strong: #4a4ac4;
  --accent-soft: #ececff;
  --ok: #2f9e6e;
  --ok-soft: #e8f6ef;
  --down: #df5050;
  --down-soft: #fdecec;
  --shadow: 0 10px 30px rgba(27, 29, 43, 0.06);
  --shadow-strong: 0 18px 44px rgba(27, 29, 43, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  min-width: 320px;
  background:
    radial-gradient(900px 500px at 12% -12%, rgba(91, 91, 214, 0.1), transparent 62%),
    radial-gradient(720px 420px at 92% -6%, rgba(47, 158, 110, 0.08), transparent 58%),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  color: inherit;
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  background: none;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(91, 91, 214, 0.3);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

img {
  display: block;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 22px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 13px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #8b6ef5);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(91, 91, 214, 0.28);
}

.brand-mark.large {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  font-size: 26px;
}

.nav {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-muted);
}

.nav-item {
  padding: 7px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: background 160ms ease, color 160ms ease;
}

.nav-item.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(20, 22, 35, 0.1);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
}

/* ---------- 通用控件 ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: 11px;
  font-size: 14px;
  font-weight: 500;
  transition: background 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.button.primary {
  background: linear-gradient(135deg, var(--accent), #7c63f0);
  color: #fff;
  box-shadow: 0 6px 16px rgba(91, 91, 214, 0.24);
}

.button.primary:hover {
  filter: brightness(1.05);
}

.button.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.button.ghost:hover {
  border-color: #cfd1dc;
  background: #fbfbfd;
}

.button.danger-text {
  color: var(--down);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.field input {
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfd;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input:focus {
  border-color: rgba(91, 91, 214, 0.55);
  box-shadow: 0 0 0 4px rgba(91, 91, 214, 0.1);
  background: #fff;
}

.form-error {
  margin: 0;
  border-radius: 10px;
  background: var(--down-soft);
  color: #b93b3b;
  padding: 9px 12px;
  font-size: 13px;
}

/* ---------- 登录 ---------- */

.login-page {
  display: flex;
  flex-direction: column;
  gap: 26px;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 40px 18px calc(40px + env(safe-area-inset-bottom));
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.login-brand h1 {
  font-size: 26px;
  letter-spacing: -0.03em;
}

.login-brand p {
  color: var(--muted);
  font-size: 14px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-strong);
}

.login-head h2 {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.login-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.login-submit {
  height: 44px;
  margin-top: 2px;
}

.link-button {
  align-self: center;
  color: var(--accent);
  font-size: 13px;
}

/* ---------- 主视图 ---------- */

.main {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 34px 24px 96px;
  animation: view-in 240ms ease-out;
}

@keyframes view-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.view-head h1 {
  font-size: clamp(26px, 3.6vw, 34px);
  letter-spacing: -0.035em;
}

.view-head p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13.5px;
}

.search {
  display: flex;
  align-items: center;
  width: 270px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.search:focus-within {
  border-color: rgba(91, 91, 214, 0.5);
  box-shadow: 0 0 0 4px rgba(91, 91, 214, 0.1);
}

.search input {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 14px;
}

.search input::placeholder {
  color: #a3a6b1;
}

/* ---------- 卡片网格 ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: 14px;
}

.tool-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 25, 38, 0.04);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.tool-card:hover,
.tool-card:focus-within {
  transform: translateY(-3px);
  border-color: rgba(91, 91, 214, 0.28);
  box-shadow: var(--shadow);
}

.tool-link {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 15px;
  border-radius: 18px;
  color: inherit;
  text-decoration: none;
}

.tool-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-muted);
}

.tool-icon img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 9px;
  object-fit: contain;
  background: #f7f8fb;
}

.tool-letter {
  color: #9a9dab;
  font-size: 17px;
  font-weight: 600;
  text-transform: uppercase;
}

.tool-emoji {
  font-size: 22px;
  line-height: 1;
}

.tool-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.tool-name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-host {
  display: flex;
  align-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #c3c5cf;
}

.status-dot.ok {
  background: var(--ok);
}

.status-dot.down {
  background: var(--down);
}

.tool-ops {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.tool-card:hover .tool-ops,
.tool-card:focus-within .tool-ops {
  opacity: 1;
}

.icon-button {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 12px;
  transition: color 140ms ease, border-color 140ms ease;
}

.icon-button:hover {
  border-color: rgba(91, 91, 214, 0.4);
  color: var(--accent);
}

.icon-button.danger:hover {
  border-color: rgba(223, 80, 80, 0.45);
  color: var(--down);
}

/* ---------- 空状态 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  grid-column: 1 / -1;
  padding: 56px 24px;
  border: 1px dashed #d8dae4;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
}

.empty h2 {
  font-size: 17px;
  letter-spacing: -0.01em;
}

.empty p {
  max-width: 340px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- 设置 ---------- */

.panel {
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 25, 38, 0.04);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-head h2 {
  font-size: 17px;
  letter-spacing: -0.02em;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.manage-list {
  margin-top: 14px;
}

.manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.manage-row:first-child {
  border-top: 0;
}

.manage-row .tool-icon {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
}

.manage-row .tool-icon img {
  padding: 7px;
}

.manage-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.manage-url {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  flex: none;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
}

.status-pill.ok {
  background: var(--ok-soft);
  color: #237a55;
}

.status-pill.down {
  background: var(--down-soft);
  color: #b93b3b;
}

.manage-actions {
  display: flex;
  flex: none;
  gap: 4px;
}

.account-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13.5px;
}

.account-line strong {
  color: var(--text);
  font-weight: 500;
}

/* ---------- 对话框 ---------- */

.editor-dialog {
  width: min(430px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-strong);
}

.editor-dialog::backdrop {
  background: rgba(20, 22, 35, 0.42);
  backdrop-filter: blur(3px);
}

.editor-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
}

.editor-form h2 {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.editor-hint {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  z-index: 100;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #1b1c22;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 响应式 ---------- */

@media (max-width: 720px) {
  .topbar-inner {
    gap: 12px;
    padding: 10px 16px;
  }

  .brand-name {
    display: none;
  }

  .nav-item {
    padding: 7px 13px;
    font-size: 13px;
  }

  .topbar-actions .button {
    height: 34px;
    padding: 0 12px;
    font-size: 13px;
  }

  .avatar {
    display: none;
  }

  .main {
    padding: 24px 16px calc(80px + env(safe-area-inset-bottom));
  }

  .view-head {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .search {
    width: 100%;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(152px, 1fr));
    gap: 10px;
  }

  .tool-link {
    gap: 10px;
    padding: 14px 12px;
  }

  .tool-name {
    font-size: 14px;
  }

  .tool-ops {
    opacity: 1;
    top: 8px;
    right: 8px;
  }

  .icon-button {
    padding: 3px 6px;
    font-size: 11px;
  }

  .panel {
    padding: 18px 16px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .manage-row {
    flex-wrap: wrap;
  }

  .manage-info {
    flex-basis: calc(100% - 50px);
  }

  .login-card {
    padding: 22px;
  }
}
