/* ============================================================
   Petrarch Marketplace — Browse page (datasets)
   Implements the Figma "marketplace page" design.
   Loads AFTER landing.css and reuses its tokens, nav, footer,
   gate, buttons and dark-mode palette. Only page-specific
   pieces live here.
   ============================================================ */

/* ---- Extra tokens (light) ---------------------------------- */
:root {
  --tag-bg:     rgba(1, 45, 29, 0.05);
  --tag-border: rgba(1, 45, 29, 0.10);
  --field-bg:   #ffffff;
  --dot:        #012d1d;
  --hairline:   rgba(233, 225, 220, 0.6);
}
html.dark {
  --tag-bg:     rgba(193, 236, 212, 0.10);
  --tag-border: rgba(193, 236, 212, 0.20);
  --field-bg:   #0f261c;
  --dot:        #6ee7a8;
  --hairline:   rgba(30, 59, 46, 0.8);
}

/* ============================================================
   PAGE SHELL
   ============================================================ */
.mkt-main {
  flex: 1 0 auto;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 64px 48px 80px;
}

/* ---- Search section ---------------------------------------- */
.search-section {
  max-width: 1024px;
  margin: 0 auto 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.search-title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: clamp(30px, 4vw, 40px);
  line-height: 1.1;
  letter-spacing: -1.28px;
  color: var(--ink);
  text-align: center;
}

.searchbar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}
.searchbar .search-field {
  flex: 1 0 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}
.searchbar .search-field svg {
  width: 18px;
  height: 18px;
  color: var(--ink-2);
  flex-shrink: 0;
}
.searchbar input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--font-sans);
  font-size: 18px;
  color: var(--ink);
  padding: 10px 0;
}
.searchbar input::placeholder { color: #717973; }

.search-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
  margin: 0 8px;
  flex-shrink: 0;
}

.filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.96px;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color .15s ease, background-color .15s ease;
}
.filter-btn:hover { color: var(--ink); }
.filter-btn svg { width: 18px; height: 18px; }

.explore-btn {
  flex-shrink: 0;
  margin-left: 8px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 12px 32px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity .15s ease;
}
.explore-btn:hover { opacity: .92; }

/* ============================================================
   BROWSE LAYOUT: sidebar + results
   ============================================================ */
.browse-layout {
  display: grid;
  grid-template-columns: 256px 1fr;
  gap: 64px;
  align-items: start;
}

/* ---- Sidebar ---------------------------------------------- */
.mkt-sidebar { position: sticky; top: 96px; }
.sb-head {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.96px;
  color: var(--ink-2);
  padding-bottom: 9px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.sb-list { display: flex; flex-direction: column; gap: 16px; }
.sb-item {
  display: block;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 24px;
  font-weight: 400;
  color: var(--ink-2);
  padding: 0;
  transition: color .15s ease;
}
.sb-item:hover { color: var(--ink); }
.sb-item.active { font-weight: 700; color: var(--ink); }

/* ---- Results column -------------------------------------- */
.sort-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-bottom: 24px;
  min-height: 32px;
}
.sort-bar .sort-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.96px;
  color: var(--ink-2);
}
.sort-select {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.sort-select select {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.96px;
  color: var(--ink);
  padding: 8px 24px 8px 12px;
  outline: none;
}
.sort-select::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.6px solid var(--ink-2);
  border-bottom: 1.6px solid var(--ink-2);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

/* ---- Card grid ------------------------------------------- */
.ds-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 32px;
}

.ds-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 33px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.ds-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(1, 45, 29, 0.06);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.card-tag {
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  border-radius: 2px;
  padding: 5px 9px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
  line-height: 15px;
}
.card-bookmark {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-2);
  padding: 0;
  opacity: .7;
  transition: opacity .15s ease, color .15s ease;
}
.card-bookmark:hover { opacity: 1; color: var(--ink); }
.card-bookmark.saved { color: var(--accent); opacity: 1; }
.card-bookmark svg { width: 14px; height: 18px; }

.card-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 24px;
  line-height: 32px;
  color: var(--ink);
  margin-bottom: 16px;
}
.card-desc {
  font-size: 16px;
  line-height: 24px;
  color: var(--ink-2);
  margin-bottom: 32px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-stats {
  display: flex;
  gap: 16px;
  border-top: 1px solid var(--hairline);
  padding-top: 25px;
  padding-bottom: 32px;
}
.card-stats .stat { flex: 1 0 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.96px;
  text-transform: uppercase;
  color: var(--ink-2);
  opacity: .6;
}
.stat-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 24px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-value .dot {
  width: 8px;
  height: 8px;
  border-radius: 12px;
  background: var(--dot);
  flex-shrink: 0;
}

.card-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--hairline);
  padding-top: 25px;
}
.price { display: flex; align-items: baseline; gap: 8px; }
.price-val {
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 32px;
  color: var(--ink);
}
.price-unit {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-2);
}
.btn-buy {
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: none;
  cursor: pointer;
  border-radius: 2px;
  padding: 10px 32px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  transition: opacity .15s ease;
}
.btn-buy:hover { opacity: .92; }

/* ---- Empty state ----------------------------------------- */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 0;
  color: var(--ink-2);
}
.empty svg { width: 40px; height: 40px; margin: 0 auto 12px; color: var(--ink-2); opacity: .5; }

/* ---- Pagination ------------------------------------------ */
.pagination {
  margin-top: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.reveal-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  border-radius: 999px;
  padding: 12px 28px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  transition: background-color .18s ease, color .18s ease;
}
.reveal-btn:hover { background: var(--ink); color: var(--bg); }
.reveal-btn svg { width: 12px; height: 12px; }
.reveal-btn[hidden] { display: none; }
.showing-count {
  font-size: 12px;
  letter-spacing: 0.4px;
  color: var(--ink-2);
}

/* ============================================================
   MODAL (request a sample / request to buy)
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 20, 14, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.open { display: flex; }

.modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 16px;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.modal-close:hover { color: var(--ink); }

.modal-hd .cat-tag {
  display: inline-block;
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  border-radius: 2px;
  padding: 5px 9px;
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink);
}
.modal-name {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 28px;
  line-height: 1.2;
  color: var(--ink);
  margin: 16px 0 12px;
}
.modal-desc { font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.modal-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin: 20px 0;
  padding: 18px 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}
.modal-stats .ms { display: flex; flex-direction: column; gap: 2px; }
.modal-stats .ms .v { font-size: 18px; font-weight: 700; color: var(--ink); }
.modal-stats .ms .k { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--ink-2); opacity: .7; }
.modal-fmts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.modal-fmts .fmt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
}
.modal-src { font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.modal-lic { font-size: 13px; color: var(--ink); font-weight: 600; margin-bottom: 8px; }

.m-tabs {
  display: flex;
  gap: 8px;
  margin: 20px 0 20px;
  border-bottom: 1px solid var(--border);
}
.m-tab {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 4px;
  margin-bottom: -1px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  transition: color .15s ease, border-color .15s ease;
}
.m-tab.on { color: var(--ink); border-bottom-color: var(--accent); }

.frow { display: flex; gap: 12px; }
.frow .fg { flex: 1; }
.fg { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.fl { font-size: 13px; font-weight: 600; color: var(--ink); }
.fi, .ft, .fs {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--field-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .15s ease;
}
.fi:focus, .ft:focus, .fs:focus { border-color: var(--accent); }
.ft { resize: vertical; }

.f-success { display: none; text-align: center; padding: 24px 0; }
.f-success.show { display: block; }
.f-success .f-icon {
  width: 48px; height: 48px; line-height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--pill-bg);
  color: var(--pill-ink);
  font-size: 22px;
}
.f-success h3 { font-family: var(--font-serif); font-weight: 400; font-size: 22px; color: var(--ink); margin-bottom: 8px; }
.f-success p { font-size: 14px; line-height: 1.6; color: var(--ink-2); }

.btn-loading { opacity: .7; pointer-events: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  .mkt-main { padding: 48px 24px 64px; }
  .browse-layout { grid-template-columns: 1fr; gap: 32px; }
  .mkt-sidebar { position: static; }
  .sb-list { flex-direction: row; flex-wrap: wrap; gap: 12px 20px; }
}
@media (max-width: 720px) {
  .searchbar { flex-wrap: wrap; }
  .searchbar .search-field { flex-basis: 100%; }
  .search-divider { display: none; }
  .explore-btn { flex: 1; margin-left: 0; }
  .ds-grid { grid-template-columns: 1fr; }
  .frow { flex-direction: column; gap: 0; }
}
