:root {
  --background: #ffffff;
  --foreground: #171717;
  --card: #ffffff;
  --border: #e5e7eb;
  --input: #e5e7eb;
  --muted: #f3f4f6;
  --muted-foreground: #6b7280;
  --accent: #f3f4f6;
  --theme-color: #006eff;
  --radius: 0.5rem;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

html.dark {
  --background: #0b0f14;
  --foreground: #f3f4f6;
  --card: #121820;
  --border: #243041;
  --input: #243041;
  --muted: #1a2330;
  --muted-foreground: #9ca3af;
  --accent: #1a2330;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
}

button,
input,
a {
  font: inherit;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid color-mix(in srgb, var(--theme-color) 12%, transparent);
  background: color-mix(in srgb, var(--background) 90%, transparent);
  backdrop-filter: blur(8px);
}

.container {
  width: 100%;
  max-width: 56rem;
  margin: 0 auto;
  padding: 1rem 1rem;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.logo {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.375rem;
  object-fit: cover;
  flex-shrink: 0;
}

.logo-fallback {
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  background: linear-gradient(135deg, var(--theme-color), #ff6a00);
}

.site-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ml-auto {
  margin-left: auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
}

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

main {
  flex: 1;
  padding: 1.5rem 1rem;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

.input {
  width: 100%;
  border: 1px solid var(--input);
  background: var(--background);
  color: var(--foreground);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  outline: none;
}

.input:focus {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--theme-color) 35%, transparent);
}

.paste-btn {
  border: 1px solid var(--input);
  background: var(--background);
  color: var(--muted-foreground);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: opacity 0.15s ease, background 0.15s ease;
}

.paste-btn:hover {
  background: var(--accent);
  color: var(--foreground);
}

.btn-primary {
  width: 100%;
  border: 0;
  background: var(--theme-color);
  color: #fff;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.btn-primary:disabled {
  opacity: 1;
  background: var(--theme-color);
  color: #fff;
  cursor: not-allowed;
}

.btn-primary:not(:disabled):hover {
  opacity: 0.9;
}

.error {
  margin: 0;
  color: #dc2626;
  font-size: 0.875rem;
  text-align: center;
}

.card {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.card.tinted {
  background: color-mix(in srgb, var(--theme-color) 13%, transparent);
  border-color: color-mix(in srgb, var(--theme-color) 25%, transparent);
}

.product-top {
  display: flex;
  gap: 0.75rem;
}

.thumb {
  width: 4rem;
  height: 4rem;
  border-radius: 0.375rem;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--muted);
  flex-shrink: 0;
}

.thumb.sm {
  width: 3.5rem;
  height: 3.5rem;
}

.product-meta {
  min-width: 0;
  flex: 1;
}

.product-title-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.product-name {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.remove-btn {
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.375rem;
  line-height: 0;
}

.remove-btn:hover {
  background: var(--accent);
  color: var(--foreground);
}

.price-row {
  margin-top: 0.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.price {
  font-weight: 600;
  color: var(--theme-color);
}

.price-old {
  color: var(--muted-foreground);
  text-decoration: line-through;
  font-size: 0.75rem;
}

.badge {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
}

.time-ago {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.affiliates {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.affiliate-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .site-title {
    font-size: 1.25rem;
  }

  .affiliate-row {
    flex-direction: row;
    align-items: center;
  }
}

.affiliate-name {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  flex: 1;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-outline,
.btn-buy {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 0.375rem;
  padding: 0.375rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

.btn-outline {
  border: 1px solid var(--border);
  background: var(--background);
  color: var(--foreground);
}

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

.btn-buy {
  border: 0;
  background: var(--theme-color);
  color: #fff;
}

.btn-buy:hover {
  opacity: 0.9;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.count-badge {
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--theme-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Giống AffiPad: thanh trắng full-width, viền mỏng, clock + title + badge + chevron */
.history-panel {
  display: block;
  width: 100%;
  max-width: 100%;
  align-self: stretch;
  box-sizing: border-box;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 0.625rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

html.dark .history-panel {
  background: var(--card);
}

.history-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3.25rem;
  padding: 0.85rem 1rem;
  border: 0;
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  text-align: left;
}

.history-toggle:hover {
  background: color-mix(in srgb, var(--muted) 55%, transparent);
}

.history-toggle-left {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}

.history-clock {
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  color: var(--muted-foreground);
}

.history-toggle-title {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.history-chevron {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  color: var(--muted-foreground);
  transition: transform 0.18s ease;
}

.history-toggle[aria-expanded="true"] .history-chevron {
  transform: rotate(180deg);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--background);
}

.history-panel:not(.is-open) .history-list,
.history-panel:not(.is-open) .history-actions {
  display: none !important;
}

.history-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 1rem 0.85rem;
  background: var(--background);
  border-top: 0;
}

.link-muted {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  cursor: pointer;
}

.link-muted:hover {
  color: var(--foreground);
}

.info-card {
  text-align: center;
}

.info-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

.info-card ol {
  margin: 0 auto;
  padding: 0;
  list-style-position: inside;
  text-align: center;
  max-width: 36rem;
  line-height: 1.75;
  font-size: 0.875rem;
}

.info-card li {
  text-align: center;
}

.info-card .group-link {
  display: inline-flex;
  margin-top: 0.4rem;
  max-width: 100%;
}

.voucher-panel {
  width: 100%;
  align-self: stretch;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem 1rem;
  overflow: hidden;
}

.voucher-head {
  width: 100%;
  gap: 0.45rem;
}

.voucher-panel-title {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voucher-count {
  flex-shrink: 0;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 0.72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.voucher-live-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1rem;
}

.voucher-live-list.collapsed {
  display: none;
}

.voucher-loading,
.voucher-empty {
  padding: 1rem 1.1rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  background: var(--muted);
  border-radius: 0.75rem;
}

.vcard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--background);
}

.vcard.is-out {
  opacity: 0.85;
}

.vcard-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted-foreground);
  line-height: 1.45;
}

.vcard-body {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 0.9rem;
  align-items: center;
}

.vcard-badge {
  border-radius: 0.85rem;
  background: #ee4d2d;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.7rem 0.35rem;
  min-height: 88px;
}

.vcard.is-out .vcard-badge {
  background: #9ca3af;
}

.vcard-badge-pct {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1;
}

.vcard-badge-go {
  margin-top: 0.45rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 0.22rem 0.4rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vcard-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.vcard-top {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}

.vcard-code {
  margin: 0;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  word-break: break-all;
  line-height: 1.35;
}

.vcard-status {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  white-space: nowrap;
}

.vcard-status.ok {
  color: #15803d;
  background: rgba(34, 197, 94, 0.12);
}

.vcard-status.out {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.12);
}

.vcard-desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted-foreground);
  line-height: 1.45;
}

.vcard-progress {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.15rem;
  border-top: 1px solid var(--border);
}

.vcard-progress-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.vcard-progress-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0.85rem;
  align-items: center;
}

.vcard-spark {
  width: 100%;
  height: 42px;
  display: block;
}

.vcard-bar-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: center;
  min-width: 0;
}

.vcard-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(238, 77, 45, 0.12);
  overflow: hidden;
}

.vcard-bar.is-out {
  background: rgba(156, 163, 175, 0.22);
}

.vcard-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #ee4d2d;
}

.vcard-bar.is-out > span {
  background: #9ca3af;
}

.vcard-pct {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.15;
  min-width: 3.2rem;
}

.vcard-pct strong {
  font-size: 0.95rem;
  font-weight: 800;
}

.vcard-pct span {
  font-size: 0.65rem;
  color: var(--muted-foreground);
}

@media (max-width: 420px) {
  .vcard-progress-row {
    grid-template-columns: 1fr 2fr;
    gap: 0.65rem;
  }
}

.group-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 1.25rem;
  border-radius: 0.375rem;
  background: var(--theme-color);
  color: #fff !important;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  word-break: break-all;
  margin-top: 0.25rem;
}

.hidden {
  display: none !important;
}
