
*{box-sizing:border-box}
:root{
  --primary:#2563eb;
  --primary-dark:#1d4ed8;
  --navy:#0f172a;
  --bg:#eef2f7;
  --surface:#ffffff;
  --surface-soft:#f8fafc;
  --text:#334155;
  --heading:#0f172a;
  --muted:#64748b;
  --border:#e2e8f0;
  --success:#16a34a;
  --danger:#dc2626;
  --warning:#d97706;
  --radius:14px;
  --shadow:0 16px 40px rgba(15,23,42,.08);
}

html,body{margin:0;padding:0}
body{
  min-height:100vh;
  background:var(--bg);
  color:var(--text);
  font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  font-size:14px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
a{color:inherit}
button,input,textarea,select{font:inherit}
button{cursor:pointer}

/* MAIN LAYOUT */
.builder{
  display:grid;
  grid-template-columns:420px minmax(0,1fr);
  min-height:100vh;
  height:100vh;
}
.panel{
  position:relative;
  overflow-y:auto;
  overflow-x:hidden;
  background:#fff;
  border-right:1px solid var(--border);
  scrollbar-width:thin;
}
.panel::-webkit-scrollbar{width:8px}
.panel::-webkit-scrollbar-thumb{
  background:#cbd5e1;
  border-radius:999px;
}

/* TOP HEADER */
.panel>header{
  position:sticky;
  top:0;
  z-index:50;
  min-height:68px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 18px;
  background:linear-gradient(135deg,#0f172a,#1e293b);
  color:#fff;
  box-shadow:0 8px 26px rgba(15,23,42,.16);
}
.panel>header strong{
  display:block;
  font-size:15px;
  font-weight:800;
  letter-spacing:.01em;
}
.panel>header small{
  display:block;
  margin-top:2px;
  color:#94a3b8;
  font-size:11px;
}
.head-actions{
  display:flex;
  align-items:center;
  gap:8px;
}
.head-actions a{
  padding:7px 9px;
  border:1px solid rgba(255,255,255,.14);
  border-radius:8px;
  color:#e2e8f0;
  text-decoration:none;
  font-size:11px;
  font-weight:700;
}
.head-actions a:hover{
  background:rgba(255,255,255,.08);
  color:#fff;
}

/* TABS */
.tabs{
  position:sticky;
  top:68px;
  z-index:40;
  display:grid;
  grid-template-columns:repeat(4,1fr);
  background:rgba(255,255,255,.97);
  border-bottom:1px solid var(--border);
  backdrop-filter:blur(10px);
}
.tab{
  position:relative;
  border:0;
  background:transparent;
  color:#64748b;
  padding:13px 6px 12px;
  font-size:11px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.03em;
}
.tab:hover{color:var(--primary)}
.tab.active{
  color:var(--primary);
  background:#eff6ff;
}
.tab.active:after{
  content:"";
  position:absolute;
  left:22%;
  right:22%;
  bottom:0;
  height:2px;
  border-radius:999px;
  background:var(--primary);
}
.tabpane{display:none}
.tabpane.active{display:block}

/* COLLAPSIBLE BLOCKS */
details{
  border-bottom:1px solid var(--border);
  background:#fff;
}
summary{
  position:relative;
  list-style:none;
  padding:16px 42px 16px 18px;
  color:var(--heading);
  font-size:13px;
  font-weight:800;
  cursor:pointer;
  user-select:none;
}
summary::-webkit-details-marker{display:none}
summary:after{
  content:"+";
  position:absolute;
  right:18px;
  top:50%;
  transform:translateY(-50%);
  width:22px;
  height:22px;
  display:grid;
  place-items:center;
  border-radius:7px;
  background:#f1f5f9;
  color:#64748b;
  font-size:15px;
}
details[open] summary{
  background:#fbfdff;
  color:var(--primary);
}
details[open] summary:after{
  content:"−";
  background:#eff6ff;
  color:var(--primary);
}

/* FORM GROUP */
.group{
  display:grid;
  gap:14px;
  padding:5px 18px 22px;
}
.group h3{
  margin:6px 0 0;
  color:var(--heading);
  font-size:13px;
}
.group label{
  display:grid;
  gap:7px;
  color:#475569;
  font-size:11px;
  font-weight:800;
}
.group input,
.group textarea,
.group select{
  width:100%;
  min-width:0;
  border:1px solid #cbd5e1;
  border-radius:10px;
  background:#fff;
  color:var(--heading);
  padding:10px 11px;
  outline:none;
  transition:.16s;
}
.group input:hover,
.group textarea:hover,
.group select:hover{
  border-color:#94a3b8;
}
.group input:focus,
.group textarea:focus,
.group select:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(37,99,235,.10);
}
.group textarea{
  min-height:96px;
  resize:vertical;
  line-height:1.55;
}
.group .tall{min-height:180px}
.code{
  font-family:Consolas,"SFMono-Regular",Menlo,monospace!important;
  font-size:12px!important;
  background:#fbfdff!important;
}
input[type="color"]{
  height:44px;
  padding:4px!important;
}
input[type="checkbox"],
input[type="radio"]{
  width:auto!important;
  accent-color:var(--primary);
}
input[type="range"]{
  border:0!important;
  padding:0!important;
  box-shadow:none!important;
  accent-color:var(--primary);
}

/* PAGE LIST */
.page-list{
  padding-top:14px;
}
.page-link{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:11px 12px;
  border:1px solid var(--border);
  border-radius:10px;
  background:#fff;
  color:#334155;
  text-decoration:none;
  transition:.15s;
}
.page-link:hover{
  border-color:#bfdbfe;
  background:#f8fbff;
}
.page-link.active{
  border-color:#93c5fd;
  background:#eff6ff;
  color:#1d4ed8;
}
.page-link span{
  font-size:12px;
  font-weight:800;
}
.page-link small{
  color:#94a3b8;
  font-size:10px;
}

/* BUTTONS */
.secondary,.linkbtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  padding:9px 12px;
  border:1px solid var(--border);
  border-radius:9px;
  background:#fff;
  color:#334155;
  text-decoration:none;
  font-size:11px;
  font-weight:800;
}
.secondary:hover,.linkbtn:hover{
  border-color:#bfdbfe;
  background:#eff6ff;
  color:#1d4ed8;
}

/* SECTION BUILDER */
.builder-toolbar{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:8px;
}
.section-editor{
  display:grid;
  gap:12px;
}
.section-card{
  overflow:hidden;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
  box-shadow:0 7px 20px rgba(15,23,42,.04);
}
.section-head-admin{
  display:grid;
  grid-template-columns:28px minmax(0,1fr) auto;
  align-items:center;
  gap:8px;
  padding:10px 11px;
  background:#f8fafc;
  border-bottom:1px solid var(--border);
}
.section-head-admin strong{
  color:var(--heading);
  font-size:11px;
  letter-spacing:.05em;
}
.grip{
  width:26px;
  height:26px;
  display:grid;
  place-items:center;
  border-radius:7px;
  color:#94a3b8;
  cursor:grab;
}
.grip:hover{
  background:#e2e8f0;
  color:#475569;
}
.section-head-admin>div{
  display:flex;
  gap:5px;
}
.mini{
  border:1px solid var(--border);
  border-radius:7px;
  background:#fff;
  color:#475569;
  padding:6px 8px;
  font-size:10px;
  font-weight:800;
}
.mini:hover{
  background:#f1f5f9;
}
.mini.danger{
  border-color:#fecaca;
  background:#fff1f2;
  color:#b91c1c;
}
.section-card>label{
  display:grid;
  gap:7px;
  padding:12px;
  color:#64748b;
  font-size:10px;
  font-weight:800;
}
.section-card textarea{
  width:100%;
  min-height:210px;
  padding:11px;
  resize:vertical;
  border:1px solid #cbd5e1;
  border-radius:9px;
  background:#fbfdff;
  color:#0f172a;
  font-family:Consolas,monospace;
  font-size:11px;
  line-height:1.55;
  outline:none;
}
.section-card textarea:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(37,99,235,.10);
}
.section-card textarea.invalid{
  border-color:#ef4444;
  background:#fff7f7;
}

/* MISC */
.hint{
  margin:0;
  padding:9px 10px;
  border-radius:9px;
  background:#f8fafc;
  color:#64748b;
  font-size:10px;
}
.backup{
  display:block;
  padding:9px 10px;
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
  color:#475569;
  text-decoration:none;
  font-family:Consolas,monospace;
  font-size:10px;
}
.backup:hover{
  border-color:#bfdbfe;
  background:#eff6ff;
  color:#1d4ed8;
}

/* SAVE BAR */
.savebar{
  position:sticky;
  bottom:0;
  z-index:45;
  display:flex;
  align-items:center;
  gap:12px;
  padding:13px 18px;
  background:rgba(255,255,255,.97);
  border-top:1px solid var(--border);
  backdrop-filter:blur(10px);
  box-shadow:0 -8px 24px rgba(15,23,42,.06);
}
.savebar button{
  min-height:40px;
  border:0;
  border-radius:10px;
  background:linear-gradient(135deg,var(--primary),var(--primary-dark));
  color:#fff;
  padding:10px 16px;
  font-size:11px;
  font-weight:900;
  box-shadow:0 8px 20px rgba(37,99,235,.18);
}
#saveState{
  color:var(--warning);
  font-size:10px;
  font-weight:700;
}

/* PREVIEW AREA */
.preview{
  min-width:0;
  display:flex;
  flex-direction:column;
  background:#e9eef5;
}
.previewbar{
  min-height:62px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 20px;
  background:#fff;
  border-bottom:1px solid var(--border);
}
.previewbar strong{
  color:var(--heading);
  font-size:13px;
}
.previewbar>div{
  display:flex;
  gap:6px;
}
.previewbar button{
  border:1px solid var(--border);
  border-radius:8px;
  background:#fff;
  color:#475569;
  padding:7px 9px;
  font-size:10px;
  font-weight:800;
}
.previewbar button:hover,
.previewbar button.active-device{
  border-color:#bfdbfe;
  background:#eff6ff;
  color:#1d4ed8;
}
.framewrap{
  flex:1;
  overflow:auto;
  display:flex;
  justify-content:center;
  align-items:flex-start;
  padding:22px;
  background:#e9eef5;
}
.framewrap iframe{
  width:100%;
  min-height:760px;
  height:calc(100vh - 106px);
  border:0;
  border-radius:12px;
  background:#fff;
  box-shadow:0 18px 60px rgba(15,23,42,.14);
  transition:width .22s ease;
}

/* LOGIN */
.login{
  min-height:100vh;
  display:grid;
  place-items:center;
  padding:20px;
  background:
    radial-gradient(circle at 20% 10%,rgba(59,130,246,.30),transparent 32%),
    linear-gradient(135deg,#020617,#172554 55%,#1d4ed8);
}
.login-box{
  width:min(100%,420px);
  padding:34px;
  border-radius:22px;
  background:#fff;
  box-shadow:0 30px 80px rgba(0,0,0,.34);
}
.login-logo{
  width:52px;
  height:52px;
  display:grid;
  place-items:center;
  border-radius:15px;
  background:linear-gradient(135deg,#2563eb,#1d4ed8);
  color:#fff;
  font-weight:900;
}
.login h1{
  margin:18px 0 5px;
  color:#0f172a;
  font-size:25px;
}
.login p{
  margin:0;
  color:#64748b;
  font-size:13px;
}
.login form{
  display:grid;
  gap:14px;
  margin:24px 0 18px;
}
.login label{
  display:grid;
  gap:7px;
  color:#475569;
  font-size:12px;
  font-weight:800;
}
.login input{
  width:100%;
  border:1px solid #cbd5e1;
  border-radius:10px;
  padding:11px 12px;
  outline:none;
}
.login input:focus{
  border-color:var(--primary);
  box-shadow:0 0 0 3px rgba(37,99,235,.10);
}
.login button{
  min-height:43px;
  border:0;
  border-radius:10px;
  background:linear-gradient(135deg,#2563eb,#1d4ed8);
  color:#fff;
  font-weight:900;
}
.alert{
  margin-top:16px;
  padding:10px;
  border-radius:9px;
  background:#fee2e2;
  color:#991b1b;
  font-size:11px;
  font-weight:700;
}

/* RESPONSIVE */
@media(max-width:1150px){
  .builder{grid-template-columns:380px minmax(0,1fr)}
}
@media(max-width:900px){
  .builder{grid-template-columns:350px minmax(0,1fr)}
}
@media(max-width:780px){
  .builder{
    grid-template-columns:1fr;
    height:auto;
  }
  .panel{
    border-right:0;
  }
  .preview{
    min-height:700px;
    border-top:1px solid var(--border);
  }
  .framewrap iframe{
    height:640px;
    min-height:640px;
  }
}
@media(max-width:520px){
  .panel>header{
    align-items:flex-start;
    flex-direction:column;
  }
  .tabs{top:104px}
  .builder-toolbar{grid-template-columns:1fr}
  .previewbar{
    align-items:flex-start;
    flex-direction:column;
    padding:12px;
  }
  .section-head-admin{
    grid-template-columns:28px 1fr;
  }
  .section-head-admin>div{
    grid-column:1/-1;
    justify-content:flex-end;
  }
  .framewrap{padding:10px}
}
