:root {
  --bg-dark: #0f1115;
  --panel: #16213e;
  --border: #2a2a4e;
  --accent: #e94560;
  --success: #4caf50;
  --text: #eaeaea;
  --text-muted: #888;
  --snap-line: #b026ff;
}

* { box-sizing: border-box; outline: none; }

body { 
  margin: 0; font-family: system-ui, -apple-system, sans-serif; 
  background: var(--bg-dark); color: var(--text); 
  height: 100vh; display: flex; overflow: hidden; 
}

/* --- SIDEBAR --- */
.sidebar {
  width: 380px; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 200;
  transition: margin 0.3s ease; flex-shrink: 0;
  box-shadow: 5px 0 15px rgba(0,0,0,0.3);
}

.sidebar-header {
  padding: 15px; border-bottom: 1px solid var(--border); 
  font-weight: 800; letter-spacing: 1px; color: #fff;
  background: rgba(0,0,0,0.2); 
  display: flex; justify-content: space-between; align-items: center;
}

.sidebar-tabs { display: flex; background: #0a0a12; }
.sidebar-tab { flex: 1; padding: 10px; text-align: center; cursor: pointer; border-bottom: 2px solid transparent; font-size: 12px; font-weight: bold; color: #666; }
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: #1a1a2e; }

.sidebar-content {
  flex: 1; overflow-y: auto; padding: 15px; position: relative;
}

.sidebar-content::-webkit-scrollbar { width: 6px; }
.sidebar-content::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.panel-section { display: none; }
.panel-section.active { display: block; }

.group { margin-bottom: 25px; padding-bottom: 15px; border-bottom: 1px solid var(--border); }
.group h3 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }

button {
  background: #2a2a4e; border: 1px solid #3e3e6e; color: #fff; 
  padding: 10px; border-radius: 6px; cursor: pointer; transition: 0.2s; font-weight: 600; font-size: 13px;
}
button:hover { background: #3e3e6e; }
button:active { transform: translateY(1px); }

button.primary { background: var(--accent); border-color: var(--accent); box-shadow: 0 4px 15px rgba(233, 69, 96, 0.3); }
button.special { background: linear-gradient(135deg, #00c6ff, #0072ff); border:none; box-shadow: 0 4px 15px rgba(0, 114, 255, 0.4); }
button.success { background: var(--success); border-color: var(--success); color:#fff; }
button.danger { background: #5a1a1a; border-color: #7a2a2a; color: #ffcccc; }
button.full-width { width: 100%; margin-top: 5px; }
button.sm { padding: 4px 8px; font-size: 11px; min-width: 30px; }

.mode-btns { display:flex; gap:10px; }
.mode-btns button { flex:1; display:flex; align-items:center; justify-content:center; gap:5px;}
.mode-btns button.active { background: #fff; color:#000; border-color:#fff; }

label { display: block; font-size: 11px; margin-bottom: 5px; color: #ccc; margin-top: 12px; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; background: #0a0a12; border: 1px solid var(--border); 
  color: #fff; padding: 10px; border-radius: 4px; font-size: 13px; font-family: inherit;
}
input[type="color"] { width: 100%; height: 40px; padding: 0; border: none; cursor: pointer; background: none; }

textarea { resize: vertical; min-height: 80px; line-height: 1.4; }

.slider-row { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
input[type="range"] { flex: 1; cursor: pointer; accent-color: var(--accent); }

.val-input { 
  width: 55px !important; font-size: 11px !important; text-align: center;
  padding: 4px !important; background: #000 !important; color: var(--accent) !important;
  border: 1px solid #333 !important; border-radius: 4px !important; -moz-appearance: textfield;
}
.val-input::-webkit-outer-spin-button, .val-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* --- CANVAS AREA --- */
.main-area {
  flex: 1; display: flex; flex-direction: column; position: relative;
  background: #000; overflow: hidden;
}

.toolbar {
  height: 50px; background: #1a1a2e; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  z-index: 100; flex-shrink: 0;
}

.canvas-wrapper {
  flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center;
  padding: 40px; position: relative;
  background-image: 
    linear-gradient(45deg, #111 25%, transparent 25%), 
    linear-gradient(-45deg, #111 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #111 75%), 
    linear-gradient(-45deg, transparent 75%, #111 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#canvas {
  width: 1200px;
  height: 500px;
  background: #fff; 
  color: #333; 
  position: relative; 
  box-shadow: 0 0 50px rgba(0,0,0,0.8);
  transition: width 0.3s ease, height 0.3s ease;
  overflow: hidden; 
  z-index: 1; flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

/* --- BUILDER MOBILE VIEW OVERRIDES --- */
#canvas.mobile-view { 
    width: 380px !important; display: flex !important; 
    flex-direction: column !important; padding: 20px 0 !important;
    min-height: 600px; justify-content:flex-start;
}

.el {
  position: absolute; cursor: grab; 
  border: 1px dashed transparent; user-select: none;
  min-width: 50px; min-height: 30px;
  z-index: 10; box-sizing: border-box;
}
.el:hover { border: 1px dashed rgba(233, 69, 96, 0.5); }
.el.selected { border: 2px solid var(--accent); z-index: 100; cursor: move; }

#canvas.mobile-view .el {
  position: relative !important; left: auto !important; top: auto !important;
  width: var(--m-width, 100%) !important; margin-bottom: 15px; transform: none !important;
  order: var(--m-order, 0);
  align-self: center;
  height: auto !important;
  min-height: auto !important;
}

/* Smart Card Styles */
.el-card {
    background: transparent; overflow: hidden;
    display: flex; flex-direction: column; 
    border-radius: 12px;
}
.el-card .card-img { position: relative; width: 100%; height: 200px; overflow: hidden; flex-shrink:0; }
.el-card .card-img img { 
    width: 100%; height: 100%; object-fit: cover; transition:0.3s; display:block; 
    transform: scale(var(--zoom, 1));
    object-position: var(--pan-x, 50%) var(--pan-y, 50%);
}
.el-card .card-overlay { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition:0.3s; }

.el-card .card-content { 
    padding: 15px; display: flex; flex-direction: column; gap: 8px; position:relative;
    justify-content: center;
}
.el-card h3 { margin: 0; font-weight: 800; line-height: 1.2; }
.el-card p { margin: 0; line-height: 1.5; opacity: 0.9; word-wrap: break-word; overflow-wrap: break-word; }
.el-card a.c-btn {
    display: inline-block; text-decoration: none; align-self: flex-start;
    padding: 10px 25px; border-radius: 50px; font-weight: bold;
    margin-top: 5px; box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.layout-top { flex-direction: column; }
.layout-side { flex-direction: row; align-items: center; padding: 10px; gap: 20px; }
.layout-side .card-img { width: 40%; height: auto; aspect-ratio: 1/1; border-radius: 12px; box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
.layout-side .card-content { width: 60%; padding: 0; }

.layout-overlay { position: relative; display: block; }
.layout-overlay .card-img { width: 100%; height: 100%; position: absolute; inset: 0; z-index: 0; }
.layout-overlay .card-content { position: relative; z-index: 2; height: 100%; align-items: center; text-align: center; }
.layout-overlay .c-btn { align-self: center; }

#canvas.mobile-view .el-card.layout-side { flex-direction: column !important; align-items: flex-start !important; }
#canvas.mobile-view .el-card.layout-side .card-img { width: 100% !important; height: 200px !important; aspect-ratio: auto; }
#canvas.mobile-view .el-card.layout-side .card-content { width: 100% !important; padding: 15px 5px !important; text-align: left; }

.el-h { color: #0b1b3a; line-height: 1.2; font-weight: 800; margin:0; }
.el-p { color: #333; line-height: 1.5; font-weight: 400; margin:0; }

.el-img { overflow: hidden; border-radius: 12px; background: #eee; display: flex; align-items: center; justify-content: center; }
.el-img img { display: block; width: 100%; height: 100%; object-fit: cover; pointer-events: none; transform: scale(var(--zoom, 1)); object-position: var(--pan-x, 50%) var(--pan-y, 50%); }
.el-img.empty::after { content: "IMAGE PLACEHOLDER"; color: #999; font-weight: bold; font-size:10px; }
.el-img:not(.empty) { background: transparent !important; }

/* Backgrounds */
.bg-white { background: #ffffff; }
.bg-gray { background: #e0e5ec; }
.bg-dark { background: #0f1115; }

/* Modal */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 2000; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-box { background: var(--panel); padding: 25px; width: 600px; max-width: 90%; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.modal textarea { height: 300px; width:100%; font-family: monospace; font-size: 12px; margin-bottom: 15px; color: #4af; background: #111; border: 1px solid #333; }
.modal h3 { margin-top: 0; color: #fff; }

body.is-fullscreen .sidebar { margin-left: -380px; }
body.is-fullscreen .toolbar { margin-top: -50px; }
body.is-fullscreen .canvas-wrapper { padding: 0; background: #000; align-items: center; }
body.is-fullscreen #canvas { transform: none !important; box-shadow: none; border-radius: 0; width: 100vw !important; height: 100vh !important; }
#exit-fs-btn { position: fixed; top: 20px; right: 20px; z-index: 1000; padding: 12px 25px; display: none; background: rgba(0,0,0,0.8); border: 1px solid rgba(255,255,255,0.2); backdrop-filter: blur(5px); }
body.is-fullscreen #exit-fs-btn { display: block; }

.view-alert {
    display:none; text-align:center; background:#ff9800; color:#000; 
    font-weight:bold; font-size:11px; padding:5px; border-radius:4px; margin-bottom:10px;
}