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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #232733;
  --border: #2e3341;
  --text: #e4e7ef;
  --text-muted: #8b91a5;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

/* Navbar */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-content { display: flex; align-items: center; justify-content: space-between; }
.logo { font-size: 1.4rem; font-weight: 700; color: var(--text); letter-spacing: -0.5px; }
.logo:hover { text-decoration: none; color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 16px; }
.nav-link { color: var(--text-muted); font-size: 0.9rem; }
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-user { color: var(--primary); font-size: 0.9rem; font-weight: 500; }
.btn-link { background: none; border: none; cursor: pointer; font: inherit; }
.inline { display: inline; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: var(--radius); font-size: 0.9rem;
  font-weight: 500; border: none; cursor: pointer; transition: all 0.15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary-sm { background: var(--primary); color: white; padding: 6px 14px; border-radius: var(--radius); font-size: 0.85rem; }
.btn-outline { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 32px; font-size: 1rem; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.9rem; font-family: var(--font);
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 200px; }
.flex-2 { flex: 2; min-width: 300px; }
.checkbox-label { display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: auto; }

/* Alert */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.3); color: #fca5a5; }

/* Hero */
.hero { text-align: center; padding: 80px 0 60px; }
.hero h1 { font-size: 2.8rem; font-weight: 700; letter-spacing: -1px; margin-bottom: 16px; }
.hero-sub { font-size: 1.15rem; color: var(--text-muted); margin-bottom: 32px; max-width: 500px; margin-left: auto; margin-right: auto; }
.hero-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 60px; }
.features-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; text-align: left; }
.feature-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px;
}
.feature-card h3 { font-size: 1rem; margin-bottom: 8px; }
.feature-card p { font-size: 0.85rem; color: var(--text-muted); }

/* Auth pages */
.auth-page { display: flex; justify-content: center; padding: 60px 0; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 40px; width: 100%; max-width: 420px;
}
.auth-card h2 { margin-bottom: 24px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-muted); }

/* Dashboard */
.dashboard { padding: 30px 0; }
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.create-link-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 24px;
}
.create-link-card h3 { margin-bottom: 16px; font-size: 1rem; }

.links-toolbar { margin-bottom: 20px; }
.search-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input {
  flex: 1; min-width: 200px; padding: 8px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.85rem;
}
.search-input:focus { outline: none; border-color: var(--primary); }
.sort-select {
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 0.85rem;
}

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; }

.link-card {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin-bottom: 8px; gap: 16px; flex-wrap: wrap;
}
.link-info { flex: 1; min-width: 0; }
.link-short { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.short-url { font-weight: 600; font-size: 0.95rem; color: var(--primary); word-break: break-all; }
.btn-copy {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 4px; border-radius: 4px; font-size: 0.75rem; display: flex; align-items: center;
}
.btn-copy:hover { color: var(--text); background: var(--surface-2); }
.link-dest { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 500px; }
.link-stats { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.click-count { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }

/* Badges */
.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; font-weight: 500; white-space: nowrap; }
.badge-lock { background: rgba(99,102,241,0.15); color: var(--primary); }
.badge-inactive { background: rgba(239,68,68,0.15); color: #fca5a5; }

/* Link detail */
.detail-page { padding: 30px 0; }
.detail-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px; gap: 20px; flex-wrap: wrap;
}
.detail-header h2 { margin-bottom: 8px; }
.detail-urls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.9rem; }
.arrow { color: var(--text-muted); }
.dest-url { color: var(--text-muted); word-break: break-all; }
.detail-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 8px; }
.detail-actions { text-align: right; }
.big-stat { font-size: 2.5rem; font-weight: 700; color: var(--primary); display: block; }
.big-stat-label { font-size: 0.8rem; color: var(--text-muted); }

.detail-edit-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; margin-bottom: 24px;
}
.detail-edit-card h3 { margin-bottom: 16px; font-size: 1rem; }
.form-actions { display: flex; gap: 10px; align-items: center; }

/* Charts */
.charts-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.chart-card h3 { font-size: 0.9rem; margin-bottom: 16px; color: var(--text-muted); }
.chart-wide { grid-column: 1 / -1; }

/* QR Modal */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
}
.modal-content {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; min-width: 320px; z-index: 1;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
  background: none; border: none; color: var(--text-muted); font-size: 1.5rem;
  cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { display: flex; justify-content: center; }
.modal-body canvas { border-radius: 6px; }
.modal-footer { display: flex; justify-content: center; margin-top: 16px; }

/* QR section on detail page */
.qr-section { margin-bottom: 24px; }
.qr-section .chart-card { display: inline-flex; flex-direction: column; align-items: center; }

/* Error pages */
.error-page { text-align: center; padding: 80px 0; }
.error-page h1 { font-size: 4rem; font-weight: 700; color: var(--primary); margin-bottom: 12px; }
.error-page p { color: var(--text-muted); margin-bottom: 24px; }

/* Responsive */
@media (max-width: 640px) {
  .hero h1 { font-size: 2rem; }
  .form-row { flex-direction: column; }
  .flex-1, .flex-2 { min-width: 100%; }
  .link-card { flex-direction: column; align-items: flex-start; }
  .link-stats { width: 100%; justify-content: space-between; }
}
