/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0b0c10;
  --surface:   #13151a;
  --card:      #1a1d26;
  --card-hover:#1f2330;
  --border:    #282d3a;
  --border-light: #333846;

  --primary:   #6c63ff;
  --primary-d: #5a52e0;
  --primary-glow: rgba(108,99,255,.25);

  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --info:      #38bdf8;

  --text-1: #f0f2f8;
  --text-2: #8891aa;
  --text-3: #545c72;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;

  --sidebar-w: 220px;
  --font: 'Inter', system-ui, sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text-1); font-family: var(--font); font-size: 14px; line-height: 1.5; }

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
svg { fill: currentColor; }

/* ─── Layout ─────────────────────────────────────────────────── */
.app { display: flex; height: 100vh; }
.main { flex: 1; overflow-y: auto; background: var(--bg); }

/* ─── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-logo {
  font-size: 22px;
  font-weight: 700;
  padding: 24px 20px;
  color: var(--text-1);
  letter-spacing: -0.5px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span { color: var(--primary); }

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  transition: all .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--card); color: var(--text-1); }
.nav-item.active { background: var(--primary-glow); color: var(--primary); }

.sidebar-footer {
  padding: 16px 10px;
  border-top: 1px solid var(--border);
}
.btn-ghost-sm {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-3);
  font-size: 13px;
  transition: all .15s;
}
.btn-ghost-sm svg { width: 16px; height: 16px; }
.btn-ghost-sm:hover { color: var(--danger); background: rgba(239,68,68,.08); }

/* ─── Page wrapper ────────────────────────────────────────────── */
.page { padding: 32px 36px; max-width: 1200px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-title { font-size: 22px; font-weight: 700; }
.page-sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* ─── Stat Cards ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat-value { font-size: 32px; font-weight: 700; margin-top: 6px; }
.stat-value.green { color: var(--success); }
.stat-value.violet { color: var(--primary); }
.stat-value.blue { color: var(--info); }

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-1);
}

/* ─── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
td { color: var(--text-1); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--card-hover); }

.slug-cell { font-family: monospace; font-size: 13px; color: var(--primary); }
.url-cell { max-width: 240px; overflow: hidden; text-overflow: ellipsis; color: var(--text-2); font-size: 12px; }
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-green { background: rgba(34,197,94,.12); color: var(--success); }
.badge-red   { background: rgba(239,68,68,.12);  color: var(--danger); }
.badge-blue  { background: rgba(56,189,248,.12); color: var(--info); }

.actions { display: flex; gap: 6px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: all .15s;
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover         { background: var(--border); color: var(--text-1); }
.btn-icon.danger:hover  { background: rgba(239,68,68,.12); color: var(--danger); }
.btn-icon.success:hover { background: rgba(34,197,94,.12); color: var(--success); }

/* ─── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-1);
  outline: none;
  transition: border .15s;
}
.search-input:focus { border-color: var(--primary); }
.search-input::placeholder { color: var(--text-3); }

select.filter-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-2);
  outline: none;
  cursor: pointer;
}
select.filter-select:focus { border-color: var(--primary); }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  transition: all .15s;
  cursor: pointer;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-secondary { background: var(--card); color: var(--text-1); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--card-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-full { width: 100%; justify-content: center; }

/* ─── Forms ───────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-1);
  outline: none;
  transition: border .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11px; color: var(--text-3); margin-top: 4px; }

.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-3);
  margin: 20px 0 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-label::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.url-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: monospace;
  font-size: 11px;
  color: var(--text-2);
  word-break: break-all;
  min-height: 38px;
  margin-top: 4px;
}
.url-preview.has-url { color: var(--primary); }

/* Toggle */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.toggle-label { font-size: 13px; font-weight: 500; }
.toggle-sub   { font-size: 11px; color: var(--text-3); margin-top: 1px; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border); border-radius: 22px;
  transition: .2s;
}
.slider:before {
  content: ''; position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white; border-radius: 50%;
  transition: .2s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }

/* AB Rows */
.ab-row {
  display: grid;
  grid-template-columns: 1fr 80px 32px;
  gap: 8px; align-items: center;
  margin-bottom: 8px;
}
.ab-row input { width: 100%; }
.btn-remove {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--danger); font-size: 18px;
  transition: background .15s;
}
.btn-remove:hover { background: rgba(239,68,68,.1); }
.btn-add-ab {
  font-size: 12px; color: var(--primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--primary-d);
  width: 100%; text-align: center;
  transition: background .15s;
}
.btn-add-ab:hover { background: var(--primary-glow); }

/* ─── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,.6);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 20px;
  transition: all .15s;
}
.modal-close:hover { background: var(--border); color: var(--text-1); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ─── Login ───────────────────────────────────────────────────── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg);
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 360px;
  box-shadow: 0 32px 80px rgba(0,0,0,.5);
}
.login-logo { font-size: 32px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-sub { color: var(--text-2); text-align: center; font-size: 13px; margin-bottom: 28px; }
.login-error { color: var(--danger); font-size: 12px; text-align: center; margin-top: 10px; }

/* ─── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
  z-index: 200;
  transition: opacity .3s;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--danger);  color: var(--danger);  }

/* ─── Chart ───────────────────────────────────────────────────── */
.chart-container { position: relative; height: 240px; }

/* ─── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-3);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── Utilities ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-2); }
.text-sm { font-size: 12px; }
.mono { font-family: monospace; }

/* Copy link display */
.link-full {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: monospace; font-size: 12px;
  color: var(--text-2);
}
.link-full span { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* Analytics link selector */
.analytics-controls {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin-bottom: 20px;
}
.analytics-controls select { flex: 1; min-width: 200px; }

/* Referrer list */
.referrer-list { list-style: none; }
.referrer-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.referrer-list li:last-child { border-bottom: none; }
.referrer-bar-wrap { flex: 1; margin: 0 12px; height: 4px; background: var(--border); border-radius: 4px; }
.referrer-bar { height: 100%; background: var(--primary); border-radius: 4px; }

/* Mini stats in analytics */
.mini-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-bottom: 20px; }
.mini-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; }
.mini-stat .v { font-size: 24px; font-weight: 700; }
.mini-stat .l { font-size: 11px; color: var(--text-2); margin-top: 2px; }
