/* ============================================================
   Wally — Wallpaper + Logo Compositor
   Corporate blue / black accent theme
   ============================================================ */
:root {
  --bg:            #0a0e17;
  --bg-2:          #0f1522;
  --panel:         #121a2b;
  --panel-2:       #172236;
  --border:        #22304a;
  --blue:          #1f6feb;
  --blue-bright:    #3b8bff;
  --blue-deep:     #0b3d91;
  --blue-glow:     rgba(59,139,255,0.35);
  --text:          #e8eef8;
  --text-dim:      #90a0bd;
  --text-mute:     #5f7091;
  --black-accent:  #05070c;
  --success:       #2ecc71;
  --danger:        #e74c3c;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 10px 40px rgba(0,0,0,0.45);
  --font:          -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(31,111,235,0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(11,61,145,0.18), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  background: linear-gradient(180deg, var(--black-accent), rgba(5,7,12,0.6));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--blue-bright), var(--blue-deep));
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: #fff;
  box-shadow: 0 0 18px var(--blue-glow);
}
.brand h1 { font-size: 20px; letter-spacing: 0.5px; font-weight: 700; }
.brand span.sub { font-size: 12px; color: var(--text-dim); display:block; font-weight:400; letter-spacing:0.3px;}
.topbar-actions { display: flex; gap: 10px; }

/* ---------- Layout ---------- */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 0;
  min-height: 0;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  padding: 22px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.step {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  position: relative;
}
.step-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.step-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-bright), var(--blue-deep));
  color: #fff; font-weight: 700; font-size: 13px;
  display: grid; place-items: center;
  box-shadow: 0 0 12px var(--blue-glow);
}
.step-head h2 { font-size: 14px; font-weight: 600; letter-spacing: 0.3px; }
.step-head .hint { font-size: 11px; color: var(--text-mute); margin-left: auto; }

label.field-label {
  display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-dim); margin-bottom: 6px;
}

/* Custom dropdown */
.dropdown { position: relative; user-select: none; }
.dropdown-toggle {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer;
  font-size: 13px; transition: border-color .15s, box-shadow .15s;
}
.dropdown-toggle:hover { border-color: var(--blue); }
.dropdown.open .dropdown-toggle { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); }
.dropdown-toggle img {
  width: 34px; height: 22px; object-fit: cover; border-radius: 4px;
  background: #000; flex-shrink: 0; border:1px solid var(--border);
}
.dropdown-toggle .dd-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-toggle .caret { color: var(--text-dim); transition: transform .2s; }
.dropdown.open .caret { transform: rotate(180deg); }

.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 320px; overflow-y: auto;
  z-index: 40; box-shadow: var(--shadow);
  display: none; padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; }
.dd-search {
  width: 100%; padding: 8px 10px; margin-bottom: 6px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 12px;
}
.dd-search:focus { outline: none; border-color: var(--blue); }
.dd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 6px; cursor: pointer;
  font-size: 13px;
}
.dd-item:hover { background: rgba(59,139,255,0.14); }
.dd-item.selected { background: rgba(59,139,255,0.22); }
.dd-item img {
  width: 46px; height: 30px; object-fit: cover; border-radius: 4px;
  background: #0006; border:1px solid var(--border); flex-shrink:0;
}
.dd-item.logo img { object-fit: contain; background:
  repeating-conic-gradient(#1b2740 0% 25%, #223050 0% 50%) 50% / 12px 12px; }
.dd-empty { padding: 14px; text-align: center; color: var(--text-mute); font-size: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--panel-2);
  color: var(--text); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; text-decoration: none;
}
.btn:hover { border-color: var(--blue); background: rgba(59,139,255,0.12); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--blue-bright), var(--blue-deep));
  border-color: transparent; color: #fff;
  box-shadow: 0 4px 18px var(--blue-glow);
}
.btn-primary:hover { filter: brightness(1.1); background: linear-gradient(135deg, var(--blue-bright), var(--blue-deep)); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* Logo controls */
.logo-controls { margin-top: 14px; display: none; }
.logo-controls.show { display: block; }
.ctrl-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ctrl-row label { font-size: 12px; color: var(--text-dim); width: 70px; }
.ctrl-row input[type="range"] { flex: 1; accent-color: var(--blue-bright); }
.ctrl-row .val { font-size: 12px; color: var(--text); width: 42px; text-align: right; }

/* ---------- Stage ---------- */
.stage-wrap {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 0; padding: 24px;
}
.stage-toolbar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.stage-toolbar .spacer { flex: 1; }
.badge-dim { font-size: 12px; color: var(--text-mute); }

.canvas-frame {
  flex: 1; display: grid; place-items: center;
  background:
    linear-gradient(45deg, #0c111c 25%, transparent 25%) -10px 0/ 20px 20px,
    linear-gradient(-45deg, #0c111c 25%, transparent 25%) -10px 0/ 20px 20px,
    linear-gradient(45deg, transparent 75%, #0c111c 75%) -10px 0/ 20px 20px,
    linear-gradient(-45deg, transparent 75%, #0c111c 75%) -10px 0/ 20px 20px,
    var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  position: relative;
}
#stage {
  position: relative;
  max-width: 100%; max-height: 100%;
  box-shadow: var(--shadow);
  background: #000;
}
#stage img.wallpaper {
  display: block; max-width: 100%; max-height: calc(100vh - 220px);
  width: auto; height: auto;
}
#stage .placeholder {
  width: min(70vw, 900px); aspect-ratio: 16/9;
  display: grid; place-items: center; text-align: center;
  color: var(--text-mute); padding: 40px;
}
#stage .placeholder .big { font-size: 48px; margin-bottom: 12px; opacity:.5;}

/* Logo overlay element */
.logo-layer {
  position: absolute; cursor: move; touch-action: none;
  border: 1.5px dashed transparent;
}
.logo-layer.active { border-color: var(--blue-bright); }
.logo-layer img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; }
.logo-layer .handle {
  position: absolute; width: 14px; height: 14px;
  background: var(--blue-bright); border: 2px solid #fff;
  border-radius: 50%; display: none; z-index: 3;
  box-shadow: 0 0 6px var(--blue-glow);
}
.logo-layer.active .handle { display: block; }
.logo-layer .handle.br { right: -8px; bottom: -8px; cursor: nwse-resize; }
.logo-layer .handle.bl { left: -8px; bottom: -8px; cursor: nesw-resize; }
.logo-layer .handle.tr { right: -8px; top: -8px; cursor: nesw-resize; }
.logo-layer .handle.tl { left: -8px; top: -8px; cursor: nwse-resize; }

/* Toast */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display:flex; flex-direction:column; gap:8px; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border);
  border-left: 3px solid var(--blue-bright);
  padding: 12px 18px; border-radius: 8px; color: var(--text);
  font-size: 13px; box-shadow: var(--shadow);
  animation: slideup .25s ease; min-width: 220px;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
@keyframes slideup { from { opacity:0; transform: translateY(10px);} to {opacity:1; transform:none;} }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #23324e; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #2e4066; }

/* Responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  #stage img.wallpaper { max-height: 50vh; }
}
