/* ═══════════════════════════════════════════════════════
   WP THEME BUILDER — UI Styles
   ═══════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg0:     #030712;
  --bg1:     #060d1a;
  --bg2:     #0c1422;
  --bg3:     #111827;
  --bg4:     #1a2435;
  --border:  #1e2d40;
  --border2: #243044;
  --text:    #e2e8f0;
  --muted:   #8899aa;
  --dim:     #4a5568;
  --blue:    #2563eb;
  --red:     #ef4444;
  --green:   #22c55e;

  --topbar-h: 48px;
  --icon-nav-w: 48px;
  --panel-w: 258px;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg0);
  color: var(--text);
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.5;
}
input, select, textarea, button { font-family: inherit; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg1); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #334155; }

/* ── Top Bar ────────────────────────────────────────────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 12px; gap: 8px;
  z-index: 100;
  user-select: none;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; margin-right: 4px; }
.topbar-logo {
  width: 26px; height: 26px; border-radius: 6px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 900;
}
.topbar-title { font-size: 13px; font-weight: 800; color: #f1f5f9; letter-spacing: -.02em; white-space: nowrap; }
.topbar-badge {
  font-size: 9px; background: #1e3a5f; color: #60a5fa;
  padding: 2px 7px; border-radius: 10px; font-weight: 700;
}
.topbar-sep { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; }
.topbar-meta { font-size: 11px; color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Viewport switcher */
.viewport-switcher {
  display: flex; background: var(--bg3);
  border-radius: 5px; padding: 2px; gap: 2px;
}
.vp-btn {
  padding: 3px 9px; border-radius: 3px; border: none;
  background: transparent; color: var(--dim);
  font-size: 11px; transition: all .15s;
}
.vp-btn.active { background: var(--blue); color: #fff; }
.vp-btn:not(.active):hover { color: var(--muted); }

/* Toolbar buttons */
.tb-btn {
  padding: 4px 10px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--muted); font-size: 11px;
  transition: all .15s; white-space: nowrap;
}
.tb-btn:hover { color: var(--text); border-color: var(--border2); }
.tb-btn:disabled { opacity: .35; cursor: default; }
.tb-btn-primary {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border: none; color: #fff; font-weight: 700;
  padding: 5px 14px; font-size: 12px;
  box-shadow: 0 2px 8px rgba(37,99,235,.4);
}
.tb-btn-primary:hover { filter: brightness(1.1); }
.tb-btn-danger { border-color: rgba(239,68,68,.3); color: var(--red); }
.tb-btn-danger:hover { background: rgba(239,68,68,.1); }
.tb-btn-logout { color: var(--dim); }

/* Notification */
.notification {
  position: fixed; top: var(--topbar-h); left: 0; right: 0;
  padding: 7px 16px; font-size: 12px; text-align: center;
  z-index: 99; transition: opacity .3s;
}
.notification.success { background: #14532d; color: #86efac; }
.notification.error   { background: #7f1d1d; color: #fca5a5; }
.notification.hidden  { display: none; }

/* ── App Layout ─────────────────────────────────────────── */
#app {
  position: fixed;
  top: var(--topbar-h); left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ── Icon Nav ───────────────────────────────────────────── */
#icon-nav {
  width: var(--icon-nav-w);
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; padding: 6px 0;
  gap: 1px; flex-shrink: 0;
  overflow-y: auto;
}
.nav-icon {
  width: 36px; height: 36px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--dim);
  font-size: 13px; transition: all .15s;
  border-left: 2px solid transparent;
}
.nav-icon.active {
  background: var(--bg3); color: #60a5fa;
  border-left-color: var(--blue);
}
.nav-icon:not(.active):hover { color: var(--muted); background: var(--bg2); }
.nav-icon[data-panel="code"], .nav-icon[data-panel="wordpress"], .nav-icon[data-panel="snippets"] { font-size: 10px; font-weight: 700; }
.nav-icon-spacer { flex: 1; }

/* ── Settings Panel ─────────────────────────────────────── */
#settings-panel {
  width: var(--panel-w);
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
  transition: width .2s, opacity .2s;
}
#settings-panel.collapsed { width: 0; opacity: 0; overflow: hidden; }

#panel-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
#panel-title {
  font-size: 9px; font-weight: 800; color: var(--blue);
  text-transform: uppercase; letter-spacing: .12em;
}
#panel-counter { font-size: 9px; color: var(--dim); }

#panel-body {
  flex: 1; overflow-y: auto;
  padding: 4px 12px 16px;
}

/* ── Panel UI Components ────────────────────────────────── */
.sec-title {
  font-size: 9px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .14em; color: var(--blue);
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px; margin-bottom: 10px; margin-top: 16px;
}
.field { margin-bottom: 9px; }
.field-label {
  font-size: 10px; color: var(--muted);
  display: block; margin-bottom: 3px;
}
.field-hint { font-size: 9px; color: var(--dim); margin-top: 2px; }

.field input[type=text],
.field input[type=url],
.field input[type=number],
.field select,
.field textarea {
  width: 100%; padding: 5px 8px;
  background: var(--bg0); border: 1px solid var(--border2);
  border-radius: 4px; color: var(--text); font-size: 11px;
  outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--blue);
}
.field textarea { resize: vertical; line-height: 1.55; padding: 6px 8px; }
.field select { cursor: pointer; }
.field input[type=text].mono,
.field textarea.mono { font-family: 'Courier New', monospace; }

/* Row: label + control side by side */
.field-row {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}
.field-row .field-label { flex: 1; margin-bottom: 0; }

/* Color picker row */
.color-row {
  display: flex; align-items: center; gap: 5px;
}
.color-row input[type=color] {
  width: 26px; height: 26px; border: 1px solid var(--border2);
  border-radius: 4px; padding: 0; background: none;
  cursor: pointer; flex-shrink: 0;
}
.color-row input[type=text] {
  width: 80px; font-family: monospace; font-size: 10px;
  padding: 3px 6px;
}

/* Slider */
.slider-wrap { margin-bottom: 10px; }
.slider-top {
  display: flex; justify-content: space-between; margin-bottom: 3px;
}
.slider-label { font-size: 10px; color: var(--muted); }
.slider-val   { font-size: 10px; color: var(--blue); font-family: monospace; }
input[type=range] {
  width: 100%; accent-color: var(--blue); height: 3px; cursor: pointer;
}

/* Toggle */
.toggle-wrap {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 8px; gap: 8px;
}
.toggle-info .toggle-label { font-size: 11px; color: var(--muted); }
.toggle-info .toggle-hint  { font-size: 9px;  color: var(--dim); margin-top: 1px; }
.toggle {
  width: 34px; height: 18px; border-radius: 9px;
  background: var(--border2); cursor: pointer;
  position: relative; transition: background .18s;
  flex-shrink: 0; border: none;
}
.toggle.on { background: var(--blue); }
.toggle::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: left .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.toggle.on::after { left: 18px; }

/* Color palette grid */
.palette-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 4px; margin-bottom: 8px;
}
.palette-btn {
  padding: 5px 6px; border: 1px solid var(--border2);
  border-radius: 4px; background: var(--bg3);
  cursor: pointer; display: flex; align-items: center;
  gap: 4px; font-size: 9px; color: var(--muted);
  transition: border-color .15s;
}
.palette-btn:hover { border-color: var(--blue); }
.palette-dots { display: flex; gap: 2px; }
.palette-dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid var(--border);
}

/* Card (for nav menus, sidebars, CPT) */
.item-card {
  background: var(--bg4); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px; margin-bottom: 8px;
}
.item-card-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 8px;
}
.item-card-title { font-size: 11px; font-weight: 700; color: var(--text); }
.btn-del {
  padding: 2px 8px; background: transparent;
  border: 1px solid rgba(239,68,68,.3); border-radius: 4px;
  color: var(--red); font-size: 10px;
}
.btn-del:hover { background: rgba(239,68,68,.1); }
.btn-add {
  width: 100%; padding: 6px; margin-top: 6px;
  background: var(--bg4); border: 1px dashed var(--border2);
  border-radius: 4px; color: var(--blue);
  font-size: 11px; font-weight: 600;
  transition: border-color .15s;
}
.btn-add:hover { border-color: var(--blue); }

/* ── Content Area ───────────────────────────────────────── */
#content-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}
#preview-bar {
  padding: 5px 14px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 10px; color: var(--dim); flex-shrink: 0;
}
.sep { color: var(--border); }
.vp-label { color: #60a5fa; }

#preview-wrap {
  flex: 1; overflow: auto;
  background: #020817;
  display: flex; flex-direction: column;
  align-items: center; padding: 20px;
}


#preview-wrap[data-builder-viewport="mobile"] #preview-stage {
  outline: 1px solid rgba(96,165,250,.35);
}
#preview-wrap[data-builder-viewport="mobile"] {
  align-items: center;
}

#preview-stage {
  position: relative;
  border-radius: 12px;
  box-shadow: 0 12px 80px rgba(0,0,0,.6);
  overflow: hidden;
  background: #fff;
  max-width: 100%;
  margin-inline: auto;
}

#preview-frame {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  border: 0;
  background: #fff;
  transform-origin: top left;
  will-change: transform;
}

/* ── File Viewer ────────────────────────────────────────── */
#file-viewer {
  flex: 1; display: flex; overflow: hidden;
  background: var(--bg2);
}
#file-viewer.hidden { display: none; }
#preview-wrap.hidden { display: none; }

#file-tree {
  width: 190px; background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto; flex-shrink: 0;
}
.file-tree-header {
  padding: 7px 12px; font-size: 9px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--dim); border-bottom: 1px solid var(--border);
}
.file-item {
  padding: 4px 10px; font-size: 10px; cursor: pointer;
  font-family: monospace; color: var(--dim);
  border-left: 2px solid transparent;
  display: flex; align-items: center; gap: 5px;
  transition: all .1s;
}
.file-item:hover { color: var(--muted); background: var(--bg3); }
.file-item.active {
  color: #60a5fa; background: var(--bg3);
  border-left-color: var(--blue);
}
.file-item-icon { font-size: 9px; }

#file-content {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
#file-content-header {
  padding: 5px 14px; border-bottom: 1px solid var(--border);
  font-size: 10px; color: var(--dim);
  display: flex; justify-content: space-between;
  background: var(--bg3); flex-shrink: 0;
  font-family: monospace;
}
#file-content-body {
  flex: 1; overflow: auto; padding: 12px 16px;
  font-size: 10px; font-family: 'Courier New', monospace;
  color: #e2e8f0; line-height: 1.65;
  white-space: pre; margin: 0;
}


/* ── Media Library ─────────────────────────────────────── */
.upload-dropzone {
  border: 1px dashed var(--border2);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(37,99,235,.08), rgba(124,58,237,.06));
  padding: 16px;
  margin-bottom: 12px;
  text-align: center;
}
.upload-dropzone.dragover {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px rgba(37,99,235,.25), 0 10px 30px rgba(37,99,235,.18);
}
.upload-drop-icon { font-size: 24px; margin-bottom: 6px; }
.upload-drop-title { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.upload-drop-subtitle { font-size: 10px; color: var(--muted); margin-bottom: 12px; line-height: 1.6; }
.media-card { overflow: hidden; }
.media-thumb-wrap {
  background: var(--bg0);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}
.media-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: linear-gradient(135deg, rgba(37,99,235,.2), rgba(124,58,237,.15));
}
.media-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.media-badge {
  display: inline-flex; align-items: center;
  font-size: 9px; font-weight: 700;
  color: #dbeafe; background: rgba(37,99,235,.18);
  border: 1px solid rgba(96,165,250,.22);
  border-radius: 999px; padding: 3px 8px;
}
.media-badge-soft {
  color: var(--muted); background: var(--bg3); border-color: var(--border2);
}
.empty-state {
  padding: 12px; border: 1px dashed var(--border2); border-radius: 8px;
  color: var(--muted); background: var(--bg3); line-height: 1.6; font-size: 11px;
}
.binary-preview { display: grid; gap: 12px; }
.binary-preview-image {
  display: block; max-width: 100%; height: auto; border-radius: 8px;
  background: #fff; border: 1px solid var(--border2);
}
.binary-preview-meta { color: var(--muted); font-size: 11px; line-height: 1.6; }
.tb-btn-mobile { display: none; }

@media (max-width: 980px) {
  #topbar {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #topbar::-webkit-scrollbar { display: none; }
  .tb-btn-mobile { display: inline-flex; }
  #icon-nav {
    width: 100%;
    height: 50px;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .nav-icon-spacer { display: none; }
  #app { flex-direction: column; }
  #settings-panel {
    position: fixed;
    top: calc(var(--topbar-h) + 50px);
    left: 0;
    bottom: 0;
    width: min(100vw, 360px);
    z-index: 95;
    box-shadow: 0 16px 40px rgba(0,0,0,.45);
    transition: transform .2s ease, opacity .2s ease;
  }
  #settings-panel.collapsed {
    width: min(100vw, 360px);
    opacity: 1;
    transform: translateX(-102%);
  }
  #preview-bar { flex-wrap: wrap; }
}

@media (max-width: 680px) {
  #preview-wrap { padding: 12px; align-items: stretch; }
  #preview-stage { margin-inline: auto; }
  #file-viewer { flex-direction: column; }
  #file-tree {
    width: 100%; max-height: 160px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .palette-grid { grid-template-columns: 1fr; }
  .item-card-header { align-items: flex-start; gap: 8px; }
}
