/* ============ Template Library — app styles ============ */
:root{
  --bg:#fafafa;
  --surface:#ffffff;
  --ink:#18181b;
  --muted:#52525b;
  --line:#e4e4e7;
  --line-soft:#f4f4f5;
  --hover:#f4f4f5;
  --accent:#4f46e5;
  --accent-hover:#4338ca;
  --accent-soft:#eef2ff;
  --accent-line:#e0e7ff;
  --danger:#dc2626;
  --sans:'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  --radius:12px;
  --shadow-sm:0 1px 2px rgba(0,0,0,.05);
  --shadow-md:0 4px 16px rgba(0,0,0,.07);
  color-scheme:light;
}
*,*::before,*::after{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
  margin:0;background:var(--bg);color:var(--ink);
  font:400 14px/1.55 var(--sans);
  -webkit-font-smoothing:antialiased;
}
img{display:block;max-width:100%}
a{color:inherit}
button{font:inherit;color:inherit;cursor:pointer;background:none;border:0;padding:0}
button:disabled{opacity:.45;cursor:default}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:6px}
::selection{background:var(--accent);color:#fff}
h1,h2,h3{margin:0}

/* ---------- app bar ---------- */
.appbar{
  position:sticky;top:0;z-index:60;height:57px;
  display:flex;align-items:center;gap:1.75rem;
  padding:0 1.25rem;background:var(--surface);border-bottom:1px solid var(--line);
}
.brand{display:flex;align-items:center;gap:.6rem;text-decoration:none;flex:none}
.brand-mark{
  width:28px;height:28px;border-radius:8px;background:var(--accent);color:#fff;
  display:grid;place-items:center;
}
.brand-name{font-size:15px;font-weight:600;letter-spacing:-.01em}
.appnav{display:flex;align-items:stretch;height:100%;gap:1.25rem}
.nav-tab{
  position:relative;display:flex;align-items:center;text-decoration:none;
  font-size:13.5px;font-weight:500;color:var(--muted);padding:0 2px;
}
.nav-tab:hover{color:var(--ink)}
.nav-tab.active{color:var(--ink)}
.nav-tab.active::after{
  content:"";position:absolute;left:0;right:0;bottom:-1px;height:2px;background:var(--accent);
  border-radius:2px 2px 0 0;
}
.header-selection{
  margin-left:auto;display:flex;align-items:center;gap:.45rem;text-decoration:none;
  font-size:13px;font-weight:500;color:var(--muted);padding:.4rem .7rem;border-radius:8px;
  border:1px solid var(--line);background:var(--surface);
}
.header-selection:hover{background:var(--hover);color:var(--ink)}
.selection-badge{
  min-width:20px;height:20px;padding:0 6px;border-radius:999px;
  background:var(--accent-soft);color:var(--accent);
  font-size:11px;font-weight:600;display:grid;place-items:center;
}

/* ---------- generic ---------- */
.app{min-height:calc(100vh - 57px)}
.view{max-width:1480px;margin:0 auto;padding:1.75rem 1.5rem 4rem}
.page-head{
  display:flex;align-items:flex-end;justify-content:space-between;gap:1rem;flex-wrap:wrap;
  margin-bottom:1.4rem;
}
.page-head h1{font-size:22px;font-weight:600;letter-spacing:-.02em}
.page-head p{margin:.3rem 0 0;color:var(--muted);font-size:13.5px;max-width:70ch}
.toolbar{display:flex;flex-wrap:wrap;align-items:center;gap:.6rem;margin-bottom:1.4rem;flex:none}
.chips{display:flex;flex-wrap:wrap;gap:.4rem}
.chip{
  height:32px;padding:0 .8rem;display:inline-flex;align-items:center;
  border:1px solid var(--line);border-radius:8px;background:var(--surface);
  font-size:12.5px;font-weight:500;color:var(--muted);
  transition:background .15s,color .15s,border-color .15s;
}
.chip:hover{background:var(--hover);color:var(--ink)}
.chip[aria-pressed="true"]{background:var(--ink);border-color:var(--ink);color:#fff}
.search{margin-left:auto;position:relative}
.search input{
  width:220px;max-width:100%;height:34px;background:var(--surface);
  border:1px solid var(--line);border-radius:8px;
  padding:0 .8rem 0 2.1rem;font:inherit;font-size:13px;color:var(--ink);
}
.search input::placeholder{color:var(--muted)}
.search input:focus{outline:2px solid var(--accent-soft);border-color:var(--accent)}
.search svg{position:absolute;left:.7rem;top:50%;transform:translateY(-50%);width:14px;height:14px;color:var(--muted);pointer-events:none}
.select-wrap select{
  height:34px;font:inherit;font-size:12.5px;color:var(--ink);
  background:var(--surface);border:1px solid var(--line);border-radius:8px;
  padding:0 1.9rem 0 .8rem;appearance:none;cursor:pointer;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2352525b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat:no-repeat;background-position:right .7rem center;
}
.select-wrap select:focus{outline:2px solid var(--accent-soft);border-color:var(--accent)}

.btn{
  height:34px;padding:0 .9rem;display:inline-flex;align-items:center;gap:.4rem;
  border-radius:8px;font-size:13px;font-weight:600;text-decoration:none;white-space:nowrap;
  transition:background .15s,border-color .15s,color .15s;border:1px solid transparent;
}
.btn svg{width:14px;height:14px}
.btn.primary{background:var(--accent);color:#fff}
.btn.primary:hover{background:var(--accent-hover)}
.btn.secondary{background:var(--surface);border-color:var(--line);color:var(--ink)}
.btn.secondary:hover{background:var(--hover)}
.btn.secondary.added{background:var(--accent-soft);border-color:var(--accent-line);color:var(--accent)}
.btn.sm{height:30px;padding:0 .7rem;font-size:12px}
.icon-btn{
  width:30px;height:30px;border-radius:8px;display:inline-flex;align-items:center;justify-content:center;
  color:var(--muted);text-decoration:none;flex:none;transition:background .15s,color .15s;
}
.icon-btn:hover{background:var(--hover);color:var(--ink)}
.icon-btn svg{width:15px;height:15px}
.link-btn{font-size:12px;font-weight:500;color:var(--muted)}
.link-btn:hover:not(:disabled){color:var(--danger)}
.pill{
  display:inline-flex;align-items:center;padding:.15rem .5rem;border-radius:6px;
  background:var(--line-soft);color:var(--muted);font-size:11px;font-weight:500;white-space:nowrap;
}
.pill.accent{background:var(--accent-soft);color:var(--accent);font-weight:600}
.no-results{padding:2.5rem 1rem;text-align:center}
.no-results b{display:block;font-size:14px;font-weight:600;margin-bottom:.25rem}
.no-results span{font-size:13px;color:var(--muted)}

/* ---------- gallery cards ---------- */
.grid{display:grid;gap:1.25rem;grid-template-columns:repeat(auto-fill,minmax(min(320px,100%),1fr))}
.card{
  display:flex;flex-direction:column;text-decoration:none;
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);
  overflow:hidden;transition:box-shadow .2s,border-color .2s,transform .2s;
}
.card:hover{border-color:#d4d4d8;box-shadow:var(--shadow-md);transform:translateY(-2px)}
.card-media{position:relative;aspect-ratio:16/10;overflow:hidden;background:var(--line-soft)}
.card-media img{width:100%;height:100%;object-fit:cover;object-position:top center;transition:transform .5s ease}
.card:hover .card-media img{transform:scale(1.025)}
.card-cta{
  position:absolute;right:.8rem;bottom:.8rem;z-index:2;
  display:inline-flex;align-items:center;gap:.4rem;
  background:var(--surface);border:1px solid var(--line);box-shadow:var(--shadow-sm);
  border-radius:8px;padding:.45rem .8rem;font-size:12px;font-weight:600;color:var(--accent);
  opacity:0;transform:translateY(6px);transition:opacity .2s,transform .2s;
}
.card:hover .card-cta,.card:focus-visible .card-cta{opacity:1;transform:none}
.card-body{padding:.95rem 1.05rem 1.05rem;display:flex;flex-direction:column;flex:1}
.card-title-row{display:flex;align-items:baseline;justify-content:space-between;gap:.8rem}
.card-name{font-size:15px;font-weight:600;letter-spacing:-.01em}
.card-count{font-size:12px;color:var(--muted);white-space:nowrap}
.card-meta{margin-top:.45rem}
.card-desc{
  margin:.55rem 0 0;color:var(--muted);font-size:13px;flex:1;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.card-cats{
  margin:.8rem 0 0;padding-top:.7rem;border-top:1px solid var(--line-soft);
  font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}

/* ---------- browse workspace ---------- */
.view-browse{
  max-width:none;height:calc(100vh - 57px);
  display:flex;flex-direction:column;padding:1rem 1.25rem 1.25rem;
}
.view-browse .toolbar{margin-bottom:1rem}
.workspace{
  flex:1;min-height:0;
  display:grid;grid-template-columns:300px minmax(0,1fr) 300px;gap:1rem;
}
.pane{
  display:flex;flex-direction:column;min-height:0;min-width:0;
  background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;
}
.pane-head{
  flex:none;display:flex;align-items:center;gap:.6rem;
  padding:.75rem .9rem;border-bottom:1px solid var(--line-soft);
}
.pane-head h2{font-size:13px;font-weight:600;margin-right:auto}
.pane-head-meta{font-size:12px;color:var(--muted)}
.pane-scroll{
  flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:.5rem;
  scrollbar-width:thin;scrollbar-color:#d4d4d8 transparent;
}
.pane-scroll::-webkit-scrollbar{width:8px}
.pane-scroll::-webkit-scrollbar-thumb{background:#e4e4e7;border-radius:8px}

/* catalog */
.ccat{margin-bottom:2px}
.ccat-head{
  display:flex;align-items:center;gap:.5rem;width:100%;text-align:left;
  padding:.5rem .5rem;border-radius:8px;
}
.ccat-head:hover{background:var(--hover)}
.ccat-title{font-size:12.5px;font-weight:600;flex:1}
.ccat-count{font-size:11px;font-weight:500;color:var(--muted);background:var(--line-soft);border-radius:6px;padding:.05rem .45rem}
.ccat-chev{display:inline-flex;color:var(--muted);transition:transform .2s}
.ccat-chev svg{width:13px;height:13px}
.ccat.closed .ccat-chev{transform:rotate(-90deg)}
.ccat-body{display:flex;flex-direction:column;gap:2px;padding:.15rem 0 .6rem}
.ccat.closed .ccat-body{display:none}
.pg{
  display:flex;align-items:center;gap:.6rem;
  padding:.35rem;border:1px solid transparent;border-radius:8px;cursor:pointer;
  transition:background .12s,border-color .12s;
}
.pg:hover{background:var(--hover)}
.pg.active{background:var(--accent-soft);border-color:var(--accent-line)}
.pg-thumb{
  width:76px;height:50px;object-fit:cover;object-position:top center;
  border-radius:6px;border:1px solid var(--line);background:var(--line-soft);flex:none;
}
.pg-main{
  display:flex;align-items:center;gap:.6rem;flex:1;min-width:0;text-align:left;
  border-radius:6px;cursor:pointer;
}
.pg-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:.05rem}
.pg-label{
  font-size:12.5px;font-weight:500;line-height:1.35;color:var(--ink);
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.pg-site{font-size:11px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pg-add{
  width:26px;height:26px;border-radius:6px;border:1px solid var(--line);background:var(--surface);
  display:grid;place-items:center;color:var(--muted);flex:none;
  transition:background .12s,color .12s,border-color .12s;
}
.pg-add svg{width:13px;height:13px}
.pg-add:hover{border-color:var(--accent);color:var(--accent)}
.pg-add[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:#fff}

/* preview pane */
.preview-bar{
  flex:none;min-height:60px;display:flex;align-items:center;gap:.8rem;flex-wrap:wrap;
  padding:.65rem .9rem;border-bottom:1px solid var(--line-soft);
}
.preview-id{min-width:0;flex:1;display:flex;flex-direction:column;gap:.05rem}
.preview-name{font-size:14px;font-weight:600;letter-spacing:-.01em;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.preview-sub{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.preview-controls{display:flex;align-items:center;gap:.5rem;flex:none}
.device-switch{display:flex;background:var(--line-soft);border-radius:8px;padding:2px;gap:2px}
.device-switch button{
  width:28px;height:26px;border-radius:6px;display:grid;place-items:center;color:var(--muted);
  transition:background .12s,color .12s;
}
.device-switch button:hover{color:var(--ink)}
.device-switch button[aria-pressed="true"]{background:var(--surface);color:var(--ink);box-shadow:var(--shadow-sm)}
.device-switch svg{width:14px;height:14px}
.preview-stage{
  flex:1;min-height:0;position:relative;background:var(--line-soft);display:flex;overflow:hidden;
}
.frame-wrap{
  flex:1;display:flex;min-height:0;min-width:0;position:relative;margin:0 auto;max-width:100%;
  transition:max-width .25s ease;
}
.preview-stage[data-device="tablet"] .frame-wrap{max-width:768px;box-shadow:0 0 0 1px var(--line)}
.preview-stage[data-device="mobile"] .frame-wrap{max-width:390px;box-shadow:0 0 0 1px var(--line)}
.frame-wrap iframe{flex:1;width:100%;height:100%;border:0;background:#fff}
.preview-empty{
  margin:auto;text-align:center;color:var(--muted);font-size:13px;line-height:1.6;
  display:flex;flex-direction:column;gap:.9rem;align-items:center;padding:2rem;
}
.preview-empty svg{color:#d4d4d8}
.preview-empty p{margin:0}
.frame-loader{
  position:absolute;inset:0;z-index:2;display:grid;place-items:center;
  background:rgba(255,255,255,.72);transition:opacity .2s;
}
.frame-loader.hidden{opacity:0;pointer-events:none}
.spinner{
  width:26px;height:26px;border-radius:50%;
  border:3px solid var(--line);border-top-color:var(--accent);
  animation:spin .7s linear infinite;
}
@keyframes spin{to{transform:rotate(360deg)}}

/* selection pane */
#selection-body{padding:.75rem;display:flex;flex-direction:column;gap:.9rem}
.sel-empty-home{
  border:1.5px dashed var(--line);border-radius:10px;padding:1.4rem 1rem;
  text-align:center;color:var(--muted);font-size:13px;
  display:flex;flex-direction:column;gap:.7rem;align-items:center;
}
.sel-empty-home p{margin:0}
.sel-home{border:1px solid var(--line);border-radius:10px;overflow:hidden;cursor:pointer;transition:border-color .15s}
.sel-home:hover{border-color:#d4d4d8}
.sel-home-thumb{width:100%;aspect-ratio:16/9;object-fit:cover;object-position:top center;background:var(--line-soft)}
.sel-home-body{padding:.65rem .8rem .75rem;display:flex;flex-direction:column;gap:.1rem}
.sel-kick{font-size:10.5px;font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--accent)}
.sel-name{font-size:14px;font-weight:600}
.sel-row-actions{display:flex;gap:.9rem;margin-top:.5rem}
.sel-row-actions a,.sel-row-actions button{
  font-size:12px;font-weight:500;color:var(--muted);text-decoration:none;
}
.sel-row-actions a:hover,.sel-row-actions button:hover{color:var(--ink)}
.sel-row-actions .danger:hover{color:var(--danger)}
.sel-divider{
  display:flex;align-items:center;gap:.8rem;
  font-size:10.5px;font-weight:600;letter-spacing:.08em;text-transform:uppercase;color:var(--muted);
}
.sel-divider::before,.sel-divider::after{content:"";flex:1;height:1px;background:var(--line)}
.sel-pages{display:flex;flex-direction:column;gap:2px}
.spg{
  display:flex;align-items:center;gap:.6rem;padding:.35rem;border-radius:8px;cursor:pointer;
  border:1px solid transparent;transition:background .12s;
}
.spg:hover{background:var(--hover)}
.spg-remove{
  width:24px;height:24px;border-radius:6px;display:grid;place-items:center;
  color:var(--muted);flex:none;transition:background .12s,color .12s;
}
.spg-remove svg{width:12px;height:12px}
.spg-remove:hover{background:#fef2f2;color:var(--danger)}
.sel-empty{
  text-align:center;color:var(--muted);font-size:12.5px;line-height:1.7;
  padding:1.4rem 1rem;border:1.5px dashed var(--line);border-radius:10px;
}
.sel-empty p{margin:0}
.sel-empty b{color:var(--ink)}

/* ---------- responsive ---------- */
@media(max-width:1280px){
  .workspace{grid-template-columns:270px minmax(0,1fr) 270px}
}
@media(max-width:1080px){
  .view-browse{height:auto;min-height:calc(100vh - 57px)}
  .workspace{grid-template-columns:1fr}
  .workspace>.pane:first-child .pane-scroll{max-height:430px}
  .previewpane{height:66vh;min-height:460px}
  #selection .pane-scroll{overflow:visible}
  .search{margin-left:0}
  .search input{width:100%}
  .search{flex:1 1 180px}
}
@media(max-width:640px){
  .appbar{gap:1rem;padding:0 .9rem}
  .appnav{gap:.9rem}
  .brand-name{display:none}
  .header-selection span:not(.selection-badge){display:none}
  .view{padding:1.25rem 1rem 3rem}
  .view-browse{padding:.75rem .75rem 1rem}
  .preview-controls{flex-wrap:wrap}
  .previewpane{height:60vh;min-height:400px}
  .pg-thumb{width:64px;height:44px}
}
@media(prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.01ms !important;transition-duration:.01ms !important}
}
