*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e6e7ee;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 8px 24px rgba(17, 24, 39, 0.06);
  --shadow-lg: 0 24px 60px rgba(17, 24, 39, 0.2);
  --scroll: rgba(17, 24, 39, 0.2);
}

* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-button { display: none; }

body { margin: 0; font-family: "Inter", system-ui, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
body.no-scroll { overflow: hidden; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.6; cursor: wait; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.ellipsis { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.grad { background: linear-gradient(90deg, #6366f1, #ec4899); -webkit-background-clip: text; background-clip: text; color: transparent; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; white-space: nowrap; text-decoration: none; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.ghost { background: var(--surface); border-color: var(--border); }
.btn.ghost:hover { border-color: var(--text); }
.icon-btn { width: 36px; height: 36px; border: none; border-radius: 10px; background: none; font-size: 1rem; }
.icon-btn:hover { background: var(--bg); }
.error { margin: 10px 0 0; padding: 10px 14px; border-radius: 10px; background: #fef2f2; color: #b91c1c; font-size: 0.9rem; text-align: left; }

.nav { max-width: 1040px; margin: 0 auto; padding: 18px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { font-size: 1.35rem; font-weight: 800; text-decoration: none; letter-spacing: -0.03em; }

/* Hero */
.hero { max-width: 760px; margin: 0 auto; padding: 28px 16px 24px; text-align: center; }
.hero h1 { margin: 0 0 10px; font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1.1; }
.create { margin-top: 24px; padding: 10px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border); }
.create-row { display: flex; gap: 8px; }
.create-row input { flex: 1; min-width: 0; height: 52px; padding: 0 16px; border-radius: 14px; border: 1px solid transparent; background: var(--bg); outline: none; font-size: 1rem; }
.create-row input:focus { border-color: var(--primary); background: var(--surface); }
.create-row .btn { height: 52px; padding: 0 26px; border-radius: 14px; font-size: 1rem; }
.alias-row { display: flex; align-items: center; gap: 6px; padding: 10px 8px 4px; font-size: 0.85rem; flex-wrap: wrap; }
.prefix { margin-left: auto; color: var(--muted); font-weight: 600; }
.alias-row input { width: 160px; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); outline: none; }
.alias-row input:focus { border-color: var(--primary); }

.created { display: flex; align-items: center; gap: 16px; margin-top: 16px; padding: 14px 16px; border-radius: 18px; background: linear-gradient(135deg, #eef2ff, #fdf2f8); border: 1px solid #e0e7ff; text-align: left; animation: rise 0.25s ease; }
.created img { border-radius: 10px; background: #fff; padding: 4px; }
.created-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#createdLink { font-size: 1.25rem; font-weight: 800; color: var(--primary); text-decoration: none; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* List */
.container { max-width: 1040px; margin: 0 auto; padding: 8px 16px 56px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 12px; }
.section-head h2 { margin: 0; font-size: 1.3rem; }
.filter { height: 40px; width: 220px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); outline: none; }
.summary-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.summary-card { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.summary-card strong { font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-list { display: flex; flex-direction: column; gap: 10px; }
.link-row { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); transition: box-shadow 0.15s; }
.link-row:hover { box-shadow: var(--shadow); }
.row-qr { width: 52px; height: 52px; flex-shrink: 0; border-radius: 8px; border: 1px solid var(--border); }
.link-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.short { font-weight: 800; color: var(--primary); text-decoration: none; font-size: 1.02rem; }
.short:hover { text-decoration: underline; }
.target { font-size: 0.88rem; }
.clicks { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.clicks strong { font-size: 1.35rem; }
.row-actions { display: flex; align-items: center; gap: 6px; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 48px 16px; color: var(--muted); }
.empty span { font-size: 2.6rem; }

/* Stats panel */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(17, 24, 39, 0.4); backdrop-filter: blur(2px); }
.stats { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(760px, 100vw); display: flex; flex-direction: column; background: var(--bg); box-shadow: var(--shadow-lg); animation: slide 0.22s ease; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.stats-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 22px; background: var(--surface); border-bottom: 1px solid var(--border); }
.stats-head > div { min-width: 0; }
.stats-head h2 { margin: 0 0 2px; font-size: 1.4rem; color: var(--primary); }
.stats-body { flex: 1; overflow-y: auto; padding: 18px 22px 32px; display: flex; flex-direction: column; gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.kpi strong { font-size: 1.35rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-card { padding: 16px 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.chart-card h3 { margin: 0 0 12px; font-size: 0.95rem; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-head h3 { margin: 0; }
.range { display: flex; padding: 3px; border-radius: 10px; background: var(--bg); }
.range button { padding: 4px 10px; border: none; border-radius: 8px; background: none; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.range button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.line-wrap { height: 220px; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.donut-wrap { height: 170px; }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rank-top { display: flex; justify-content: space-between; gap: 8px; font-size: 0.85rem; margin-bottom: 4px; }
.rank-top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 6px; border-radius: 99px; background: var(--bg); overflow: hidden; }
.rank-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #6366f1, #ec4899); }
.table-wrap { overflow-x: auto; }
.recent { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.recent th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.recent td { padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.qr-card { display: flex; align-items: center; gap: 18px; }
.qr-card img { border-radius: 12px; border: 1px solid var(--border); }
.qr-card p { margin: 0 0 10px; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%); padding: 10px 18px; border-radius: 12px; background: var(--text); color: #fff; box-shadow: var(--shadow-lg); font-size: 0.9rem; }
.footer { padding: 24px 16px 40px; text-align: center; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 720px) {
  .nav .small { display: none; }
  .create-row { flex-direction: column; }
  .prefix { margin-left: 0; }
  .alias-row input { flex: 1; width: auto; }
  .created { flex-wrap: wrap; }
  .link-row { flex-wrap: wrap; gap: 12px; }
  .row-qr { display: none; }
  .link-main { flex-basis: calc(100% - 90px); }
  .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .stats-body, .stats-head { padding-left: 14px; padding-right: 14px; }
  .filter { width: 150px; }
  .summary-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .summary-card strong { font-size: 1.1rem; }
}
