:root{
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --border: #2a2f3a;
  --text: #eceef1;
  --text-dim: #9aa2b1;
  --accent: #e0a458;
  --accent-2: #c98a3d;
  --danger: #e0665e;
  --radius: 10px;
  font-size: 15px;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app{ display:flex; flex-direction:column; min-height:100vh; }

/* Topbar */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding: 10px 18px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top:0; z-index: 50;
  flex-wrap: wrap; gap:8px;
}
.brand{ display:flex; align-items:center; gap:8px; font-weight:700; font-size:1.05rem; }
.brand-icon{ font-size:1.3rem; }
.topbar-actions{ display:flex; align-items:center; gap:8px; flex-wrap: wrap; }
.status-msg{ font-size:.8rem; color: var(--text-dim); margin-right:6px; min-height:1em; }

.btn{
  border:1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor:pointer;
  font-size:.85rem;
  font-weight:600;
  transition: transform .05s ease, filter .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:hover{ filter: brightness(1.15); }
.btn:active{ transform: scale(.97); }
.btn:disabled{ opacity:.4; cursor:not-allowed; }
.btn-primary{ background: linear-gradient(135deg, var(--accent), var(--accent-2)); color:#1a1200; border:none; }
.btn-secondary{ background: var(--panel-2); border-color: var(--accent-2); color: var(--accent); }
.btn-ghost{ background: transparent; }
.btn-sm{ padding:5px 10px; font-size:.75rem; }

/* Body layout */
.body{ display:flex; flex:1; min-height:0; }

.sidebar{
  width: 320px; flex-shrink:0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y:auto;
  padding: 14px;
  display:flex; flex-direction:column; gap:14px;
}

.panel{
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.panel h3{
  margin: 0 0 10px 0;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--accent);
}

.file-drop{
  display:flex; align-items:center; justify-content:center;
  text-align:center;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 10px;
  cursor:pointer;
  color: var(--text-dim);
  font-size: .82rem;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.file-drop:hover{ border-color: var(--accent); color: var(--text); background: rgba(224,164,88,.06); }
.file-drop-sm{ padding: 10px; }
.file-drop small{ color: var(--text-dim); font-weight:400; }

.row{ display:flex; gap:8px; align-items:center; margin-top:8px; flex-wrap: wrap; }
.row label{ font-size:.78rem; color: var(--text-dim); display:flex; align-items:center; gap:4px; }

input[type=color]{
  width: 34px; height: 30px; border:none; border-radius:6px; background:none; cursor:pointer; padding:0;
}
textarea{
  width:100%;
  background: var(--panel);
  border:1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .85rem;
  font-family: inherit;
  resize: vertical;
  margin-top: 4px;
}
input[type=text], input[type=number]{
  width:100%;
  background: var(--panel);
  border:1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .85rem;
}
select{
  background: var(--panel);
  border:1px solid var(--border);
  color: var(--text);
  padding:6px 8px;
  border-radius:8px;
  font-size:.8rem;
}

.slider-label{
  display:block; font-size:.78rem; color: var(--text-dim);
  margin-top:10px;
}
.slider-label span{ float:right; color: var(--text); font-variant-numeric: tabular-nums; }
input[type=range]{ width:100%; accent-color: var(--accent); margin-top:4px; }

.checkbox-row{ display:flex; align-items:center; gap:8px; font-size:.85rem; font-weight:600; cursor:pointer; }
.checkbox-row input{ width:16px; height:16px; accent-color: var(--accent); }

.subsection + .subsection{ margin-top:14px; border-top:1px solid var(--border); padding-top:12px; }
.indent{ margin-top:8px; padding-left: 4px; }
.disabled-block{ opacity:.4; pointer-events:none; transition: opacity .15s ease; }
.disabled-block.enabled{ opacity:1; pointer-events:auto; }

.swatches{ display:flex; gap:6px; flex-wrap:wrap; }
.swatch{
  width:22px; height:22px; border-radius:50%;
  border:1.5px solid var(--border); cursor:pointer;
}

.hint{ font-size:.72rem; color: var(--text-dim); margin: 8px 0 0 0; line-height:1.4; }
.hint.center{ text-align:center; }

.progress-wrap{ margin-top:10px; }
.progress-wrap.hidden{ display:none; }
.progress-bar{ height:6px; background: var(--panel); border-radius: 4px; overflow:hidden; }
.progress-fill{ height:100%; width:0%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .2s ease; }
.progress-fill.ai-indeterminate{
  width:40%; animation: ai-slide 1.1s ease-in-out infinite;
}
@keyframes ai-slide{
  0%{ margin-left:0%; }
  50%{ margin-left:60%; }
  100%{ margin-left:0%; }
}
#bgRemoveText{ font-size:.72rem; color: var(--text-dim); display:block; margin-top:4px; }

/* Canvas area */
.canvas-area{
  flex:1; min-width:0;
  display:flex; flex-direction:column; align-items:center;
  padding: 16px; gap: 12px; overflow:auto;
}

.size-tabs{ display:flex; gap:8px; flex-wrap:wrap; justify-content:center; }
.size-tab{
  background: var(--panel-2);
  border:1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor:pointer;
  font-size:.78rem;
  text-align:center;
  line-height:1.5;
}
.size-tab small{ color: var(--text-dim); font-weight:400; }
.size-tab.active{ border-color: var(--accent); color: var(--text); background: rgba(224,164,88,.1); }

.custom-size-inputs{ display:flex; gap:10px; align-items:center; font-size:.8rem; color:var(--text-dim); }
.custom-size-inputs.hidden{ display:none; }
.custom-size-inputs input{ width:80px; }

.canvas-stage{
  display:inline-flex;
  align-items:center; justify-content:center;
  max-width: 100%;
}

.size-canvas-wrap{
  display:none;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, #23262e 25%, transparent 25%),
    linear-gradient(-45deg, #23262e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #23262e 75%),
    linear-gradient(-45deg, transparent 75%, #23262e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #1a1d24;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.size-canvas-wrap.active{ display:block; }

.zoom-control{
  display:flex; align-items:center; gap:8px;
  font-size:.78rem; color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
}
.zoom-control input[type=range]{ width:140px; margin-top:0; }
.zoom-control span#viewZoomVal{ min-width:38px; text-align:right; color:var(--text); }

/* Product slots */
.product-slots{ display:flex; flex-direction:column; gap:10px; }
.product-slot{
  border:1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--panel);
}
.slot-header{
  font-size:.78rem; font-weight:700; color: var(--accent);
  margin-bottom:8px; text-transform:uppercase; letter-spacing:.03em;
}
.slot-thumb-wrap{ margin-bottom:8px; }
.slot-thumb{
  height: 70px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  display:flex; align-items:center; justify-content:center;
  font-size:.72rem; color: var(--text-dim);
  background-color: #14161b;
  background-size: 14px 14px, 14px 14px, 14px 14px, 14px 14px, cover;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0px, center;
  background-repeat: repeat, repeat, repeat, repeat, no-repeat;
}
.slot-thumb.has-image{ border-style: solid; }
.slot-thumb-placeholder{ padding: 0 8px; text-align:center; }
.slot-progress{ margin-bottom:8px; }
.slot-progress.hidden{ display:none; }
.slot-status-text{ font-size:.7rem; color: var(--text-dim); display:block; margin-top:3px; }
.slot-actions{ margin-top:8px; }
.slot-actions .btn{ flex:1; }

/* Tabs (bg type) */
.tabs{ display:flex; gap:4px; margin-bottom:10px; }
.tab-btn{
  flex:1; background: var(--panel); border:1px solid var(--border); color: var(--text-dim);
  padding:6px 4px; border-radius:8px; cursor:pointer; font-size:.75rem;
}
.tab-btn.active{ background: rgba(224,164,88,.12); border-color: var(--accent); color: var(--text); }
.tab-panel.hidden{ display:none; }

.user-chip{
  font-size:.78rem; color: var(--text-dim);
  background: var(--panel-2); border:1px solid var(--border);
  border-radius: 20px; padding: 6px 12px;
}

.credit-chip{
  font-size:.78rem; color: var(--accent);
  background: var(--panel-2); border:1px solid var(--accent);
  border-radius: 20px; padding: 6px 12px;
  font-weight: 600; white-space: nowrap;
}
.credit-chip.credit-low{ color:#f0a29c; border-color:#e0665e; }

.footer-note{
  text-align:center; font-size:.72rem; color: var(--text-dim);
  padding: 10px; border-top: 1px solid var(--border); background: var(--panel);
}

@media (max-width: 860px){
  .body{ flex-direction:column; }
  .sidebar{ width:auto; border-right:none; border-bottom:1px solid var(--border); max-height: 46vh; }
}
