/* ─── Reset & Base ─────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #161625;
  --bg-card: #1c1c30;
  --bg-card-hover: #22223a;
  --bg-input: #1a1a2e;
  --border-color: rgba(99, 102, 241, 0.15);
  --border-hover: rgba(99, 102, 241, 0.35);
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #6868a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.12);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ─── App Container ─────────────────────────────────── */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ─── Header ────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 28px;
  gap: 16px;
  flex-wrap: wrap;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.header h1 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #e8e8f0 30%, #8b8bff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 400;
}
.logo {
  display: flex;
  filter: drop-shadow(0 0 10px var(--accent-glow));
}

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #8b5cf6);
  box-shadow: 0 4px 20px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-outline:hover {
  color: var(--accent-hover);
  border-color: var(--border-hover);
  background: rgba(99, 102, 241, 0.06);
}
.btn-outline:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 0.78rem;
}
.btn-icon {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}
.btn-icon:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); color: var(--red); }

/* ─── Add Link Form ─────────────────────────────────── */
.add-link-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 22px 24px 18px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-md);
}
.form-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.input-group {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.url-input-group { flex: 2; }
.desc-input-group { flex: 1.2; }
.input-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}
.input-group input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input::placeholder { color: var(--text-muted); }
.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-hint {
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.form-hint strong { color: var(--text-secondary); }

/* ─── Links List ────────────────────────────────────── */
.links-section { position: relative; }
.links-list { display: flex; flex-direction: column; gap: 12px; }

/* ─── Link Card ─────────────────────────────────────── */
.link-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: all var(--transition);
  position: relative;
  animation: cardIn 0.35s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.link-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}
.link-card.changed {
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 0 20px rgba(239, 68, 68, 0.1);
}
.link-card.changed::before {
  content: '';
  position: absolute;
  top: -1px; left: -1px; right: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--red), var(--orange));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.card-info { flex: 1; min-width: 0; }
.card-desc {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  word-break: break-word;
}
.card-url {
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-all;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

/* ─── Status Badge ──────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.badge-200 { background: var(--green-bg); color: var(--green); }
.badge-3xx { background: var(--yellow-bg); color: var(--yellow); }
.badge-4xx { background: var(--orange-bg); color: var(--orange); }
.badge-error { background: var(--red-bg); color: var(--red); }
.badge-changed {
  background: var(--red-bg);
  color: var(--red);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.meta-item {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.meta-item svg { flex-shrink: 0; }

/* ─── Redirect Chain ────────────────────────────────── */
.redirect-chain {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(234, 179, 8, 0.04);
  border: 1px solid rgba(234, 179, 8, 0.12);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
  overflow-x: auto;
}
.redirect-hop {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.redirect-hop .hop-status {
  color: var(--yellow);
  font-weight: 700;
  flex-shrink: 0;
}
.redirect-hop .hop-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}
.redirect-hop .hop-url {
  word-break: break-all;
}

/* ─── Snapshot Preview ──────────────────────────────── */
.snapshot-toggle {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font);
  padding: 0;
  font-weight: 500;
}
.snapshot-toggle:hover { color: var(--accent-hover); text-decoration: underline; }
.snapshot-preview {
  margin-top: 8px;
  padding: 10px 14px;
  background: rgba(99, 102, 241, 0.04);
  border: 1px solid rgba(99, 102, 241, 0.1);
  border-radius: var(--radius-sm);
  font-size: 0.73rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.snapshot-preview.visible { display: block; }

/* ─── Final URL ─────────────────────────────────────── */
.final-url {
  font-size: 0.75rem;
  color: var(--accent);
  word-break: break-all;
  display: flex;
  align-items: center;
  gap: 4px;
}
.final-url svg { flex-shrink: 0; color: var(--text-muted); }

/* ─── Empty State ───────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { opacity: 0.25; margin-bottom: 16px; }
.empty-state p { font-size: 0.9rem; }

/* ─── Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}
.diff-content {
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 0.78rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  line-height: 1.7;
}
.diff-line-add {
  background: rgba(34, 197, 94, 0.1);
  color: var(--green);
  padding: 1px 6px;
  border-radius: 3px;
}
.diff-line-remove {
  background: rgba(239, 68, 68, 0.1);
  color: var(--red);
  padding: 1px 6px;
  border-radius: 3px;
  text-decoration: line-through;
}
.diff-line-same {
  color: var(--text-muted);
  padding: 1px 6px;
}

/* ─── Spinner ───────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ─────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease;
  max-width: 340px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}
.toast-success { background: #1a3a2a; color: var(--green); border: 1px solid rgba(34,197,94,0.2); }
.toast-error { background: #3a1a1a; color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.toast-info { background: #1a1a3a; color: var(--accent-hover); border: 1px solid rgba(99,102,241,0.2); }

/* ─── Environment Tabs ──────────────────────────────── */
.env-tabs {
  display: flex;
  gap: 6px;
  padding: 0 0 16px;
  flex-wrap: wrap;
}
.env-tab {
  padding: 6px 16px;
  border: 1px solid var(--border-color);
  border-radius: 100px;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.env-tab:hover {
  border-color: var(--border-hover);
  color: var(--accent-hover);
  background: rgba(99, 102, 241, 0.06);
}
.env-tab.active {
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ─── Tag Badge ─────────────────────────────────────── */
.tag-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 100px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  margin-left: 8px;
  vertical-align: middle;
}

/* ─── Tag Input ─────────────────────────────────────── */
.tag-input-group { flex: 0.7; }

/* ─── Expected URL ──────────────────────────────────── */
.expected-url {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--red);
  word-break: break-all;
  opacity: 0.8;
}
.expected-label {
  font-weight: 700;
  color: var(--orange);
}

/* ─── Responsive ────────────────────────────────────── */
@media (max-width: 640px) {
  .form-row { flex-direction: column; }
  .header { flex-direction: column; align-items: flex-start; }
  .card-top { flex-direction: column; }
  .card-actions { align-self: flex-end; }
}
