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

:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3350;
  --primary: #5b6af5;
  --primary-hover: #4453e8;
  --danger: #e05252;
  --danger-hover: #c03d3d;
  --text: #e2e4ef;
  --muted: #7a80a0;
  --success: #4caf50;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Navbar ────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 2rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}

.navbar-brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

/* ─── Container ─────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

/* ─── Page header ───────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header h1 { font-size: 1.6rem; }
.page-header p.muted { font-size: 0.85rem; color: var(--muted); margin-top: 0.25rem; }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); text-decoration: none; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 1rem; padding: 0 0.3rem; color: var(--muted); }
.btn-icon:hover { color: var(--text); }
.btn-copy { vertical-align: middle; }

/* ─── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 1rem;
}

/* ─── Table ─────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th, .table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg3); }

.short-link { font-family: monospace; font-size: 0.95rem; }
.url-cell { color: var(--muted); font-size: 0.85rem; max-width: 280px; }
.actions-cell { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

/* ─── Badge ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
}

/* ─── Forms ─────────────────────────────────────────────────────────── */
.form-card { max-width: 600px; }

.form-group { margin-bottom: 1.25rem; }

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.required { color: var(--danger); }
.optional { color: var(--muted); font-weight: 400; font-size: 0.82rem; }

.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.alias-wrapper {
  display: flex;
  align-items: center;
}

.alias-prefix {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 0.6rem 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.alias-wrapper .form-control {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.hint { color: var(--muted); font-size: 0.8rem; display: block; margin-top: 0.3rem; }

/* ─── Alerts ─────────────────────────────────────────────────────────── */
.alert {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.alert-error { background: rgba(224,82,82,0.15); border: 1px solid var(--danger); color: #f5a0a0; }

/* ─── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}

.empty-state p { margin-bottom: 1rem; font-size: 1.05rem; }

/* ─── Dashboard ─────────────────────────────────────────────────────── */
.stats-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

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

.link-info { display: flex; flex-direction: column; gap: 0.75rem; }

.link-full-url {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.link-meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 1rem; flex-wrap: wrap; }

.total-clicks-badge {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.big-number { font-size: 2.8rem; font-weight: 800; color: var(--primary); line-height: 1; }
.big-number-label { font-size: 0.95rem; color: var(--muted); }

.qr-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  min-width: 160px;
}

.qr-img { width: 140px; height: 140px; border-radius: 6px; }

/* ─── KPI grid ──────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

/* ─── Rank list ─────────────────────────────────────────────────────── */
.rank-list { list-style: none; }

.rank-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.rank-list li:last-child { border-bottom: none; }
.rank-label { color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-count { color: var(--primary); font-weight: 700; margin-left: 1rem; flex-shrink: 0; }

/* ─── Charts ────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 220px; }
.chart-sm { height: 180px; }

/* ─── Error page ────────────────────────────────────────────────────── */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6rem 2rem;
  text-align: center;
}

.error-code { font-size: 6rem; font-weight: 900; color: var(--primary); line-height: 1; }
.error-message { font-size: 1.1rem; color: var(--muted); margin: 1rem 0 2rem; }

/* ─── Footer ────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* ─── Muted text ─────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
