:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-subtle: #F4F4F5;
  --surface-hover: #E4E4E7;
  --border: #E4E4E7;
  --border-strong: #D4D4D8;
  --text: #09090B;
  --text-secondary: #52525B;
  --accent: #09090B;
  --on-accent: #FFFFFF;
  --tag-neutral-bg: #F4F4F5;
  --tag-neutral-text: #3F3F46;
  --tag-positive-bg: #ECFDF5;
  --tag-positive-text: #065F46;
  --tag-warn-bg: #FEF3C7;
  --tag-warn-text: #92400E;
  --tag-sold-bg: #E4E4E7;
  --tag-sold-text: #3F3F46;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --focus-ring: #09090B;
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background-color: var(--bg);
  color: var(--text);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

::selection {
  background-color: var(--text);
  color: var(--on-accent);
}

:where(button, input, select, a, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.page-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 44px 24px 80px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 28px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--text);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
}

.page-count {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.view-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  gap: 2px;
}

.view-switch-btn {
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms ease-out, color 150ms ease-out;
}

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

.view-switch-btn[aria-pressed="true"] {
  background-color: var(--text);
  color: var(--on-accent);
  font-weight: 600;
}

.bag-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: background-color 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out;
}

.bag-btn:hover {
  border-color: var(--border-strong);
  background-color: var(--surface-subtle);
}

.bag-btn.has-items {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.sync-status {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
  width: 100%;
}

.controls-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

.search-box {
  position: relative;
  width: 100%;
  min-width: 0;
}

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.select-wrap {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
}

.select-wrap.is-sort {
  margin-left: auto;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 44px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: border-color 150ms ease-out;
}

.search-input::placeholder {
  color: var(--text-secondary);
  font-weight: 400;
  opacity: 1;
}

.search-input:hover {
  border-color: var(--border-strong);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search-clear-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.search-clear-btn:hover {
  color: var(--text);
  background-color: var(--surface-subtle);
}

.search-clear-btn[hidden] {
  display: none;
}

.select-wrap {
  position: relative;
  flex: 0 0 auto;
}

.toolbar-select {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 150ms ease-out;
}

.toolbar-select:hover {
  border-color: var(--border-strong);
}

.catalog-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 28px 20px;
}

.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}

.card-bag-btn {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out, color 150ms ease-out;
}

.card-bag-btn:hover {
  border-color: var(--border-strong);
  background-color: var(--surface-subtle);
}

.card-bag-btn.is-in-bag {
  background-color: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.card-trigger {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
}

.cover-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background-color: var(--surface-subtle);
  overflow: hidden;
  transition: border-color 150ms ease-out, transform 150ms ease-out;
}

.card-trigger:hover .cover-frame {
  border-color: var(--border-strong);
  transform: translateY(-2px);
}

.cover-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background-color: var(--surface-subtle);
}

.cover-multi-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background-color: rgba(9, 9, 11, 0.78);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.card.is-sold .cover-frame {
  opacity: 0.55;
}

.cover-fallback {
  width: 100%;
  height: 100%;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: var(--surface-subtle);
  color: var(--text);
}

.cover-fallback-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.cover-fallback-author {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 10px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-subtitle {
  margin: 0;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.35;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
}

.price-sale {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.card.is-sold .price-sale {
  color: var(--text-secondary);
  text-decoration: line-through;
}

.price-market {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-secondary);
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  background-color: var(--tag-neutral-bg);
  color: var(--tag-neutral-text);
}

.tag-pill.is-positive {
  background-color: var(--tag-positive-bg);
  color: var(--tag-positive-text);
}

.tag-pill.is-warn {
  background-color: var(--tag-warn-bg);
  color: var(--tag-warn-text);
}

.tag-pill.is-sold {
  background-color: var(--tag-sold-bg);
  color: var(--tag-sold-text);
}

.empty-state {
  padding: 48px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-state[hidden] {
  display: none;
}

.empty-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.empty-btn:hover {
  background-color: var(--surface-subtle);
}

/* Dialog nativo */
dialog.item-dialog {
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  margin: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(9, 9, 11, 0.14);
}

dialog.item-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog.item-dialog:modal {
  overscroll-behavior: contain;
}

dialog.item-dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(9, 9, 11, 0.45);
  backdrop-filter: blur(2px);
}

.dialog-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.dialog-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-counter {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.dialog-gallery {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.dialog-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.dialog-cover {
  width: 240px;
  max-width: 100%;
  flex-shrink: 0;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background-color: var(--surface-subtle);
  overflow: hidden;
}

.dialog-nav-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background-color: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.dialog-nav-btn:hover {
  background-color: var(--surface-subtle);
  border-color: var(--border-strong);
}

.dialog-thumbs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.dialog-thumb-btn {
  width: 44px;
  height: 58px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface-subtle);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 150ms ease-out;
}

.dialog-thumb-btn[aria-pressed="true"] {
  border-color: var(--text);
}

.dialog-thumb-btn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-head-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.dialog-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text);
}

.dialog-subtitle {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.dialog-prices {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-top: 6px;
}

.dialog-price-sale {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.dialog-price-market {
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
}

.dialog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.dialog-close-form {
  margin: 0;
  flex-shrink: 0;
}

.dialog-close-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 150ms ease-out;
}

.dialog-close-btn:hover {
  background-color: var(--surface-subtle);
}

.dialog-details-list {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 18px;
  font-size: 14px;
  line-height: 1.5;
}

.dialog-details-list dt {
  font-weight: 600;
  color: var(--text-secondary);
}

.dialog-details-list dd {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}

.dialog-bag-btn {
  margin-top: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background-color: var(--accent);
  color: var(--on-accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  width: fit-content;
}

.dialog-bag-btn.is-in-bag {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.bag-empty {
  margin: 12px 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.bag-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bag-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.bag-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.bag-row-cover {
  width: 44px;
  height: 62px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background-color: var(--surface-subtle);
  flex-shrink: 0;
}

.bag-row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bag-row-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bag-row-price {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.bag-remove-btn,
.bag-clear-btn,
.bag-copy-btn {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
}

.bag-remove-btn:hover,
.bag-clear-btn:hover,
.bag-copy-btn:hover {
  border-color: var(--border-strong);
  background-color: var(--surface-subtle);
}

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

.bag-secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.bag-whatsapp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background-color: #16a34a;
  color: #ffffff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.bag-whatsapp-btn:hover {
  background-color: #15803d;
}

.bag-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.bag-total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.bag-count-note {
  font-size: 14px;
  color: var(--text-secondary);
}

.bag-total-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 767px) {
  .category-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .category-tabs::-webkit-scrollbar {
    display: none;
  }
}

@media (max-width: 639px) {
  .page-shell {
    padding: 20px 16px 48px;
  }

  .page-header {
    gap: 12px;
    margin-bottom: 20px;
  }

  .page-title {
    font-size: 24px;
  }

  .header-meta {
    width: 100%;
    justify-content: space-between;
  }

  .search-input {
    font-size: 16px;
  }

  .filters-bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .select-wrap.is-sort {
    margin-left: 0;
  }

  .toolbar-select {
    width: 100%;
    padding: 10px 12px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px 12px;
  }

  .dialog-body {
    padding: 18px;
  }

  .dialog-cover {
    width: 180px;
  }

  .dialog-stage {
    gap: 8px;
  }

  .dialog-details-list {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .dialog-details-list dd {
    margin-bottom: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cover-frame,
  .category-tab,
  .search-input,
  .toolbar-select,
  .sold-toggle-track,
  .sold-toggle-track::after,
  .sold-toggle-text,
  .dialog-close-btn {
    transition: none;
  }

  .card-trigger:hover .cover-frame {
    transform: none;
  }
}
