/* Banco de Imagens - Catalogo Tramontina. CSS puro, tema claro editorial. */

:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --text: #17140f;
  --muted: #8a8578;
  --muted-2: #b4afa4;
  --border: #e7e4de;
  --border-strong: #d8d4cc;
  --accent: #c1121f;
  --accent-hover: #9d0e18;
  --accent-soft: #fdecea;
  --shadow-sm: 0 1px 2px rgba(23, 20, 15, 0.04), 0 1px 3px rgba(23, 20, 15, 0.06);
  --shadow-md: 0 8px 24px rgba(23, 20, 15, 0.10);
  --radius: 12px;
  --header-h: 132px;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* O atributo `hidden` sempre vence, mesmo em elementos com display:grid/flex
   (senao .lightbox/.status/.empty ficariam visiveis apesar de [hidden]). */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 246, 244, 0.92);
  backdrop-filter: saturate(1.1) blur(8px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px 24px 12px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.home-link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 13px 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface);
  transition: color 0.14s, border-color 0.14s, background 0.14s;
}
.home-link svg { width: 16px; height: 16px; }
.home-link:hover { color: var(--text); border-color: var(--muted-2); background: var(--bg); }
.home-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.brand-text h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.search-wrap {
  position: relative;
  flex: 1 1 320px;
  min-width: 220px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px; height: 18px;
  color: var(--muted-2);
  pointer-events: none;
}

#search {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 40px 11px 42px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search::placeholder { color: var(--muted-2); }

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 26px; height: 26px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  border-radius: 6px;
  cursor: pointer;
}
.search-clear:hover { background: var(--bg); color: var(--text); }

.result-count {
  flex: 0 0 auto;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Chips ---------- */
.chips {
  max-width: 1360px;
  margin: 0 auto;
  padding: 2px 24px 14px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { height: 6px; }
.chips::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.chip {
  flex: 0 0 auto;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.chip:hover { border-color: var(--muted-2); }
.chip .chip-count { color: var(--muted-2); font-weight: 500; margin-left: 4px; }

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip[aria-pressed="true"] .chip-count { color: rgba(255,255,255,0.75); }

.chip:focus-visible,
#search:focus-visible,
.btn:focus-visible,
.search-clear:focus-visible,
.card:focus-visible,
.lb-nav:focus-visible,
.lb-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Main / Grid ---------- */
#main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px;
  min-height: 60vh;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1140px) { .grid { grid-template-columns: repeat(5, 1fr); gap: 18px; } }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-family: inherit;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card-imgwrap {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #fff;
  display: grid;
  place-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.card-imgwrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.25s ease, opacity 0.3s ease;
}
.card:hover .card-imgwrap img { transform: scale(1.04); }
.card-imgwrap img.loaded { opacity: 1; }
.card-imgwrap img { opacity: 0; }

.card-copy {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, background 0.15s;
}
.card:hover .card-copy, .card:focus-within .card-copy { opacity: 1; transform: translateY(0); }
.card-copy:hover { background: #fff; border-color: var(--accent); color: var(--accent); }
.card-copy svg { width: 16px; height: 16px; }

.card-body { padding: 11px 13px 13px; }
.card-name {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.32;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.64em;
}
.card-ref {
  margin: 7px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* ---------- Status / Empty ---------- */
.status, .empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 20px;
  color: var(--muted);
  text-align: center;
}
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); margin: 0; }
.empty-sub { margin: 0; font-size: 14px; }

.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status.error .spinner { display: none; }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 24px 40px;
  text-align: center;
}
.site-footer p { margin: 0; font-size: 12.5px; color: var(--muted); }
#footer-count { font-weight: 600; color: var(--text); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(23, 20, 15, 0.82);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade 0.16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lb-figure {
  margin: 0;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  max-width: min(920px, 94vw);
  width: 100%;
  box-shadow: 0 24px 70px rgba(0,0,0,0.4);
}
.lb-imgwrap {
  background: #fff;
  display: grid;
  place-items: center;
  padding: 26px;
  max-height: 68vh;
}
.lb-imgwrap img { max-width: 100%; max-height: 62vh; object-fit: contain; }

.lb-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 20px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.lb-meta { min-width: 0; }
.lb-name { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.lb-ref { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.btn {
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 9px 15px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}
.btn:hover { border-color: var(--muted-2); background: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.lb-close, .lb-nav {
  position: fixed;
  z-index: 61;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s;
}
.lb-close:hover, .lb-nav:hover { background: rgba(255,255,255,0.24); }
.lb-close { top: 20px; right: 22px; width: 44px; height: 44px; font-size: 26px; line-height: 1; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 48px; height: 48px; font-size: 30px; line-height: 1; }
.lb-prev { left: 20px; }
.lb-next { right: 20px; }

@media (max-width: 620px) {
  .lb-nav { width: 40px; height: 40px; font-size: 24px; }
  .lb-prev { left: 8px; } .lb-next { right: 8px; }
  .lb-caption { justify-content: center; text-align: center; }
  .lb-actions { width: 100%; justify-content: center; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  z-index: 80;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

body.lb-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .card:hover { transform: none; }
}
