:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-soft: #e0f2fe;
  --accent-text: #0369a1;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 22px rgba(15, 23, 42, 0.04);
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-muted: #0f172a;
  --border: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #7dd3fc;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-text: #7dd3fc;
  --danger: #f87171;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 8px;
}

.nav-link:hover {
  color: var(--accent);
  background: var(--surface);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.input:focus {
  border-color: var(--accent);
}

.slug-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
  overflow: hidden;
}

.slug-input-wrap:focus-within {
  border-color: var(--accent);
}

.slug-prefix {
  padding: 0 8px 0 12px;
  font-size: 13px;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: nowrap;
}

.slug-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px 12px 10px 0;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  outline: none;
}

.create-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #ffffff;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

html[data-theme="dark"] .btn-primary {
  color: #0f172a;
}

.list-section {
  margin-top: 24px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.list-head h2 {
  margin: 0;
  font-size: 15px;
}

.count-badge {
  font-size: 12px;
  color: var(--text-muted);
}

.links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.link-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.short-url-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.short-url {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.link-title {
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.clicks-pill {
  font-size: 12px;
  color: var(--text-muted);
}

.target-url {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
}

.link-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.action-btn:hover {
  border-color: var(--accent);
}

.action-btn.danger {
  color: var(--danger);
}

.edit-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.edit-row .input {
  flex: 1;
  min-width: 200px;
  padding: 7px 10px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.modal-tip {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  pointer-events: none;
}

html[data-theme="dark"] .toast {
  background: #f1f5f9;
  color: #0f172a;
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}
