:root {
  --bg: #11141d;
  --bg-gradient: radial-gradient(circle at top, #1b2030 0%, #0c0e15 60%);
  --card: #1a1f2e;
  --card-border: #2a3145;
  --accent: #8b8ff0;
  --accent-soft: #6c70d8;
  --accent-glow: rgba(139, 143, 240, 0.18);
  --text: #eef0f7;
  --muted: #8d94aa;
  --border: #2a3145;
  --danger: #f17b7b;
  --success: #6fe0a8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-gradient), var(--bg);
  color: var(--text);
  min-height: 100vh;
  letter-spacing: 0.01em;
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 12px 30px -18px rgba(0, 0, 0, 0.7);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  margin-top: 14px;
}

label:first-of-type {
  margin-top: 0;
}

input[type="url"],
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0e1119;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder {
  color: #5b6378;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.prefix-input {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #0e1119;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.prefix-input span {
  padding: 12px 0 12px 14px;
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
}

.prefix-input input {
  border: none;
  padding-left: 2px;
}

.prefix-input input:focus {
  box-shadow: none;
}

.prefix-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: #11141d;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  box-shadow: 0 8px 20px -8px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-primary.btn-compact {
  width: auto;
  margin-top: 0;
  padding: 11px 18px;
  white-space: nowrap;
}

.btn-secondary {
  padding: 11px 18px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-soft);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: var(--accent-glow);
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  min-height: 18px;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 180px;
}

.search-wrap input {
  width: 100%;
}

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

.links-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.links-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.link-count {
  font-size: 13px;
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 28px 0;
}

.link-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.link-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-top: 12px;
  background: #161b28;
  transition: border-color 0.15s ease;
}

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

.link-item .link-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.link-item .short-url {
  font-weight: 700;
  font-size: 15px;
  word-break: break-all;
  color: var(--accent);
}

.link-item .target-url {
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
  margin: 6px 0 10px;
}

.link-item .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(141, 148, 170, 0.15);
  color: var(--muted);
}

.badge.expired,
.badge.limit-reached {
  background: rgba(241, 123, 123, 0.15);
  color: var(--danger);
}

.link-item .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.click-count {
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: filter 0.1s ease;
}

.click-count:hover {
  filter: brightness(1.2);
}

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

.actions button {
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.actions button.delete {
  border-color: rgba(241, 123, 123, 0.4);
  color: var(--danger);
}

.actions button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.actions button.delete:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(241, 123, 123, 0.08);
}

.created-at {
  font-size: 11px;
  color: var(--muted);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--success);
  color: #08291a;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 22px;
  border-radius: 10px;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 1000;
  box-shadow: 0 12px 24px -10px rgba(0, 0, 0, 0.5);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 10, 16, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

.modal {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.8);
}

.modal h3 {
  margin: 0 0 4px;
  font-size: 19px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn-primary,
.modal-actions .btn-secondary {
  margin-top: 0;
  flex: 1;
}

#qrCanvas {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

#qrCanvas img,
#qrCanvas canvas {
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  max-height: 300px;
  overflow-y: auto;
}

.stats-list li {
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  font-size: 12px;
  color: var(--muted);
}

.stats-list li strong {
  color: var(--text);
}

@media (max-width: 480px) {
  header h1 {
    font-size: 25px;
  }

  .card {
    padding: 16px;
  }

  .row-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions .btn-primary,
  .toolbar-actions .btn-secondary {
    flex: 1;
  }

  .link-item .meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    width: 100%;
  }

  .actions button {
    flex: 1;
  }
}
