:root {
  --bg: #f6f7fb;
  --bg2: #ffffff;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand2: #06b6d4;
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --chip: #eef2ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(17, 24, 39, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --bg2: #11172b; --card: #131a30; --text: #e5e7eb; --muted: #9aa3b5; --line: #24304d;
    --chip: #1e2647; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --bg2: #11172b; --card: #131a30; --text: #e5e7eb; --muted: #9aa3b5; --line: #24304d;
  --chip: #1e2647; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
code { background: var(--chip); padding: 1px 6px; border-radius: 6px; }
pre { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; overflow: auto; font-size: 13px; }
pre code { background: none; padding: 0; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.8rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; }
.hidden { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg2) 92%, transparent);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); font-size: 1.1rem; }
.logo img { width: 28px; height: 28px; }
.logo:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
.nav a, .nav button.link { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--chip); text-decoration: none; }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; cursor: pointer; color: var(--text); font-size: 14px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.narrow { max-width: 460px; margin: 0 auto; }
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.center-page .card { width: 100%; text-align: center; }
.big-emoji { font-size: 48px; }
.target-box { word-break: break-all; background: var(--chip); padding: 10px; border-radius: 10px; font-family: ui-monospace, monospace; font-size: 13px; }

/* Hero */
.hero { text-align: center; padding: 36px 0 18px; }
.hero h1 { font-size: clamp(1.8rem, 4.5vw, 2.8rem); letter-spacing: -.02em; }
.grad { background: linear-gradient(90deg, var(--brand), var(--brand2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.counters { display: flex; justify-content: center; gap: 28px; margin-top: 14px; flex-wrap: wrap; }
.counters b { display: block; font-size: 1.5rem; }

/* Form */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg2); color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
textarea { min-height: 120px; resize: vertical; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.row { display: flex; align-items: center; flex-wrap: wrap; }
.gap { gap: 8px; } .gap2 { gap: 16px; }
.grow { flex: 1; min-width: 0; }
.shorten { display: flex; gap: 8px; }
.shorten input { font-size: 1.05rem; padding: 14px 16px; }
.hint { font-size: .82rem; margin-top: 4px; }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--bad); }
details.adv { margin-top: 12px; }
details.adv summary { cursor: pointer; color: var(--brand); font-weight: 600; }
fieldset { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin: 12px 0 0; }
legend { padding: 0 6px; font-weight: 700; font-size: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: progress; }

.alert { padding: 10px 12px; border-radius: 10px; background: var(--chip); }
.alert.error { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.alert.success { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }

/* Kết quả */
.result { display: grid; grid-template-columns: 1fr 180px; gap: 16px; align-items: center; margin-top: 16px; }
.result img { width: 180px; height: 180px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.short-url { font-size: 1.3rem; font-weight: 800; word-break: break-all; }

/* Thẻ số liệu */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }

/* Bảng */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td .tgt { color: var(--muted); font-size: .85rem; max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--chip); }
.badge.active { color: var(--ok); } .badge.expired, .badge.limit { color: var(--warn); } .badge.disabled { color: var(--bad); }

/* Biểu đồ */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 10px; }
.bars .bar { display: grid; grid-template-columns: 110px 1fr 48px; gap: 8px; align-items: center; margin: 6px 0; font-size: .88rem; }
.bars .track { background: var(--chip); border-radius: 6px; height: 10px; overflow: hidden; }
.bars .track, .bars .fill { display: block; }
.bars .fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand2)); border-radius: 6px; }
.bars .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); }
.features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 24px; }
.feature { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.feature .e { font-size: 22px; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 12px; }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px; }
kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: .8em; }

@media (max-width: 760px) {
  .grid2, .grid3, .grid4, .features { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shorten { flex-direction: column; }
  .result { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .nav { gap: 0; }
  .nav a { padding: 6px 7px; font-size: .9rem; }
  .bars .bar { grid-template-columns: 90px 1fr 40px; }
  .hide-sm { display: none; }
}

/* ===== v2: realtime, bio, heatmap ===== */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 0 0 rgba(239,68,68,.6); animation: pulse 1.6s infinite; vertical-align: middle; }
@keyframes pulse { 70% { box-shadow: 0 0 0 9px rgba(239,68,68,0); } 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); } }
.live-pill { margin-left: auto; font-size: .82rem; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.live-box b { font-size: 1.1rem !important; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; margin-bottom: 12px; }
.feed-card { max-height: 640px; overflow: auto; }
.feed-item { border-left: 3px solid var(--brand); padding: 6px 10px; margin: 8px 0; background: var(--chip); border-radius: 0 8px 8px 0; animation: slideIn .35s ease; }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }
tr.flash td { animation: flash 1.2s ease; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--ok) 35%, transparent); } 100% { background: transparent; } }
.bump { animation: bump .6s ease; display: inline-block; }
@keyframes bump { 30% { transform: scale(1.35); color: var(--ok); } }
.bio-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.bio-item { padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; }
.bio-item.on { border-color: var(--brand); background: var(--chip); }
.phone { position: sticky; top: 80px; border: 10px solid #111827; border-radius: 36px; height: 600px; overflow: hidden; box-shadow: var(--shadow); }
.phone-in { height: 100%; overflow: auto; padding: 36px 16px; text-align: center; }
.phone-in h3 { margin: 6px 0; } .pv-av { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; font-size: 36px; margin: 0 auto; background: rgba(255,255,255,.2); }
.pv-btn { margin: 10px 0; padding: 12px; border-radius: 14px; font-weight: 700; border: 1.5px solid currentColor; background: rgba(255,255,255,.14); }
.theme-aurora { background: linear-gradient(135deg,#4f46e5,#06b6d4 55%,#10b981); color: #fff; }
.theme-midnight { background: radial-gradient(circle at 20% 0,#312e81,#0b1020 60%); color: #e5e7eb; }
.theme-sunset { background: linear-gradient(160deg,#f97316,#db2777 60%,#7c3aed); color: #fff; }
.theme-minimal { background: #f8fafc; color: #0f172a; }
.theme-forest { background: linear-gradient(180deg,#064e3b,#065f46 50%,#14532d); color: #ecfdf5; }
@media (max-width: 860px) { .dash-grid, .bio-grid { grid-template-columns: 1fr; } .phone { position: static; height: 520px; } }
