:root {
  color-scheme: dark;
  --bg: #070c17;
  --bg-2: #0f172a;
  --card: rgba(20, 30, 48, 0.8);
  --card-solid: #162136;
  --card-hover: rgba(30, 45, 70, 0.92);
  --border: rgba(148, 163, 184, 0.15);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --gold: #f59e0b;
  --green: #10b981;
  --danger: #ef4444;
  --radius: 20px;
}

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

html, body {
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(56, 189, 248, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 88% 12%, rgba(129, 140, 248, 0.14) 0%, transparent 42%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* Dark Scrollbars */
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(56, 189, 248, 0.72); }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, 0.35) transparent; }
}

/* Login & Status Pages */
.login-shell, .status-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card, .status-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

.status-card { text-align: center; }
.status-card h1 { font-size: 1.45rem; margin-bottom: 8px; }
.status-card p { font-size: 0.92rem; color: var(--muted); }

/* Main Shell */
.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 18px 46px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

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

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #060b16;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand h1 { font-size: 1.45rem; font-weight: 900; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.8rem; color: var(--muted); }

.nav-tabs {
  display: inline-flex;
  gap: 6px;
  background: rgba(10, 16, 30, 0.78);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.nav-tab {
  padding: 8px 15px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.nav-tab.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(129, 140, 248, 0.22));
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.4);
}

/* Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--card-solid);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, border-color 0.14s, transform 0.1s;
}
.btn:hover { background: #22324f; border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  border-color: transparent;
  color: #060b16;
  font-weight: 800;
}
.btn-primary:hover { background: linear-gradient(135deg, #7dd3fc, #818cf8); }

.btn-ghost { background: rgba(20, 30, 48, 0.58); color: var(--muted); }
.btn-ghost:hover { color: var(--text); }

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.34);
  color: #fca5a5;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-sm { padding: 6px 10px; font-size: 0.78rem; border-radius: 9px; }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(10, 16, 30, 0.86);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.inline-row { display: flex; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* KPI Strip */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
}
.kpi-label { font-size: 0.74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-val { font-size: 1.65rem; font-weight: 900; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Cards & Grids */
.card {
  background: var(--card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.card-title {
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.shortener-grid {
  display: grid;
  grid-template-columns: 0.92fr 1.28fr;
  gap: 18px;
  align-items: start;
}

.slug-input-group {
  display: flex;
  align-items: center;
  background: rgba(10, 16, 30, 0.86);
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.slug-input-group:focus-within { border-color: var(--accent); }

.slug-prefix {
  padding: 10px 10px 10px 12px;
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  background: rgba(30, 41, 59, 0.55);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slug-input-group input {
  border: none;
  background: transparent;
  padding: 10px 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  width: 100%;
  min-width: 0;
}
.slug-input-group input:focus { outline: none; }

.result-banner {
  margin-top: 14px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.16), rgba(15, 23, 42, 0.85));
  border: 1px solid rgba(16, 185, 129, 0.42);
}

/* Links List */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 620px;
  overflow-y: auto;
  padding-right: 4px;
}

.link-item {
  padding: 13px 14px;
  border-radius: 14px;
  background: rgba(10, 16, 30, 0.62);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.link-item:hover { border-color: rgba(56, 189, 248, 0.36); }
.link-item.is-paused { opacity: 0.62; }

.link-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}

.short-url-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  font-weight: 800;
  color: #38bdf8;
  word-break: break-all;
}
.short-url-link:hover { text-decoration: underline; }

.target-url-line {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 9px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.badge {
  font-size: 0.71rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  color: #cbd5e1;
}
.badge-green { background: rgba(16, 185, 129, 0.16); color: #34d399; }
.badge-blue { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }
.badge-gold { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.badge-red { background: rgba(239, 68, 68, 0.18); color: #fca5a5; }

/* QR Studio Layout */
.qr-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

.qr-type-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.pill-btn {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(10, 16, 30, 0.65);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}
.pill-btn:hover { color: var(--text); border-color: var(--border-strong); }
.pill-btn.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.55);
  color: #7dd3fc;
}

.qr-preview-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 16px;
  border-radius: 16px;
  background:
    repeating-conic-gradient(rgba(148, 163, 184, 0.12) 0% 25%, rgba(15, 23, 42, 0.45) 0% 50%) 50% / 18px 18px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  min-height: 280px;
}

#qrPreviewWrap {
  max-width: 280px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qrPreviewWrap svg {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.color-preset {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 2px solid var(--border-strong);
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.color-preset::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--p-fg) 50%, var(--p-bg) 50%);
}
.color-preset:hover { transform: scale(1.08); }

.contrast-warn {
  font-size: 0.78rem;
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.saved-qrs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.saved-qr-card {
  padding: 11px 12px;
  border-radius: 13px;
  background: rgba(10, 16, 30, 0.62);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Analytics Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.76);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  background: #111c30;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-card-sm { max-width: 460px; }

.chart-box {
  background: rgba(10, 16, 30, 0.65);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 12px 10px;
  margin-bottom: 14px;
}

.bar-chart-svg {
  width: 100%;
  height: 155px;
  display: block;
}

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.breakdown-box {
  background: rgba(10, 16, 30, 0.58);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 11px 12px;
}

.breakdown-title {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.bd-row {
  margin-bottom: 7px;
  font-size: 0.8rem;
}

.bd-row-top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.bd-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  overflow: hidden;
}

.bd-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
}

.recent-clicks-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}

.click-log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(10, 16, 30, 0.56);
  border: 1px solid var(--border);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(130%);
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.88rem;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  z-index: 300;
  transition: transform 0.25s ease;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.empty-msg { font-size: 0.86rem; color: var(--muted); text-align: center; padding: 20px 8px; }

/* Responsive */
@media (max-width: 960px) {
  .shortener-grid, .qr-grid { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .shell { padding: 14px 12px 36px; }
  .header { flex-direction: column; align-items: stretch; gap: 11px; }
  .nav-tabs { width: 100%; }
  .nav-tab { flex: 1; text-align: center; padding: 8px 8px; font-size: 0.82rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .breakdown-grid { grid-template-columns: 1fr; }
  .card { padding: 16px 14px; border-radius: 17px; }
}
