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

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e3e6ee;
  --text: #1f2433;
  --text-muted: #7a8199;
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --danger: #e74c3c;
  --success: #27ae60;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(31, 36, 51, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: none; border-radius: var(--radius); padding: 8px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background 0.15s; text-decoration: none; display: inline-block;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(0,0,0,0.06); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }

input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; font-family: inherit;
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}
label { display: block; font-weight: 600; font-size: 13px; color: var(--text); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 5px; font-weight: 400; }

.link-btn {
  background: none; border: none; color: var(--primary); cursor: pointer;
  font-size: 13px; margin-top: 12px; display: block; width: 100%; text-align: center;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- auth ---------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
  padding: 20px;
}
.auth-card {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  padding: 36px; width: 100%; max-width: 400px;
}
.auth-logo { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 24px; }
.auth-tabs {
  display: flex; background: var(--bg); border-radius: var(--radius);
  padding: 4px; margin-bottom: 20px;
}
.auth-tab {
  flex: 1; border: none; background: transparent; padding: 8px;
  border-radius: 6px; font-weight: 600; cursor: pointer; color: var(--text-muted);
}
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.auth-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.5; }
.auth-error {
  margin-top: 14px; padding: 10px 12px; border-radius: var(--radius);
  background: #fdecea; color: #c0392b; font-size: 13px;
}

/* ---------- app layout ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 230px; background: #23283b; color: #cdd2e4;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-logo { font-size: 17px; font-weight: 800; color: #fff; padding: 20px 18px 14px; }
.sidebar-heading {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: #8a91ab; padding: 10px 18px 6px;
}
.campaign-nav { flex: 1; overflow-y: auto; padding-top: 4px; }
.campaign-nav ul { list-style: none; }
.campaign-nav li {
  display: flex; align-items: center; gap: 9px; padding: 8px 18px;
  cursor: pointer; font-size: 14px;
}
.campaign-nav li:hover { background: rgba(255,255,255,0.06); }
.campaign-nav li.active { background: rgba(108, 92, 231, 0.35); color: #fff; }
.campaign-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.campaign-nav .btn { margin: 10px 14px; color: #8a91ab; }
.campaign-nav .btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.campaign-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-count { margin-left: auto; font-size: 11px; color: #8a91ab; }
.campaign-edit {
  background: none; border: none; color: #8a91ab;
  cursor: pointer; font-size: 13px; visibility: hidden; padding: 0 2px;
}
.campaign-nav li:hover .campaign-edit { visibility: visible; }
.campaign-edit:hover { color: #fff; }

.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-chip { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.user-name { font-size: 13px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 22px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.summary-tiles { display: flex; gap: 18px; flex: 1; }
.summary-tile { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.summary-tile b { display: block; font-size: 18px; color: var(--text); }
.search-input { width: 220px; }

.view { flex: 1; overflow: auto; padding: 22px; }

/* ---------- links table ---------- */
.link-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.link-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: -22px;
}
.link-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.link-table tr:last-child td { border-bottom: none; }
.link-table tbody tr { cursor: pointer; }
.link-table tbody tr:hover { background: #fafbff; }
.link-table tr.link-inactive td { opacity: 0.5; }

.link-title-cell { font-weight: 600; max-width: 300px; }
.short-url { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 12px; margin-top: 2px; }
.short-url code { color: var(--primary); font-size: 12px; }
.copy-btn {
  background: none; border: 1px solid var(--border); border-radius: 5px; cursor: pointer;
  font-size: 11px; padding: 1px 7px; color: var(--text-muted);
}
.copy-btn:hover { border-color: var(--primary); color: var(--primary); }
.copy-btn.copied { border-color: var(--success); color: var(--success); }

.dest-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: 13px; }

.campaign-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; background: var(--bg); white-space: nowrap;
}
.muted { color: var(--text-muted); }
.clicks-cell { font-weight: 700; font-size: 15px; }
.clicks-7d { font-weight: 400; font-size: 11px; color: var(--text-muted); }

.toggle {
  position: relative; width: 34px; height: 20px; border-radius: 20px; border: none;
  background: #cfd4e3; cursor: pointer; transition: background 0.15s; flex-shrink: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: left 0.15s;
}
.toggle.on { background: var(--success); }
.toggle.on::after { left: 16px; }

.empty-state {
  text-align: center; color: var(--text-muted); padding: 60px 20px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* ---------- link modal extras ---------- */
.slug-row { display: flex; align-items: center; gap: 0; margin-top: 5px; }
.slug-prefix {
  padding: 9px 8px 9px 12px; border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius) 0 0 var(--radius); background: var(--bg);
  color: var(--text-muted); font-size: 13px; white-space: nowrap; font-weight: 400;
}
.slug-row input { border-radius: 0 var(--radius) var(--radius) 0; margin-top: 0; }

.utm-details { margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.utm-details summary { font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text-muted); }
.utm-details[open] summary { margin-bottom: 12px; }
.utm-preview { font-size: 12px; word-break: break-all; line-height: 1.5; }

/* ---------- stats modal ---------- */
.modal-lg { max-width: 680px; }
.stats-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.stats-head h2 { margin-bottom: 4px; }
.stats-sub { font-size: 13px; color: var(--text-muted); word-break: break-all; line-height: 1.5; }
.stats-sub code { color: var(--primary); }

.stats-tiles { display: flex; gap: 12px; margin: 16px 0; flex-wrap: wrap; }
.stats-tile {
  flex: 1; min-width: 110px; background: var(--bg); border-radius: var(--radius);
  padding: 12px 14px; font-size: 12px; color: var(--text-muted);
}
.stats-tile b { display: block; font-size: 20px; color: var(--text); margin-bottom: 2px; }

.stats-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted); margin: 18px 0 8px; }

.chart {
  display: flex; align-items: flex-end; gap: 2px; height: 120px;
  background: var(--bg); border-radius: var(--radius); padding: 10px 10px 22px; position: relative;
}
.chart-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.chart-bar { background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; width: 100%; }
.chart-bar.zero { background: #dfe2ee; }
.chart-col:hover .chart-bar { background: var(--primary-dark); }
.chart-label { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--text-muted); white-space: nowrap; }
.chart-col .chart-tip {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 5px;
  white-space: nowrap; z-index: 2;
}
.chart-col:hover .chart-tip { display: block; }

.breakdown-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 13px; }
.breakdown-label { width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
.breakdown-bar-wrap { flex: 1; background: var(--bg); border-radius: 4px; height: 14px; overflow: hidden; }
.breakdown-bar { height: 100%; background: var(--primary); border-radius: 4px; }
.breakdown-count { width: 44px; text-align: right; font-weight: 700; flex-shrink: 0; }
.stats-columns { display: flex; gap: 28px; }
.stats-columns > div { flex: 1; min-width: 0; }

/* ---------- section tabs (links / pages) ---------- */
.side-tabs { display: flex; gap: 4px; padding: 0 14px 10px; }
.side-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  border: none; background: rgba(255,255,255,0.06); color: #cdd2e4;
  padding: 7px 4px; border-radius: 7px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.side-tab:hover { background: rgba(255,255,255,0.12); }
.side-tab.active { background: var(--primary); color: #fff; }

/* ---------- pages ---------- */
.page-title-cell { font-weight: 600; max-width: 280px; }
.file-cell { font-size: 12px; color: var(--text-muted); max-width: 200px; }
.file-cell b { display: block; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-pill {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px;
  border-radius: 20px; background: var(--bg); color: var(--text-muted); margin-left: 4px;
}
.metric-sub { font-weight: 400; font-size: 11px; color: var(--text-muted); }

.dropzone {
  margin-top: 5px; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 22px 16px; text-align: center; cursor: pointer; background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: rgba(108, 92, 231, 0.06); }
.dropzone-empty b { display: block; font-size: 14px; margin-bottom: 4px; }
.dropzone-empty span { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.dropzone-file { display: flex; align-items: center; gap: 10px; text-align: left; font-weight: 400; }
.dropzone-file b { display: block; font-size: 13px; word-break: break-all; }
.dropzone-file .muted { font-size: 12px; }
.dropzone-icon { font-size: 22px; }
.dropzone-file .copy-btn { margin-left: auto; flex-shrink: 0; }

.click-list { list-style: none; }
.click-list li {
  display: flex; align-items: baseline; gap: 10px; padding: 6px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.click-list li:last-child { border-bottom: none; }
.click-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.click-href { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.click-count { margin-left: auto; font-weight: 700; }

.version-list { list-style: none; }
.version-list li {
  display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.version-list li:last-child { border-bottom: none; }
.version-live { color: var(--success); font-weight: 700; font-size: 11px; }
.version-meta { color: var(--text-muted); font-size: 12px; }

/* ---------- modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(31, 36, 51, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  padding: 26px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
}
.modal-sm { max-width: 400px; }
.modal h2 { font-size: 18px; margin-bottom: 18px; }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; align-items: center; }
.form-error {
  padding: 10px 12px; border-radius: var(--radius); background: #fdecea;
  color: #c0392b; font-size: 13px; margin-bottom: 12px;
}

.checkbox-label { display: flex; align-items: center; gap: 8px; }
.checkbox-label input { width: auto; margin-top: 0; }

.color-options { display: flex; gap: 8px; margin-top: 6px; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected { border-color: var(--text); transform: scale(1.12); }

@media (max-width: 720px) {
  .sidebar { width: 64px; }
  .side-tabs { flex-direction: column; padding: 0 8px 10px; }
  .side-tab span { display: none; }
  .sidebar-logo { font-size: 20px; text-align: center; padding: 16px 0; }
  .sidebar-heading, .campaign-nav li span:not(.campaign-dot), .campaign-count, .user-name { display: none; }
  .campaign-nav li { justify-content: center; }
  .campaign-nav .btn { font-size: 0; text-align: center; padding: 4px; margin: 4px 14px; }
  .campaign-nav .btn::after { content: "+"; font-size: 18px; line-height: 1; }
  .sidebar-footer .btn { font-size: 0; padding: 4px; }
  .sidebar-footer .btn::after { content: "⎋"; font-size: 16px; line-height: 1; }
  .form-row { flex-direction: column; gap: 0; }
  .stats-columns { flex-direction: column; gap: 0; }
  .summary-tiles { display: none; }
  .search-input { flex: 1; width: auto; }
}
