:root {
  --bg: #f0f2f5;
  --panel: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #94a3b8;
  --line: #e2e8f0;
  --line-light: #f1f5f9;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #eef2ff;
  --primary-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --blue: #3b82f6;
  --blue-bg: #eff6ff;
  --purple-bg: #f5f3ff;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow: 0 4px 16px rgba(15,23,42,0.06), 0 2px 8px rgba(15,23,42,0.04);
  --shadow-lg: 0 10px 40px rgba(15,23,42,0.08), 0 4px 16px rgba(15,23,42,0.04);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }

/* Card */
.card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card { padding: 20px; }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 0 16px 0; border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }

/* Button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
  border: none; cursor: pointer; transition: all 0.2s; white-space: nowrap;
  font-family: inherit; line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 14px rgba(99,102,241,0.4); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
}
.btn-secondary:hover { background: #ddd6fe; }
.btn-muted { background: #f1f5f9; color: var(--text-secondary); }
.btn-muted:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-light { background: var(--blue-bg); color: var(--blue); }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-icon {
  background: transparent; border: none; cursor: pointer;
  padding: 6px; font-size: 15px; border-radius: var(--radius-sm);
  transition: all 0.15s; line-height: 1;
}
.btn-icon:hover { background: var(--line-light); transform: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Input */
.input, select, textarea {
  width: 100%; border: 1.5px solid #d1d5db; border-radius: var(--radius-sm);
  padding: 10px 12px; font: inherit; background: #fff;
  transition: all 0.2s; color: var(--text);
}
.input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* Tag / Badge */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.5;
}
.tag.green { background: var(--success-bg); color: #059669; }
.tag.purple { background: var(--purple-bg); color: #7c3aed; }
.tag.yellow { background: var(--warning-bg); color: #d97706; }
.tag.red { background: var(--danger-bg); color: #dc2626; }
.tag.gray { background: #f1f5f9; color: #64748b; }
.tag.blue { background: var(--blue-bg); color: #2563eb; }

/* Flash message */
.flash {
  margin-bottom: 16px; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14px; line-height: 1.5;
}
.flash.success { background: var(--success-bg); color: #059669; border-left: 3px solid var(--success); }
.flash.error { background: var(--danger-bg); color: #dc2626; border-left: 3px solid var(--danger); }
.muted { color: var(--muted); }

/* Table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 12px 16px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.data-table th {
  background: #f8fafc; color: var(--muted);
  font-weight: 600; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em;
}
.data-table tr:hover td { background: #f8fafc; }
.data-table .empty-row { text-align: center; color: #94a3b8; padding: 40px; }
.url-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.short-link { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; font-weight: 600; color: var(--primary); }

/* Grid */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid.cols-2, .grid.cols-4 { grid-template-columns: 1fr; } }
@media (max-width: 1200px) { .grid.cols-4 { grid-template-columns: repeat(2, 1fr); } }

/* Modal */
.modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-content {
  background: var(--panel); border: none;
  border-radius: var(--radius-lg); padding: 28px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-content h3 { margin-bottom: 16px; font-size: 17px; font-weight: 600; }

/* Toolbar */
.page-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.search-form { display: flex; gap: 8px; }
.search-form input {
  width: 260px; padding: 9px 12px;
  border: 1.5px solid #d1d5db; border-radius: var(--radius-sm);
  font: inherit; transition: all 0.2s;
}
.search-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,0.12); }

/* Stat values */
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.region-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.region-item:last-child { border-bottom: none; }
.region-name { flex: 1; }

.link-info { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }

/* Range selector */
.range-selector { display: flex; gap: 4px; }
.range-selector a {
  padding: 5px 14px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--muted);
  transition: all 0.15s; font-weight: 500;
}
.range-selector a:hover { background: #f1f5f9; color: var(--text); }
.range-selector a.active { background: var(--primary); color: #fff; }

/* Utility */
.small { font-size: 12px; color: var(--muted); }
.center { text-align: center; }
