/* ── Reset ── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%;overflow:hidden}
body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;background:#ebebea;color:#1a1a1a;font-size:13px}

/* ══════════════════════════════
   APP SHELL — full viewport
══════════════════════════════ */
.app-shell{display:flex;height:100vh;width:100vw;overflow:hidden}

/* ══════════════════════════════
   ① SIDEBAR
══════════════════════════════ */
.sidebar{
  width:72px;
  background:#16162a;
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:14px 0 16px;
  flex-shrink:0;
  overflow:hidden;
}
.sb-logo{
  width:36px;height:36px;
  border-radius:9px;
  background:#3b82f6;
  display:flex;align-items:center;justify-content:center;
  margin-bottom:16px;
  flex-shrink:0;
}
.sb-logo span{color:#fff;font-size:11px;font-weight:700;letter-spacing:-.3px}
.sb-nav{display:flex;flex-direction:column;align-items:center;gap:2px;width:100%}
.sb-item{
  width:62px;
  min-height:52px;
  border-radius:8px;
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:3px;padding:5px 3px;
  text-decoration:none;
  cursor:pointer;
  transition:background .15s;
}
.sb-item:hover{background:rgba(255,255,255,.08)}
.sb-item.active{background:rgba(59,130,246,.22);border:1px solid rgba(59,130,246,.4)}
.sb-icon{font-size:16px;line-height:1}
.sb-label{font-size:8.5px;color:rgba(255,255,255,.4);font-weight:500;text-align:center;line-height:1.25;letter-spacing:.01em}
.sb-item.active .sb-label{color:rgba(255,255,255,.9)}
.sb-divider{width:36px;height:1px;background:rgba(255,255,255,.08);margin:6px 0}

/* ══════════════════════════════
   ② MAIN AREA
══════════════════════════════ */
.main-area{flex:1;display:flex;flex-direction:column;min-width:0;overflow:hidden}

/* TOP BAR */
.topbar{
  height:46px;
  background:#fff;
  border-bottom:1px solid #e5e5e5;
  display:flex;align-items:center;
  padding:0 16px;gap:10px;
  flex-shrink:0;
  box-shadow:0 1px 3px rgba(0,0,0,.05);
}
.topbar-title{font-size:14px;font-weight:600;color:#111;white-space:nowrap}
.topbar-badge{
  font-size:10px;padding:2px 9px;
  border-radius:20px;
  background:#e6f9ef;color:#1a7a47;
  font-weight:600;border:1px solid #b3e8cf;
  white-space:nowrap;
}
.topbar-actions{margin-left:auto;display:flex;gap:7px}
.tb-btn{
  font-size:12px;padding:5px 13px;
  border-radius:6px;
  border:1px solid #d5d5d5;
  background:#fff;color:#333;
  cursor:pointer;font-weight:500;
  transition:background .15s,border-color .15s;
  white-space:nowrap;
}
.tb-btn:hover{background:#f5f5f5;border-color:#bbb}
.tb-btn.primary{background:#1d4ed8;color:#fff;border-color:#1d4ed8}
.tb-btn.primary:hover{background:#1e40af;border-color:#1e40af}
.tb-btn:disabled{opacity:.55;cursor:not-allowed}

/* CONTENT ROW */
.content-row{display:flex;flex:1;min-height:0;overflow:hidden}

/* ══════════════════════════════
   ③ CONTROLS PANEL
══════════════════════════════ */
.controls-panel{
  width:256px;
  background:#fff;
  border-right:1px solid #e5e5e5;
  overflow-y:auto;
  flex-shrink:0;
  scrollbar-width:thin;
  scrollbar-color:#ddd transparent;
}
.controls-panel::-webkit-scrollbar{width:4px}
.controls-panel::-webkit-scrollbar-thumb{background:#ddd;border-radius:2px}

.ctrl-section{border-bottom:1px solid #f0f0f0}
.ctrl-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:8px 12px;cursor:pointer;
  transition:background .12s;
}
.ctrl-head:hover{background:#fafafa}
.ctrl-title{font-size:10.5px;font-weight:700;color:#666;text-transform:uppercase;letter-spacing:.06em}
.ctrl-chevron{font-size:10px;color:#bbb;transition:transform .2s}
.ctrl-section.collapsed .ctrl-chevron{transform:rotate(-90deg)}
.ctrl-section.collapsed .ctrl-body{display:none}
.ctrl-body{padding:4px 10px 10px}

/* Form elements */
.cf-row{display:flex;align-items:center;gap:7px;margin-bottom:5px}
.cf-label{font-size:11px;color:#777;min-width:60px;flex-shrink:0}
.cf-input{
  flex:1;height:26px;
  border:1px solid #e2e2e2;border-radius:5px;
  background:#fafafa;padding:0 8px;
  font-size:11.5px;color:#111;
  outline:none;font-family:inherit;
  transition:border-color .15s;
}
.cf-input:focus{border-color:#3b82f6;background:#fff;box-shadow:0 0 0 2px rgba(59,130,246,.1)}
.cf-range{flex:1;accent-color:#3b82f6;cursor:pointer;height:3px}
.cf-val{font-size:11px;font-weight:600;color:#444;min-width:30px;text-align:right}

/* Upload zone */
.upload-zone{
  border:1.5px dashed #d0d0d0;border-radius:6px;
  padding:10px;text-align:center;cursor:pointer;
  position:relative;transition:border-color .2s,background .2s;
}
.upload-zone:hover{border-color:#3b82f6;background:#f0f7ff}
.upload-zone input{position:absolute;inset:0;opacity:0;cursor:pointer;width:100%;height:100%}
.upload-zone p{font-size:11px;color:#999}
.remove-btn{font-size:11px;color:#c00;background:none;border:none;cursor:pointer;padding:0}
.remove-btn:hover{text-decoration:underline}

/* URL badge */
.url-badge{font-size:10px;padding:2px 7px;border-radius:12px;background:#fff3cd;color:#856404;font-weight:600;border:1px solid #ffc107;white-space:nowrap;flex-shrink:0}
.url-badge.valid{background:#e6f9ef;color:#1a7a47;border-color:#b3e8cf}

/* Size chips */
.chip-row{display:flex;gap:4px;flex-wrap:wrap}
.chip{
  font-size:10px;padding:3px 8px;
  border:1px solid #e0e0e0;border-radius:12px;
  background:#fafafa;color:#666;cursor:pointer;
  transition:all .12s;font-weight:500;
}
.chip:hover{border-color:#3b82f6;color:#3b82f6;background:#f0f7ff}
.chip.active{background:#eff6ff;color:#1d4ed8;border-color:#93c5fd;font-weight:600}

/* Color swatches */
.swatch-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:6px}
.swatch-item{display:flex;flex-direction:column;align-items:center;gap:3px}
.swatch-input{
  width:36px;height:28px;
  border:1px solid #e0e0e0;border-radius:5px;
  padding:2px;cursor:pointer;background:#fafafa;
}
.swatch-label{font-size:9.5px;color:#999;text-align:center}

/* Animation chips */
.anim-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:4px}
.anim-chip{
  font-size:10px;padding:5px 4px;
  border:1px solid #e0e0e0;border-radius:5px;
  background:#fafafa;color:#666;cursor:pointer;
  text-align:center;transition:all .12s;font-weight:500;
}
.anim-chip:hover{border-color:#3b82f6;color:#3b82f6;background:#f0f7ff}
.anim-chip.active{background:#eff6ff;color:#1d4ed8;border-color:#93c5fd;font-weight:600}

/* ══════════════════════════════
   ④ PREVIEW AREA
══════════════════════════════ */
.preview-area{
  flex:1;display:flex;flex-direction:column;
  background:#d8d8d6;min-width:0;overflow:hidden;
}
.preview-topbar{
  height:36px;background:#fff;
  border-bottom:1px solid #e5e5e5;
  display:flex;align-items:center;padding:0 14px;gap:8px;flex-shrink:0;
}
.preview-label{font-size:11px;color:#999;font-weight:500}
.preview-size-badge{
  font-size:10px;padding:2px 8px;
  border-radius:20px;background:#f5f5f5;
  color:#666;border:1px solid #e0e0e0;font-weight:500;
}
.preview-stage{
  flex:1;display:flex;
  align-items:center;justify-content:center;
  padding:24px;overflow:hidden;
}
.iframe-shell{
  overflow:hidden;flex-shrink:0;line-height:0;
  box-shadow:0 6px 28px rgba(0,0,0,.28);
  border-radius:2px;
}
#adPreviewFrame{display:block;border:none;transform-origin:top left}
.preview-footer{
  height:48px;background:#fff;
  border-top:1px solid #e5e5e5;
  display:flex;align-items:center;padding:0 14px;gap:8px;flex-shrink:0;
}
.preview-hint{font-size:11.5px;font-weight:500;color:#1a7a47}

/* ══════════════════════════════
   RESPONSIVE
══════════════════════════════ */
@media(max-width:800px){
  .controls-panel{width:220px}
  .topbar-title{font-size:13px}
  .topbar-badge{display:none}
}
@media(max-width:600px){
  .sidebar{width:52px}
  .sb-label{display:none}
  .sb-item{min-height:40px}
  .controls-panel{width:200px}
}

/* ══════════════════════════════
   AD SLOTS & PREVIEW GRID
   Fully responsive — ratio-aware
══════════════════════════════ */

/* 3-col grid: left ads | centre preview | right ads */
.preview-grid {
  display: grid;
  grid-template-columns: minmax(160px, 260px) 0.75fr minmax(160px, 260px);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Ad columns — scrollable vertically, never clip horizontally */
.ad-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 10px;
  background: #c8c8c6;
  overflow-y: auto;
  overflow-x: visible;   /* MUST NOT be hidden — ratio trick needs this */
  scrollbar-width: thin;
  scrollbar-color: #aaa transparent;
  align-items: stretch;
}
.ad-col::-webkit-scrollbar { width: 3px; }
.ad-col::-webkit-scrollbar-thumb { background: #aaa; border-radius: 2px; }

/* Ad slot base — ratio + content set entirely by ads.js */
.ad-slot {
  width: 100%;
  flex-shrink: 0;
  /* No overflow, no fixed height — JS controls everything */
}

/* B: Zoom-in entrance animation on ad images */
@keyframes adZoomIn {
  from { transform: scale(1.08); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
@keyframes adFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

/* Applied to the img inside an image ad slot */
.ad-slot--image img {
  animation: adZoomIn 0.7s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
  will-change: transform, opacity;
}

/* Hover: subtle 3% scale-up to invite clicks */
.ad-slot--image a:hover img {
  transform: scale(1.03);
  transition: transform 0.35s ease;
}

/* AdSense slots fade in smoothly */
.ad-slot--adsense > div {
  animation: adFadeIn 0.6s ease both;
}

/* Slot wrapper gets a very subtle shadow to lift it off the background */
.ad-slot--image,
.ad-slot--adsense {
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
  border-radius: 4px;
}

/* Centre preview column */
.preview-centre {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #d0d0ce;
  padding: 20px;
  overflow: hidden;
  min-width: 0;
}

/* preview-area sits inside preview-grid centre cell */
.preview-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.preview-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
  height: 100%;
  padding: 0;
}

/* ── Responsive breakpoints ── */

/* Narrow screens: tighten the ad columns */
@media (max-width: 1100px) {
  .preview-grid {
    grid-template-columns: minmax(130px, 200px) 0.75fr minmax(130px, 200px);
  }
}

/* Tablet: stack ads above & below preview */
@media (max-width: 800px) {
  .preview-grid {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .ad-col {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 10px;
    gap: 10px;
    overflow: visible;
  }
  /* 2 slots per row on tablet */
  .ad-col .ad-slot {
    width: calc(50% - 5px) !important;
    padding-top: 0 !important;
    height: auto !important;
  }
  /* For ratio slots on mobile, override with aspect-ratio CSS property */
  .ad-col .ad-slot[style*="padding-top"] {
    height: 0 !important;
  }
  .preview-centre {
    padding: 16px;
    min-height: 260px;
    order: 2;
  }
  .ad-col:first-child { order: 1; }
  .ad-col:last-child  { order: 3; }
}

/* Mobile: single column */
@media (max-width: 520px) {
  .ad-col .ad-slot {
    width: 100% !important;
  }
}
