:root,
[data-theme="dark"] {
  --bg: #090d16;
  --bg-elevated: #111827;
  --bg-card: rgba(17, 24, 39, 0.82);
  --bg-subtle: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-soft: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 20px 45px -15px rgba(0, 0, 0, 0.55);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #0891b2;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 40px -15px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: -20% 0 auto 0;
  height: 520px;
  background: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.22), rgba(6, 182, 212, 0.08) 42%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 20px;
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  padding-bottom: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  border-radius: 9px;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

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

.tip-pill {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: 999px;
}

.tip-pill code {
  color: var(--accent);
  font-weight: 700;
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  transition: border-color 0.15s, transform 0.15s;
}

.btn-icon:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

/* Hero */
.hero {
  text-align: center;
  padding: 34px 0 26px;
}

.hero h1 {
  font-size: clamp(1.9rem, 4vw, 2.85rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin: 0 0 12px;
}

.gradient-text {
  background: linear-gradient(135deg, #818cf8 0%, #22d3ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto 28px;
  font-size: 1.02rem;
}

/* Shorten Form */
.shorten-card {
  background: var(--bg-card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  text-align: left;
}

.primary-bar {
  display: flex;
  gap: 10px;
}

.url-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-soft);
  pointer-events: none;
}

.url-input-wrap input {
  width: 100%;
  height: 50px;
  padding: 0 16px 0 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.98rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.url-input-wrap input:focus,
.input-field:focus,
.prefix-input:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 50px;
  padding: 0 22px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  color: #fff;
  font-weight: 600;
  font-size: 0.96rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s, transform 0.1s;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.btn-ghost:hover {
  border-color: var(--border-strong);
}

.btn-danger {
  color: var(--danger);
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 0.82rem;
  border-radius: 9px;
}

.full-width {
  width: 100%;
}

.options-toggle-row {
  margin-top: 10px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 4px 2px;
  cursor: pointer;
}

.btn-text:hover {
  color: var(--text);
}

.advanced-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field-label small {
  font-weight: 400;
  color: var(--text-soft);
}

.input-field {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.prefix-input {
  display: flex;
  align-items: center;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow: hidden;
}

.prefix-text {
  padding: 0 8px 0 11px;
  font-size: 0.8rem;
  color: var(--text-soft);
  background: var(--bg-subtle);
  height: 100%;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border);
  max-width: 135px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prefix-input input {
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  font-size: 0.88rem;
  width: 100%;
  height: 100%;
  outline: none;
}

.inline-error {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.88rem;
}

[data-theme="light"] .inline-error {
  color: #b91c1c;
}

/* Result Banner */
.result-banner {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(16, 185, 129, 0.38);
  background: rgba(16, 185, 129, 0.09);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  text-align: left;
}

.result-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.result-kicker {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--success);
}

.result-short-link {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  word-break: break-all;
}

.result-short-link:hover {
  text-decoration: underline;
}

.result-target {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Metrics */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 10px 0 28px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* Workspace */
.workspace {
  padding-bottom: 64px;
}

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

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

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-soft);
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-compact {
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

/* Links List */
.links-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.link-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: border-color 0.15s;
}

.link-item:hover {
  border-color: var(--border-strong);
}

.link-info {
  min-width: 0;
  flex: 1;
}

.link-top-row {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.short-anchor {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--accent);
  text-decoration: none;
}

.short-anchor:hover {
  text-decoration: underline;
}

.link-title-tag {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.badge-paused,
.badge-expired,
.badge-limit_reached {
  background: rgba(245, 158, 11, 0.16);
  color: var(--warning);
}

.badge-lock {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
}

[data-theme="light"] .badge-lock {
  color: var(--primary);
}

.link-dest {
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 6px;
}

.link-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--text-soft);
}

.link-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.clicks-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 9px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.clicks-pill:hover {
  border-color: var(--primary);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  border-radius: 16px;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-sm {
  max-width: 380px;
}

.modal-lg {
  max-width: 760px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal-sub {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  word-break: break-all;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.qr-modal-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.qr-frame {
  width: 220px;
  height: 220px;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.qr-frame svg {
  width: 100%;
  height: 100%;
}

.qr-url-code {
  font-size: 0.86rem;
  color: var(--accent);
  word-break: break-all;
  text-align: center;
}

.qr-actions {
  display: flex;
  gap: 10px;
}

/* Analytics Modal */
.stats-modal-body {
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats-kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.stats-kpi {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.stats-kpi span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stats-kpi strong {
  font-size: 1.3rem;
}

.chart-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.chart-card h3,
.breakdown-card h3 {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.bars-wrap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  align-items: end;
  height: 140px;
  padding-top: 18px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  gap: 6px;
}

.bar-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
}

.bar-fill {
  width: 100%;
  max-width: 36px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  min-height: 4px;
}

.bar-label {
  font-size: 0.72rem;
  color: var(--text-soft);
}

.breakdown-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.breakdown-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.dist-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.dist-bar-bg {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-bottom: 9px;
}

.dist-bar-fg {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.manage-box {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* Interstitial Pages (Unlock / Preview / 404) */
.interstitial-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.interstitial-card {
  width: 100%;
  max-width: 460px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.brand-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  margin-bottom: 14px;
}

.status-pill {
  display: block;
  width: fit-content;
  margin: 0 auto 10px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.16);
  color: #a5b4fc;
}

.interstitial-card h1 {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

.interstitial-sub {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 20px;
}

.unlock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.interstitial-footer {
  margin-top: 16px;
  font-size: 0.85rem;
}

.interstitial-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.preview-box {
  text-align: left;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.preview-row {
  margin-bottom: 10px;
}

.preview-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}

.preview-url {
  font-size: 0.88rem;
  word-break: break-all;
}

.preview-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.preview-qr {
  width: 128px;
  height: 128px;
  margin: 14px auto 2px;
  background: #fff;
  padding: 6px;
  border-radius: 10px;
}

.preview-qr svg {
  width: 100%;
  height: 100%;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 80;
}

@media (max-width: 720px) {
  .primary-bar {
    flex-direction: column;
  }
  .metrics-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .link-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .link-right {
    width: 100%;
    justify-content: flex-start;
  }
  .tip-pill {
    display: none;
  }
}
