/* ============ 主题变量 ============ */
:root {
  --bg: #f4f6fb;
  --bg-soft: #eef1f8;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e6e9f2;
  --border-strong: #d6dbe8;
  --text: #171a23;
  --text-2: #5b6478;
  --text-3: #8b93a7;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: rgba(79, 70, 229, 0.09);
  --danger: #e5484d;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.1);
  --radius: 16px;
}

[data-theme='dark'] {
  --bg: #0d1017;
  --bg-soft: #131722;
  --surface: #161b25;
  --surface-2: #1c222e;
  --border: #262d3b;
  --border-strong: #313a4c;
  --text: #e8eaf0;
  --text-2: #9aa3b5;
  --text-3: #6f7a8d;
  --brand: #7c74ff;
  --brand-2: #a78bfa;
  --brand-soft: rgba(124, 116, 255, 0.14);
  --danger: #ff6369;
  --ok: #3dd68c;
  --warn: #fbbf24;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
    'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

/* 背景光斑 */
.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(680px 380px at 12% -8%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(620px 420px at 92% 4%, rgba(168, 85, 247, 0.14), transparent 62%),
    radial-gradient(700px 460px at 50% 106%, rgba(56, 189, 248, 0.1), transparent 60%);
}
[data-theme='dark'] .bg-glow { opacity: 0.55; }

.app {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* ============ 头部 ============ */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo {
  width: 46px; height: 46px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.32);
}
.logo svg { width: 24px; height: 24px; }
.brand-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.2px;
}
.brand-text p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

.header-right { display: flex; align-items: center; gap: 8px; flex: none; }

.addr-chip {
  display: inline-flex; align-items: center; gap: 7px;
  max-width: 240px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.18s ease;
}
.addr-chip:hover { color: var(--brand); border-color: var(--brand); transform: translateY(-1px); }
.addr-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.addr-chip .ico { width: 14px; height: 14px; flex: none; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.18s ease;
}
.icon-btn:hover { color: var(--brand); border-color: var(--brand); }
.icon-btn .ico { width: 17px; height: 17px; }
.icon-btn .moon { display: none; }
[data-theme='dark'] .icon-btn .sun { display: none; }
[data-theme='dark'] .icon-btn .moon { display: block; }
.ico { flex: none; }

/* ============ 命名空间栏 ============ */
.nsbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 10px 12px 10px 14px;
  margin-bottom: 14px;
}
.ns-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ns-ico {
  width: 36px; height: 36px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand);
}
.ns-ico svg { width: 18px; height: 18px; }
.ns-label {
  display: block;
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--text-3);
}
.ns-name {
  display: block;
  font-size: 15.5px;
  font-weight: 650;
  color: var(--text);
  word-break: break-all;
  line-height: 1.35;
}
.ns-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ns-input {
  width: 160px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.ns-input::placeholder { color: var(--text-3); }
.ns-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ============ 输入区 ============ */
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px 6px 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft), var(--shadow-md);
}
#input {
  display: block;
  width: 100%;
  min-height: 62px;
  max-height: 260px;
  padding: 14px 14px 6px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.65;
  overflow-y: auto;
}
#input::placeholder { color: var(--text-3); }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px 8px;
  border-top: 1px solid transparent;
}
.counter { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.composer-actions { display: flex; align-items: center; gap: 8px; }

.kbd-hint { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 4px; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: inherit;
  font-size: 11px;
  text-align: center;
  color: var(--text-2);
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}
.btn .ico { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.28);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); box-shadow: 0 8px 22px rgba(79, 70, 229, 0.36); }
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  background: var(--surface-2);
  color: var(--text-3);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

.btn-danger-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-2);
}
.btn-danger-ghost:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}

/* ============ 工具条 ============ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 22px 2px 12px;
  flex-wrap: wrap;
}
.stats {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.stats strong { color: var(--text); font-weight: 600; }
.dot { color: var(--text-3); }

.toolbar-right { display: flex; align-items: center; gap: 8px; }
.search {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  transition: border-color 0.18s ease;
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search .ico { width: 15px; height: 15px; color: var(--text-3); }
.search input {
  width: 130px;
  border: 0; outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}
.search input::placeholder { color: var(--text-3); }

/* ============ 列表 ============ */
.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: cardIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease, opacity 0.2s ease;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.card.leaving { opacity: 0; transform: scale(0.97); }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.card-body {
  padding: 14px 16px 10px;
  cursor: pointer;
}
.card-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--text);
}
.card.is-long .card-text {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.expanded .card-text { display: block; overflow: visible; }

.toggle-more {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.toggle-more:hover { text-decoration: underline; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.card-actions { display: flex; align-items: center; gap: 6px; flex: none; }

.act {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.16s ease;
}
.act .ico { width: 14px; height: 14px; }
.act:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.act.copy:hover { color: var(--brand); border-color: var(--brand); }
.act.del:hover { color: var(--danger); border-color: var(--danger); }
.act.copied { color: var(--ok); border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.act.copied .ico-check { display: block; }
.act.copied .ico-copy { display: none; }
.ico-check { display: none; }

/* ============ 空状态 ============ */
.empty { padding: 46px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 148px; height: auto; margin-bottom: 6px; }
.empty-title { margin: 8px 0 2px; font-size: 15px; font-weight: 600; color: var(--text-2); }
.empty-sub { margin: 0; font-size: 13px; }

.footer {
  margin-top: 34px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.9;
}
.footer p { margin: 6px 0 0; }
.footer code {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

.storage-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.storage-pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.storage-pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* ============ Toast ============ */
.toasts {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(23, 26, 35, 0.92);
  color: #fff;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  animation: toastIn 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.err { background: rgba(229, 72, 77, 0.95); }
.toast.ok { background: rgba(22, 163, 74, 0.95); }
.toast.out { animation: toastOut 0.2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ============ 响应式 ============ */
@media (max-width: 620px) {
  .app { padding: 20px 14px 48px; }
  .header { flex-direction: column; align-items: stretch; gap: 14px; }
  .header-right { justify-content: space-between; }
  .addr-chip { max-width: none; flex: 1; }
  .nsbar { flex-direction: column; align-items: stretch; }
  .ns-actions { justify-content: flex-end; }
  .ns-input { flex: 1; width: auto; min-width: 0; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-right { justify-content: space-between; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .kbd-hint { display: none; }
  .brand-text h1 { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
