/* ============ TOKENS ============ */
:root {
  --bg: #f7f8fc;
  --bg-2: #ffffff;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: #ede9fe;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --info: #0891b2;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.1);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}
[data-theme="dark"] {
  --bg: #0f0f17;
  --bg-2: #16161f;
  --surface: #1c1c28;
  --surface-2: #232332;
  --border: #2d2d3f;
  --border-strong: #3d3d55;
  --text: #f4f4f9;
  --text-muted: #a0a0b8;
  --text-subtle: #707086;
  --primary: #a78bfa;
  --primary-hover: #8b5cf6;
  --primary-soft: rgba(167,139,250,.15);
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --info: #22d3ee;
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background .2s, color .2s;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.02em; font-weight: 700; line-height: 1.2; }
p { margin: 0; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 24px; }
.main { min-height: calc(100vh - 130px); }

/* ============ NAV ============ */
.nav {
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(20px);
  background: rgba(255,255,255,.85);
}
[data-theme="dark"] .nav { background: rgba(22,22,31,.85); }
.nav-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; height: 64px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.05rem; color: var(--text);
}
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #7c3aed, #06b6d4);
  display: grid; place-items: center;
  box-shadow: 0 4px 12px -4px rgba(124,58,237,.5);
}
.logo-mark svg { width: 16px; height: 16px; stroke: #fff; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links > a {
  color: var(--text-muted); font-size: .89rem; font-weight: 500;
  padding: 8px 14px; border-radius: 8px;
  transition: .2s;
}
.nav-links > a:hover, .nav-links > a.active { color: var(--text); background: var(--primary-soft); }
.nav-user {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border); border-radius: 999px;
  margin-left: 8px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .8rem;
}
.nav-user-info { display: flex; flex-direction: column; line-height: 1.15; }
.nav-user-info span { font-size: .82rem; font-weight: 600; }
.nav-user-info small { font-size: .7rem; color: var(--text-muted); }
.theme-toggle {
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); display: grid; place-items: center;
  transition: .2s; position: relative; padding: 0; margin-left: 4px;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle svg {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  position: absolute; transition: opacity .3s, transform .3s;
}
.theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(.5); }
.theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(.5); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: 0; cursor: pointer; text-decoration: none;
  font-weight: 600; font-size: .92rem; white-space: nowrap;
  padding: 10px 18px; border-radius: 10px;
  transition: .15s; font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 12px -4px rgba(124,58,237,.4);
}
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 6px 18px -6px rgba(124,58,237,.5); }
.btn-ghost {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: .82rem; border-radius: 8px; }
.btn-full { width: 100%; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input {
  width: 100%; padding: 11px 14px; font-family: inherit; font-size: .94rem;
  color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; outline: none; transition: .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.input::placeholder { color: var(--text-subtle); }
textarea.input { resize: vertical; font-family: inherit; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error { display: none; margin-top: 10px; padding: 10px 12px; background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; border-radius: 8px; font-size: .85rem; }
.form-error.show { display: block; }
[data-theme="dark"] .form-error { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.3); }
.pw-hint { font-size: .75rem; color: var(--text-muted); margin-top: 6px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--text-muted); }
.slug-wrap { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow: hidden; }
.slug-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.slug-prefix { display: flex; align-items: center; padding: 0 10px; background: var(--surface-2); color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-size: .8rem; border-right: 1px solid var(--border); }
.slug-wrap .input { border: 0; box-shadow: none !important; }

/* ============ LAYOUT ============ */
.dashboard { padding: 40px 24px 80px; }
.dashboard.narrow { max-width: 800px; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.page-header h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); letter-spacing: -.03em; }
.page-header p { color: var(--text-muted); font-size: .93rem; margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ HERO ============ */
.hero {
  padding: 80px 0 60px;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--border);
}
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: .78rem; font-weight: 500; color: var(--text-muted);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.hero h1 {
  font-size: clamp(2.2rem, 5.5vw, 3.8rem); font-weight: 800;
  letter-spacing: -.04em; line-height: 1.05;
  margin: 24px auto 0; max-width: 900px;
}
.grad { background: linear-gradient(100deg, #7c3aed, #0891b2, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-lede { max-width: 580px; margin: 18px auto 0; font-size: 1.05rem; color: var(--text-muted); }

.shortener-card {
  max-width: 680px; margin: 32px auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 14px;
  box-shadow: var(--shadow-lg); text-align: left;
}
.field {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 6px 6px 14px;
  transition: .2s;
}
.field:focus-within { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.field-icon { width: 18px; height: 18px; stroke: var(--text-subtle); fill: none; stroke-width: 2; flex-shrink: 0; }
.field input {
  flex: 1; min-width: 0; border: 0; background: transparent;
  font-family: inherit; font-size: .95rem; color: var(--text);
  padding: 12px 4px; outline: none;
}
.field input::placeholder { color: var(--text-subtle); }
.result {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-top: 12px; padding: 14px;
  border-radius: 10px;
  background: var(--primary-soft); border: 1px solid rgba(124,58,237,.3);
}
.result-label { font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); margin-bottom: 4px; }
.result-link { font-size: 1rem; font-weight: 700; color: var(--primary); font-family: 'JetBrains Mono', monospace; word-break: break-all; }
.result-original { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 3px; }
.hero-actions { margin-top: 24px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

.section { padding: 80px 0; }
.section-head { text-align: center; max-width: 640px; margin: 0 auto 48px; }
.eyebrow { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--primary); }
.section-head h2 { font-size: clamp(1.7rem, 3.5vw, 2.4rem); margin-top: 12px; letter-spacing: -.03em; }
.section-head p { color: var(--text-muted); margin-top: 12px; }
.features-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.feature-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px; transition: .2s;
}
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.feature-icon { font-size: 1.8rem; margin-bottom: 14px; }
.feature-card h3 { font-size: 1rem; margin-bottom: 6px; }
.feature-card p { color: var(--text-muted); font-size: .9rem; }

/* ============ AUTH ============ */
.auth-wrap { min-height: calc(100vh - 130px); display: grid; place-items: center; padding: 60px 24px; }
.auth-card {
  width: 100%; max-width: 440px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-header { text-align: center; margin-bottom: 24px; }
.auth-header h1 { font-size: 1.5rem; letter-spacing: -.02em; margin-bottom: 6px; }
.auth-header p { color: var(--text-muted); font-size: .9rem; }
.auth-tabs {
  display: flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px; margin-bottom: 20px;
}
.auth-tab {
  flex: 1; padding: 9px 12px; border: 0; background: transparent;
  color: var(--text-muted); font-size: .86rem; font-weight: 600;
  border-radius: 7px; transition: .15s;
}
.auth-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.auth-footer { text-align: center; margin-top: 18px; font-size: .85rem; color: var(--text-muted); }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ============ STATS ============ */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.stat-label { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; color: var(--text); line-height: 1.1; }

/* ============ CARDS ============ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px; margin-bottom: 20px;
}
.card.create-card { padding: 20px; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-title span { font-size: .78rem; font-weight: 500; color: var(--text-muted); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.card-header h2 { font-size: 1rem; font-weight: 700; }
.badge-count {
  font-size: .75rem; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border);
}
.card-danger { border-color: #fecaca; }
[data-theme="dark"] .card-danger { border-color: rgba(248,113,113,.3); }
.text-muted { color: var(--text-muted); font-size: .9rem; }
.text-link { color: var(--primary); }

.create-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.create-form .form-group { margin-bottom: 0; }
.create-form .btn { padding: 11px 20px; }

/* ============ LINK ROWS ============ */
.link-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px; border-top: 1px solid var(--border);
  transition: background .15s; flex-wrap: wrap;
}
.link-row:first-child { border-top: 0; }
.link-row:hover { background: var(--surface-2); }
.link-info { flex: 1; min-width: 0; }
.link-title { font-weight: 600; color: var(--text); font-size: .94rem; margin-bottom: 2px; }
.link-slug { font-family: 'JetBrains Mono', monospace; font-size: .82rem; color: var(--primary); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.link-slug:hover { text-decoration: underline; }
.link-dest { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.link-clicks { flex-shrink: 0; text-align: right; min-width: 60px; }
.link-clicks b { display: block; font-size: 1.1rem; font-weight: 800; color: var(--text); }
.link-clicks span { font-size: .68rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.link-actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); display: grid; place-items: center;
  padding: 0; transition: .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
[data-theme="dark"] .icon-btn.danger:hover { background: rgba(248,113,113,.1); border-color: rgba(248,113,113,.3); }
.icon-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: .9rem; }

.analytics-panel { display: none; width: 100%; }
.analytics-panel.open { display: block; }
.stats-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stats-mini .stat-card { padding: 12px 14px; }
.stats-mini .stat-value { font-size: 1.3rem; }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.chart-title { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.chart { display: flex; align-items: flex-end; gap: 2px; height: 100px; }
.chart-bar { flex: 1; background: var(--primary); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .8; transition: opacity .15s; }
.chart-bar:hover { opacity: 1; }
.chart-stack { display: flex; align-items: flex-end; gap: 2px; height: 140px; }
.chart-bar-stack { flex: 1; display: flex; align-items: flex-end; gap: 1px; height: 100%; }
.chart-bar-v { flex: 1; background: var(--primary); border-radius: 2px 2px 0 0; min-height: 2px; }
.chart-bar-c { flex: 1; background: var(--info); border-radius: 2px 2px 0 0; min-height: 2px; }
.chart-legend { display: flex; gap: 16px; margin-top: 10px; font-size: .78rem; color: var(--text-muted); }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.breakdowns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.breakdown { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.breakdown-title { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.breakdown-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.breakdown-row { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; }
.breakdown-row b { font-family: 'JetBrains Mono', monospace; color: var(--text); }
.breakdown-empty { font-size: .82rem; color: var(--text-muted); }

/* ============ BIO EDITOR ============ */
.bio-link-row { display: flex; align-items: center; gap: 12px; padding: 12px; border-top: 1px solid var(--border); }
.bio-link-row:first-child { border-top: 0; }
.bio-link-info { flex: 1; min-width: 0; }
.bio-link-title { font-weight: 600; font-size: .92rem; }
.bio-link-dest { font-size: .78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.social-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.publish-bar { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.info-list { display: grid; gap: 10px; }
.info-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--text-muted); }
.role-admin { color: #f59e0b; font-weight: 600; }

/* ============ TABLES ============ */
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th {
  text-align: left; padding: 10px 8px;
  font-size: .7rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 8px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--surface-2); }

/* ============ MODAL ============ */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 28px 24px; max-width: 500px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card h3 { margin-bottom: 16px; font-size: 1.15rem; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translate(-50%, 100px);
  padding: 12px 22px; border-radius: 10px;
  background: #111827; color: #fff; font-size: .88rem; font-weight: 500;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,.4);
  opacity: 0; transition: .3s;
  z-index: 200; max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

/* ============ FOOTER ============ */
.footer { border-top: 1px solid var(--border); padding: 20px 0; background: var(--bg-2); }
.footer-inner { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; font-size: .83rem; color: var(--text-muted); }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .features-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .nav-links > a:not(.btn) { display: none; }
  .nav-user-info { display: none; }
  .dashboard { padding: 24px 16px 60px; }
  .stats-grid { grid-template-columns: 1fr; }
  .features-grid { grid-template-columns: 1fr; }
  .create-form { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .breakdowns { grid-template-columns: 1fr; }
  .stats-mini { grid-template-columns: 1fr; }
  .social-row { grid-template-columns: 1fr; }
  .result { flex-direction: column; align-items: stretch; }
  .hero { padding: 50px 0 40px; }
  .section { padding: 50px 0; }
  .nav-user { display: none; }
}