@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary: #0F0C29;
  --primary-light: #302B63;
  --secondary: #24243E;
  --accent: #8E44AD;
  --accent-light: #F5F5F5;
  --bg: #F0F4F8;
  --bg-card: #FFFFFF;
  --bg-elevated: #FAFBFC;
  --text: #1A2332;
  --text-secondary: #5A6B7F;
  --text-muted: #8E9BAE;
  --border: #E2E8F0;
  --border-light: #EDF2F7;
  --success: #10B981;
  --success-bg: #ECFDF5;
  --error: #EF4444;
  --error-bg: #FEF2F2;
  --shadow-sm: 0 1px 3px rgba(13, 71, 161, 0.06);
  --shadow-md: 0 4px 12px rgba(13, 71, 161, 0.08);
  --shadow-lg: 0 8px 24px rgba(13, 71, 161, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

::selection {
  background: var(--accent);
  color: white;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== APP CONTAINER ===== */
.app-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px 80px;
  min-height: 100vh;
}

/* ===== HEADER ===== */
.app-header {
  padding: 32px 0 24px;
  text-align: center;
  position: relative;
}

.app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
}

.app-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
  font-weight: 400;
}

/* ===== TAB NAVIGATION ===== */
.tab-nav {
  display: flex;
  gap: 4px;
  margin: 24px 0;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 4px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--primary);
  background: var(--bg);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(13, 71, 161, 0.25);
}

.tab-icon {
  font-size: 1rem;
}

/* ===== SHORTENER ===== */
.shortener-container {
  animation: fadeInUp 0.4s ease both;
}

.shortener-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.card-header {
  margin-bottom: 24px;
}

.card-header h2 {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}

.card-description {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 16px;
  flex: 1;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  pointer-events: none;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg-elevated);
  transition: all 0.2s ease;
  outline: none;
}

.form-input.with-icon {
  padding-left: 40px;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.15);
  background: var(--bg-card);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 16px;
}

.message {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.error-message {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(13, 71, 161, 0.25);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(13, 71, 161, 0.3);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-shorten {
  margin-top: 8px;
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ===== SUCCESS CARD ===== */
.success-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  margin-top: 20px;
  border-top: 3px solid var(--success);
  animation: fadeInUp 0.3s ease both;
}

.success-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.success-icon {
  font-size: 1.5rem;
}

.success-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--success);
}

.short-link-display {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.short-link-code {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--primary);
  flex: 1;
}

.btn-copy {
  padding: 6px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-copy:hover {
  background: var(--primary-light);
}

.original-url-display {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 10px;
  word-break: break-all;
}

.success-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg);
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: var(--border-light);
  border-color: var(--primary);
}

.btn-ghost {
  padding: 10px 20px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ghost:hover {
  color: var(--primary);
  background: var(--bg);
}

/* ===== STATS STRIP ===== */
.stats-strip {
  display: flex;
  gap: 16px;
  margin-top: 20px;
}

.stat-item {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stat-number {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
}

/* ===== LINKS LIST ===== */
.links-container {
  animation: fadeInUp 0.4s ease both;
}

.links-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.95rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 10px 16px 10px 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-card);
  outline: none;
  transition: all 0.2s ease;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.15);
}

.toolbar-controls {
  display: flex;
  gap: 8px;
}

.sort-select,
.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-card);
  cursor: pointer;
  outline: none;
}

.sort-select:focus,
.filter-select:focus {
  border-color: var(--accent);
}

.links-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 500;
}

/* ===== LINK CARDS ===== */
.links-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.link-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  animation: fadeInUp 0.4s ease both;
}

.link-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent-light);
}

.link-card-top {
  margin-bottom: 10px;
}

.link-code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.link-code {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--primary);
}

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

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--border);
}

.btn-delete:hover {
  background: var(--error-bg);
}

.btn-analytics:hover {
  background: rgba(66, 165, 245, 0.12);
}

.btn-simulate {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s ease;
}

.btn-simulate:hover {
  background: var(--success-bg);
}

.btn-simulate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.original-url {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  word-break: break-all;
  transition: color 0.15s ease;
}

.original-url:hover {
  color: var(--primary);
}

.link-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.link-meta {
  display: flex;
  gap: 12px;
  align-items: center;
}

.click-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(13, 71, 161, 0.08);
  padding: 3px 10px;
  border-radius: 20px;
}

.time-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tag-list {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tag-chip {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--secondary);
  background: rgba(25, 118, 210, 0.08);
  padding: 2px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag-chip:hover {
  background: rgba(25, 118, 210, 0.16);
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.no-clicks-state {
  text-align: center;
  padding: 48px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-top: 20px;
}

.no-clicks-state h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.no-clicks-state p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 400px;
  margin: 0 auto;
}

/* ===== SKELETON LOADING ===== */
.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 20px;
  border: 1px solid var(--border);
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  margin-bottom: 10px;
}

.skeleton-line.wide { width: 80%; }
.skeleton-line.medium { width: 55%; }
.skeleton-line.narrow { width: 30%; }

/* ===== ANALYTICS ===== */
.analytics-container {
  animation: fadeInUp 0.4s ease both;
}

.btn-back {
  padding: 8px 16px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-bottom: 16px;
}

.btn-back:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.analytics-header-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--primary);
  margin-bottom: 20px;
}

.analytics-code {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--primary);
}

.analytics-url {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  word-break: break-all;
  margin-top: 4px;
}

.analytics-url:hover {
  color: var(--primary);
}

.analytics-summary {
  display: flex;
  gap: 20px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.summary-stat {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.summary-number {
  display: block;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

.summary-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ===== CHARTS ===== */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.charts-grid .chart-card:first-child {
  grid-column: 1 / -1;
}

.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.chart-wrapper {
  position: relative;
  height: 220px;
}

/* ===== CLICK LOG TABLE ===== */
.click-log-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.click-log-table {
  overflow-x: auto;
}

.table-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  padding: 10px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s ease;
}

.table-row:hover {
  background: var(--bg);
}

.referrer-badge {
  font-weight: 500;
  color: var(--primary);
}

.device-badge {
  font-weight: 500;
  color: var(--text);
}

/* ===== FOOTER ===== */
.app-footer {
  text-align: center;
  padding: 32px 0 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .app-container {
    padding: 0 12px 80px;
  }

  .app-title {
    font-size: 1.6rem;
  }

  .shortener-card {
    padding: 20px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .stats-strip {
    flex-direction: column;
    gap: 8px;
  }

  .stat-item {
    padding: 14px;
  }

  .stat-number {
    font-size: 1.4rem;
  }

  .tab-label {
    display: none;
  }

  .tab-icon {
    font-size: 1.2rem;
  }

  .tab-btn {
    padding: 12px;
  }

  .toolbar-controls {
    flex-wrap: wrap;
    width: 100%;
  }

  .sort-select,
  .filter-select {
    flex: 1;
    min-width: 0;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .analytics-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .success-actions {
    flex-direction: column;
  }

  .link-code-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .table-header,
  .table-row {
    grid-template-columns: 1fr 0.8fr 0.6fr;
    font-size: 0.78rem;
  }
}

/* ===== FOCUS STYLES ===== */
.btn-primary:focus-visible,
.btn-secondary:focus-visible,
.btn-ghost:focus-visible,
.btn-back:focus-visible,
.btn-icon:focus-visible,
.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-input:focus-visible,
.search-input:focus-visible,
.sort-select:focus-visible,
.filter-select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(66, 165, 245, 0.15);
}
```

<!-- WALKTHROUGH_SCRIPT:
[
  {"step": 1, "narration": "Welcome to Sniplink, your personal link shortener. Let's create your first short link.", "view": "user", "highlight_selector": ".shortener-card", "wait_for": "tap_to_continue"},
  {"step": 2, "narration": "Paste any long URL into the Destination URL field. You can optionally set a custom alias and tags.", "view": "user", "highlight_selector": "#url-input", "wait_for": "user_interaction"},
  {"step": 3, "narration": "Click Shorten Link to generate your short code. You'll see a confirmation with a copy button.", "view": "user", "highlight_selector": ".btn-shorten", "wait_for": "user_interaction"},
  {"step": 4, "narration": "Your link is created! Copy the short code and share it anywhere. The stats strip shows your running totals.", "view": "user", "highlight_selector": ".success-card", "wait_for": "tap_to_continue"},
  {"step": 5, "narration": "Switch to My Links to see all your shortened links. Search, sort, and filter by tags.", "view": "user", "highlight_selector": ".tab-btn:nth-child(2)", "wait_for": "user_interaction"},
  {"step": 6, "narration": "Each link card shows its short code, click count, and creation date. Use the 👆 button to simulate clicks for testing.", "view": "user", "highlight_selector": ".link-card", "wait_for": "tap_to_continue"},
  {"step": 7, "narration": "Click the 📊 icon on any link to view detailed analytics — click charts, referrer breakdown, and device stats.", "view": "user", "highlight_selector": ".btn-analytics", "wait_for": "user_interaction"},
  {"step": 8, "narration": "The Analytics view shows clicks over time, referrer sources, device distribution, and a detailed click log.", "view": "user", "highlight_selector": ".charts-grid", "wait_for": "tap_to_continue"}
]
-->

.chart-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.success-qr-row {
  margin-top: 16px;
  display: flex;
  justify-content: flex-start;
}

.qr-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.qr-card-header {
  width: 100%;
  display: flex;
  justify-content: center;
}

.qr-card-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.qr-code-image {
  width: 180px;
  height: 180px;
  border-radius: 10px;
  background: white;
  padding: 8px;
}

.qr-card-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.btn-share {
  background: var(--secondary);
}

.btn-share:hover {
  background: var(--primary-light);
}

.export-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.btn-export {
  width: auto;
}

@media (max-width: 640px) {
  .export-actions {
    flex-direction: column;
  }

  .btn-export {
    width: 100%;
  }
}
