/*
  LinkManager UI
  No external assets or inline styles, so the CSP in _headers can stay strict.
*/

:root {
  --bg: #080b10;
  --panel: #0f151d;
  --panel-2: #131b25;
  --line: #1e2937;
  --line-soft: #17212e;
  --text: #e8eef7;
  --muted: #8a99ad;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --green: #2fd08c;
  --green-soft: rgba(47, 208, 140, 0.14);
  --amber: #f5b544;
  --amber-soft: rgba(245, 181, 68, 0.14);
  --red: #ff6b6b;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(91, 140, 255, 0.10), transparent 60%),
    radial-gradient(700px 400px at 0% 100%, rgba(124, 92, 255, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; letter-spacing: -0.02em; }
h2 { font-size: 16px; letter-spacing: -0.01em; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  color: #b9c8dd;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 5px;
  padding: 1px 5px;
}

.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- layout */

.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  border-right: 1px solid var(--line-soft);
  background: rgba(9, 13, 19, 0.72);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  color: var(--text);
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, rgba(91, 140, 255, 0.26), rgba(124, 92, 255, 0.20));
  border: 1px solid rgba(91, 140, 255, 0.35);
  color: #a9c0ff;
  font-size: 15px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-item:hover { background: rgba(255, 255, 255, 0.03); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-soft);
  border-color: rgba(91, 140, 255, 0.22);
  color: #c9d8ff;
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.55;
}

.nav-item.is-active .nav-dot { opacity: 1; box-shadow: 0 0 10px rgba(91, 140, 255, 0.9); }

.sidebar-foot { margin-top: auto; display: grid; gap: 12px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}

.user-chip div { min-width: 0; }
.user-chip strong {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-chip small { color: var(--muted); font-size: 11px; }

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: linear-gradient(140deg, #5b8cff, #7c5cff);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.main {
  min-width: 0;
  padding: 28px 32px 56px;
}

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

.eyebrow {
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.view { display: grid; gap: 18px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: linear-gradient(180deg, rgba(19, 27, 37, 0.92), rgba(15, 21, 29, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.card-head .muted { font-size: 12.5px; margin-top: 4px; max-width: 560px; }

.export-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.export-card .muted { font-size: 12.5px; margin-top: 5px; max-width: 640px; }

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

.stat { position: relative; overflow: hidden; }
.stat::after {
  content: "";
  position: absolute;
  inset: auto -30% -60% auto;
  width: 140px;
  height: 140px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(91, 140, 255, 0.16), transparent 70%);
  pointer-events: none;
}

.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -0.03em; margin-top: 8px; }
.stat-value.muted-value { color: var(--muted); }
.stat-hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; }

/* ----------------------------------------------------------------- chart */

.chart-card { padding-bottom: 12px; }

.chart-legend {
  display: flex;
  gap: 18px;
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 10px;
}

.chart-legend span { display: inline-flex; align-items: center; gap: 7px; }

.swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.swatch.human { background: #5b8cff; }
.swatch.bot { background: #33445c; }

.chart { width: 100%; min-height: 220px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: #1b2634; stroke-width: 1; }
.chart .axis-text { fill: #75859a; font-size: 10px; }
.chart .bar-human { fill: url(#humanGradient); }
.chart .bar-bot { fill: #2a3a4f; }
.chart .bar-human:hover, .chart .bar-bot:hover { filter: brightness(1.25); }

/* ----------------------------------------------------------------- lists */

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

.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.rank-list { display: grid; gap: 2px; }

.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: 9px;
}

.rank-row + .rank-row { border-top: 1px solid var(--line-soft); }
.rank-row:hover { background: rgba(255, 255, 255, 0.02); }

.rank-main { min-width: 0; }
.rank-title {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rank-sub {
  color: var(--muted);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-bar {
  display: block;
  width: 100%;
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
}
.rank-track { fill: var(--line); }
.rank-fill { fill: #5b8cff; }

.rank-value { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

.empty { color: var(--muted); font-size: 12.5px; padding: 18px 8px; text-align: center; }

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search { flex: 1 1 260px; min-width: 200px; }

.search input, .select-wrap select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 11, 16, 0.6);
  color: var(--text);
  font: inherit;
  outline: none;
}

.search input:focus, .select-wrap select:focus,
.field input:focus, .field select:focus {
  border-color: rgba(91, 140, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.12);
}

.select-wrap { width: 190px; }

/* ----------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--line-soft); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.8px;
}

.table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 550;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

.table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.018); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions-col { width: 1%; text-align: right; white-space: nowrap; }

.link-cell { display: grid; gap: 3px; min-width: 180px; }
.link-title { font-weight: 600; color: var(--text); }
.slug-line { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.slug {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(91, 140, 255, 0.10);
  border: 1px solid rgba(91, 140, 255, 0.18);
  color: #a9c0ff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10.5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slug.woo { background: rgba(124, 92, 255, 0.10); border-color: rgba(124, 92, 255, 0.20); color: #c3b4ff; }

.url-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 999px; background: currentColor; }
.badge.active { color: var(--green); background: var(--green-soft); }
.badge.paused { color: var(--amber); background: var(--amber-soft); }

.click-cell { display: grid; justify-items: end; gap: 2px; }
.click-cell strong { font-weight: 600; }
.click-cell small { color: var(--muted); font-size: 10.5px; }

.row-actions { display: inline-flex; gap: 4px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); border-color: var(--line); }
.icon-btn.danger:hover { color: var(--red); border-color: rgba(255, 107, 107, 0.3); background: rgba(255, 107, 107, 0.08); }

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
}

.pager { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.btn:hover { background: rgba(255, 255, 255, 0.06); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #6a97ff, #4f7ff0);
  border-color: rgba(120, 160, 255, 0.55);
  color: #fff;
  box-shadow: 0 8px 24px rgba(60, 110, 240, 0.28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { height: 32px; padding: 0 11px; font-size: 12px; }
.btn.full { width: 100%; }

/* ----------------------------------------------------------------- modal */

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(3, 5, 8, 0.72); backdrop-filter: blur(4px); }

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #101720;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.modal-panel.small { width: min(440px, 100%); }

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

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

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12px; color: #b7c4d6; font-weight: 550; }
.field > span b { color: var(--accent); font-weight: 600; }
.field small { color: var(--muted); font-size: 11px; }

.field input, .field select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 11, 16, 0.65);
  color: var(--text);
  font: inherit;
  outline: none;
}

.form-error {
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(255, 107, 107, 0.09);
  border: 1px solid rgba(255, 107, 107, 0.25);
  color: #ff9b9b;
  font-size: 12.5px;
  margin-bottom: 14px;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #16202c;
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  font-size: 13px;
}
.toast.success { border-color: rgba(47, 208, 140, 0.35); }
.toast.error { border-color: rgba(255, 107, 107, 0.35); }

/* ------------------------------------------------------------------ auth */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(19, 27, 37, 0.95), rgba(15, 21, 29, 0.95));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-brand { padding: 0; margin-bottom: 24px; }
.auth-card h1 { font-size: 22px; margin-bottom: 6px; }
.auth-form { margin-top: 22px; }
.auth-foot { color: var(--muted); font-size: 11.5px; margin-top: 20px; line-height: 1.6; }

/* -------------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    overflow-x: auto;
  }
  .brand { padding: 0; }
  .brand span:last-child { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-item { white-space: nowrap; padding: 8px 10px; }
  .sidebar-foot { margin-top: 0; margin-left: auto; display: flex; align-items: center; gap: 8px; }
  .user-chip { display: none; }
  .main { padding: 20px 16px 40px; }
  .topbar h1 { font-size: 22px; }
  .topbar { align-items: flex-start; }
}

@media (max-width: 620px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .field-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar { align-items: stretch; }
  .select-wrap { width: 100%; }
  .topbar { flex-direction: column; }
  .topbar .btn { width: 100%; }
  .url-cell { max-width: 160px; }
}
