:root {
  --bg: #0f0f12;
  --bg-card: #1a1a22;
  --bg-elevated: #24242e;
  --text: #f4f4f6;
  --text-muted: #9b9bab;
  --primary: #7c5cff;
  --primary-hover: #6a4ae8;
  --danger: #ff5c6c;
  --success: #3dd68c;
  --border: #2e2e3a;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: min(1100px, 92vw);
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, background 0.15s;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.45rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Forms */
.form label {
  display: block;
  margin-bottom: 1rem;
  font-weight: 500;
  font-size: 0.9rem;
}
.form input[type="text"],
.form input[type="url"],
.form input[type="password"],
.form input[type="number"],
.form input[type="file"],
.form textarea {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.form input:focus, .form textarea:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}
.field-hint, .hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: rgba(255, 92, 108, 0.15); color: #ff8a96; }
.alert-success { background: rgba(61, 214, 140, 0.15); color: var(--success); }

.subtitle { color: var(--text-muted); margin-top: -0.5rem; }

/* Auth */
.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top, rgba(124, 92, 255, 0.15), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(400px, 92vw);
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }

/* Admin */
.admin-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0.85rem 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.admin-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.admin-header .logo {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.admin-header nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.admin-main { padding: 2rem 0 3rem; }
.admin-main.narrow { max-width: 640px; }
.admin-main h1 { margin: 0 0 0.5rem; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-top: 1.5rem;
}
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.product-card-image {
  position: relative;
  height: 160px;
  background: var(--bg-elevated);
}
.product-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.placeholder-img {
  display: grid;
  place-items: center;
  height: 100%;
  font-size: 3rem;
}
.badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-muted { background: rgba(0,0,0,0.6); color: #ccc; }
.product-card-body { padding: 1rem; }
.product-card-body h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.meta { color: var(--text-muted); font-size: 0.85rem; margin: 0; }
.link-preview { margin: 0.5rem 0; }
.link-preview code {
  font-size: 0.75rem;
  word-break: break-all;
  color: var(--text-muted);
}

.copy-link-box {
  margin-bottom: 1rem;
  padding: 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.copy-link-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.copy-link-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.copy-link-input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  font-family: ui-monospace, monospace;
}
.copy-link-input:focus {
  outline: 2px solid var(--primary);
}
.copy-btn.copied {
  background: var(--success);
}
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state.small { padding: 1.5rem; }

.preview-box { margin-bottom: 1rem; }
.preview-img {
  max-width: 200px;
  border-radius: 10px;
  display: block;
  margin-bottom: 0.5rem;
}
.preview-img.small { max-width: 80px; }

.links-section { margin-top: 2rem; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 { margin: 0; font-size: 1.2rem; }

.link-list { list-style: none; padding: 0; margin: 0; }
.link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}
.link-item.inactive { opacity: 0.55; }
.link-item-left { display: flex; align-items: center; gap: 0.85rem; }
.store-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: contain;
  background: #fff;
  padding: 4px;
}
.store-logo.placeholder {
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
}
.coupon-tag {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.75rem;
  background: rgba(124, 92, 255, 0.2);
  color: #b9a6ff;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
}
.link-item-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

/* Public page (Linktree style) */
.public-page {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(124, 92, 255, 0.2), transparent 55%),
    linear-gradient(180deg, #12121a 0%, var(--bg) 100%);
  min-height: 100vh;
}

.public-container {
  width: min(480px, 92vw);
  margin: 0 auto;
  padding: 2.5rem 0 2rem;
  text-align: center;
}

.public-header { margin-bottom: 2rem; }

.product-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.product-avatar.placeholder {
  display: inline-grid;
  place-items: center;
  background: var(--bg-elevated);
  font-size: 2.5rem;
}

.public-header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.public-description {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.6;
}

.store-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.store-block {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.store-btn {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.store-btn:hover {
  text-decoration: none;
  color: var(--text);
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 6px 24px rgba(124, 92, 255, 0.2);
}

.store-btn-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  padding: 3px;
  flex-shrink: 0;
}

.store-btn-letter {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

.store-btn-name { flex: 1; text-align: left; }
.store-btn-arrow { color: var(--text-muted); font-size: 1.1rem; }

.coupon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.coupon-btn:hover {
  background: rgba(124, 92, 255, 0.1);
  border-color: var(--primary);
  color: var(--text);
}
.coupon-btn.copied {
  border-color: var(--success);
  color: var(--success);
}
.coupon-code {
  font-weight: 700;
  color: var(--primary);
  background: rgba(124, 92, 255, 0.15);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
}
.coupon-copy { font-size: 0.8rem; }

.empty-message { color: var(--text-muted); padding: 2rem; }

.public-footer {
  margin-top: 2.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.public-footer a { color: var(--text-muted); }

@media (max-width: 600px) {
  .link-item {
    flex-direction: column;
    align-items: flex-start;
  }
  .link-item-actions { width: 100%; }
}
