/* Premium VE Templates - styles
   Values measured from Refference/1st Draft (dashboard at ~1308px wide). */

@font-face {
  font-family: 'DM Sans';
  src: url('../assets/fonts/DMSans-latin.woff2') format('woff2');
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'DM Sans';
  src: url('../assets/fonts/DMSans-latin-ext.woff2') format('woff2');
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #0c0e11;
  --toolbar: #10151c;
  --panel: #15191d;
  --pill: #1f2428;
  --pill-hover: #282e34;
  --line: #222a33;
  --text: #e8eaed;
  --text-dim: #a3a8ad;
  --text-mute: #6d737a;
  --cyan: #19a7e0;
  --blue: #2f8fff;
  --radius: 10px;
  --sidebar-w: 218px;
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
body.has-modal { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 1em; height: 1em; flex: none; }

/* ---------- Masthead ---------- */
.masthead {
  height: 80px;
  display: grid;
  place-items: center;
  background: #070b16 url('../assets/ui/header-bg.jpg') center 40% / cover;
}
.wordmark { margin: 0; line-height: 0; }
.wordmark img {
  height: 56px;
  width: auto;
  max-width: 90vw;
  object-fit: contain;
  filter: drop-shadow(3px 4px 3px rgba(0, 0, 0, 0.85));
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 84px;
  padding: 0 28px 0 18px;
  background: linear-gradient(90deg, #0e131a, #12161d);
  border-bottom: 1px solid #1b222b;
}
.ratio-filters {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: #0f151c;
}
.ratio-btn {
  display: grid;
  place-items: center;
  width: 60px;
  height: 58px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #131a22;
  transition: background .15s, border-color .15s;
}
.ratio-btn:last-child { width: 70px; }
.ratio-btn:hover { background: #18212b; }
.ratio-btn.is-active { border-color: var(--blue); background: #142338; box-shadow: 0 0 0 1px rgba(47, 143, 255, .25), 0 0 14px rgba(47, 143, 255, .25); }
.ratio-svg { width: 40px; height: 36px; }

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 20px 0 54px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #11161d;
  position: relative;
}
.search:focus-within { border-color: #2c4d73; }
.search-icon { position: absolute; left: 54px; font-size: 26px; color: #9aa1aa; }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding-left: 40px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 22px;
  color: var(--text);
}
.search input::placeholder { color: #9aa1aa; }
.search input::-webkit-search-cancel-button { filter: invert(.7); }

.brand-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px 0 12px;
  border: 0;
  border-radius: 10px;
  background: #000;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}
.brand-btn .icon { font-size: 20px; color: #cfd3d8; }
.brand-btn:hover { background: #12161c; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 22px;
}
.icon-btn:hover { background: #1a2028; color: var(--text); }
.menu-btn { display: none; }

.dev-tools:empty { display: none; }
.dev-btn {
  height: 36px;
  padding: 0 12px;
  border: 1px dashed #b98a1d;
  border-radius: 8px;
  background: transparent;
  color: #f1c35b;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- Layout ---------- */
.layout { display: flex; align-items: flex-start; }

.sidebar {
  flex: none;
  width: var(--sidebar-w);
  padding: 8px 12px 12px;
  background: var(--panel);
  border-bottom-right-radius: 26px;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}
.cat-list, .cat-children { list-style: none; margin: 0; padding: 0; }
.cat + .cat { margin-top: 11px; }
.cat-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 23px;
  padding: 3px 10px 3px 10px;
  border: 0;
  border-radius: 5px;
  background: var(--pill);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 700;
  text-align: left;
}
.cat-btn--small .cat-name { font-size: 9px; }
.cat-btn:hover { background: var(--pill-hover); color: var(--text); }
.cat.is-active > .cat-btn { background: #1d2f45; color: #fff; box-shadow: inset 0 0 0 1px rgba(47, 143, 255, .5); }
.cat-caret {
  width: 0; height: 0;
  border-left: 6px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform .15s;
}
.cat-btn[aria-expanded='true'] .cat-caret { transform: rotate(90deg); }
.cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-count { font-size: 10px; color: var(--text-mute); }
.cat-children { padding: 6px 0 2px 22px; }
.cat--all .cat-btn { color: #dfe3e8; }
.cat-all-icon {
  width: 9px; height: 9px; flex: none;
  background: linear-gradient(currentColor 0 0) 0 0 / 4px 4px, linear-gradient(currentColor 0 0) 5px 0 / 4px 4px,
              linear-gradient(currentColor 0 0) 0 5px / 4px 4px, linear-gradient(currentColor 0 0) 5px 5px / 4px 4px;
  background-repeat: no-repeat;
}
.cat-child {
  display: block;
  width: 100%;
  padding: 4px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  text-align: left;
}
.cat-child:hover { background: var(--pill); color: var(--text); }
.cat-empty { padding: 3px 6px; font-size: 11px; color: var(--text-mute); font-style: italic; }
.sidebar-scrim { display: none; }

/* ---------- Gallery ---------- */
.library { flex: 1; min-width: 0; padding: 16px 16px 40px; }
.gallery {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px 11px;
}
.gallery:empty { display: none; }
.card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
}
.card-thumb {
  position: relative;
  display: block;
  aspect-ratio: 203 / 134;
  overflow: hidden;
  border: 1px solid var(--cyan);
  border-radius: 11px;
  background:
    radial-gradient(120% 90% at 100% 25%, #1565b0 0%, #0b3570 35%, #061638 65%, #040a1c 100%);
  transition: box-shadow .15s, transform .15s;
}
.card-thumb > img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Live thumbnail: the real template stage, scaled to the card (see js/thumbs.js). */
.thumb-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; overflow: hidden; pointer-events: none; background: #030916;
  /* reset what the card button would otherwise pass down, so thumbnails match the popup */
  text-align: left; line-height: normal; font-size: 16px; font-weight: 400; letter-spacing: normal; white-space: normal; color: #fff; }
.thumb-stage .stage-layer, .thumb-stage .bg-layer { position: absolute; inset: 0; }
.thumb-stage .bg-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-stage[data-bg-mode='light'] .bg-layer { background: #f4f6fa; }
.card-thumb .badge { z-index: 1; }
/* Portrait cards get narrower columns so they don't become huge. */
.gallery[data-ratio='1:1'] { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.gallery[data-ratio='3:4'] { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); }
.gallery[data-ratio='9:16'] { grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); }
.gallery[data-ratio='9:16'] .card-title, .gallery[data-ratio='3:4'] .card-title { font-size: 13px; }
.card:hover .card-thumb { box-shadow: 0 0 0 1px var(--cyan), 0 6px 22px rgba(25, 167, 224, .25); transform: translateY(-1px); }
.card-title { font-size: 15px; color: #9ea3a8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card:hover .card-title { color: var(--text); }
.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #b98a1d;
  color: #120d00;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.gallery-status[hidden] { display: none; }
.js-ready .boot-fallback { display: none; }
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 12vh auto 0;
  max-width: 360px;
  text-align: center;
}
.empty-icon { font-size: 40px; color: #2a3a4d; margin-bottom: 8px; }
.empty-title { margin: 0; font-size: 17px; font-weight: 700; color: #c4c8cd; }
.empty-sub { margin: 0; font-size: 14px; color: var(--text-mute); }
.empty-btn {
  margin-top: 10px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #141a21;
  color: var(--text);
  font-size: 14px;
}
.empty-btn:hover { border-color: var(--blue); }

/* ---------- Standalone template preview page (preview.html) ---------- */
.pv-wrap { max-width: 640px; margin: 0 auto; padding: 48px 24px; }
.pv-kicker { margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #f1c35b; }
.pv-title { margin: 0; font-size: 26px; }
.pv-path { margin: 6px 0 20px; font-size: 13px; color: var(--text-mute); word-break: break-all; }
.pv-meta { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0 0 20px; font-size: 14px; }
.pv-meta dt { color: var(--text-mute); }
.pv-meta dd { margin: 0; color: var(--text); }
.pv-problems { margin: 0 0 20px; padding: 12px 12px 12px 30px; border: 1px solid #5a3b12; border-radius: 10px; background: #1c1408; color: #f1c35b; font-size: 13px; }
.pv-problems[hidden] { display: none; }
.pv-actions { display: flex; gap: 10px; }
.pv-actions a { text-decoration: none; }


/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .toolbar { gap: 10px; padding: 0 14px; }
  .ratio-btn { width: 50px; height: 50px; }
  .ratio-btn:last-child { width: 58px; }
  .search { padding-left: 16px; }
  .search-icon { left: 16px; font-size: 22px; }
  .search input { padding-left: 30px; font-size: 18px; }
}

@media (max-width: 900px) {
  .masthead { height: 64px; }
  .wordmark img { height: 38px; }
  .menu-btn { display: grid; }
  .toolbar { flex-wrap: wrap; height: auto; padding: 10px 12px; }
  .search { order: 5; flex-basis: 100%; height: 46px; }
  .brand-btn { margin-left: auto; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    height: 100vh;
    max-height: none;
    padding-top: 16px;
    border-radius: 0 20px 20px 0;
    transform: translateX(-105%);
    transition: transform .2s ease-out, visibility .2s;
    visibility: hidden;
  }
  .sidebar-open .sidebar { transform: none; visibility: visible; box-shadow: 10px 0 40px rgba(0, 0, 0, .5); }
  .sidebar-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(0, 0, 0, .5); }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

}

@media (max-width: 520px) {
  .ratio-btn { width: 44px; height: 44px; }
  .ratio-btn:last-child { width: 50px; }
  .ratio-svg { width: 32px; height: 29px; }
  .brand-btn span { display: none; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
