:root{
  --bg: #eef2f7;
  --panel: #f4f6f9;
  --card: #ffffff;
  --border: #d7dde7;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --primary: #2563eb;
}

html, body{ height:100%; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

.navbar{
  background: #fff !important;
  border-bottom: 1px solid var(--border);
}
.navbar .nav-link, .navbar .navbar-brand{ color: var(--text) !important; }
.navbar .nav-link.active{ font-weight:600; }
.navbar .navbar-toggler{ border-color: var(--border); }
.navbar .navbar-toggler-icon{ filter: invert(1) grayscale(1) contrast(2); }

.app-shell{
  padding-top: 56px;
  padding-bottom: 6px;
}

.tool-card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(15,23,42,.05);
}

.workspace{
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 10px;
  height: calc(100vh - 70px);
  min-height: 520px;
}

.preview-side{
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 8px;
}
.preview-top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  flex: 0 0 auto;
}

.preview-body{
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.preview-body.has-thumbs{
  grid-template-columns: 112px 1fr;
}

.preview-main{
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.thumbs-rail{
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
  border-radius: 6px;
}

.thumbs-rail-label{
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 0 2px;
  flex: 0 0 auto;
}

.dropzone-inline{
  display: inline-flex;
  align-items: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #f8fafc;
  padding: 4px 8px;
}
.dropzone.dragover{
  border-color: var(--primary);
  background: #eff6ff;
}

.thumb-strip{
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-width: none;
}
.thumb{
  width: 100%;
  height: 110px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  background: #e5e7eb;
}
.thumb img{ width:100%; height:100%; object-fit:cover; display:block; }
.thumb.active{ border: 2px solid var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.2); }
.thumb .badge{
  position:absolute; bottom:4px; left:4px; font-size:10px; padding:.15em .4em;
}
.thumb-remove{
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  line-height: 20px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: rgba(15, 23, 42, 0.78);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.9;
  z-index: 2;
}
.thumb-remove:hover{
  opacity: 1;
  background: #dc2626;
}
.thumb:hover .thumb-remove,
.thumb.active .thumb-remove{
  opacity: 1;
}

.canvas-wrap{
  flex: 1 1 auto;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg,#e8edf5 25%,transparent 25%),
    linear-gradient(-45deg,#e8edf5 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,#e8edf5 75%),
    linear-gradient(-45deg,transparent 75%,#e8edf5 75%);
  background-size: 14px 14px;
  background-position: 0 0, 0 7px, 7px -7px, -7px 0;
  background-color: #f3f6fb;
}

.side-panel{
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}
.side-tabs{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: #fff;
}
.side-tab{
  text-align: center;
  padding: 10px 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.btn-check:checked + .side-tab{
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: #fff;
}

.side-body{
  padding: 10px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.ctrl-row{
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.btn-add{
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
  white-space: nowrap;
  min-width: 56px;
}

.check-row{
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  margin-bottom: 8px;
  color: var(--text);
}
.check-row input{ width: 15px; height: 15px; }

.ctrl-block{ margin-bottom: 10px; }
.ctrl-title{
  font-size: .78rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.num-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.num-label{ font-size: .78rem; color: var(--text); }
.num-ctrl{
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.num-btn{
  width: 28px;
  height: 28px;
  border: 0;
  background: #f3f4f6;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
}
.num-btn:hover{ background: #e5e7eb; }
.num-ctrl input{
  width: 54px;
  height: 28px;
  border: 0;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  font-size: .8rem;
  outline: none;
}

.swatch-row{
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.swatch{
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  padding: 0;
  cursor: pointer;
}
.swatch.rect{ border-radius: 4px; width: 26px; height: 18px; }
.swatch.active{ outline: 2px solid var(--primary); outline-offset: 1px; }
.color-pick{
  width: 28px !important;
  height: 28px !important;
  padding: 2px !important;
  border-radius: 6px;
}

.pos-grid{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.pos-btn{
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 6px 4px;
  font-size: .72rem;
  color: var(--text);
}
.pos-btn.active,
.pos-btn:hover{
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #0f766e;
}

.adv-box{
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: #fff;
  margin-bottom: 8px;
}
.adv-box summary{
  cursor: pointer;
  font-size: .78rem;
  font-weight: 600;
  color: var(--muted);
}
.adv-box[open] summary{ margin-bottom: 6px; }

.side-actions{ margin-top: 4px; }

.grid-box{
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.grid-sliders{
  margin-top: 8px;
  display: grid;
  gap: 8px;
}
.grid-sliders.is-disabled{
  opacity: .45;
  pointer-events: none;
}
.grid-slider-row{
  display: flex;
  align-items: center;
  gap: 8px;
}
.grid-ico{
  width: 18px;
  text-align: center;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1;
}
.grid-range{
  flex: 1 1 auto;
  accent-color: var(--accent);
}
.grid-val{
  min-width: 36px;
  text-align: right;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.form-control-sm, .form-select-sm{
  font-size: .8rem;
  padding: .28rem .5rem;
}

.footer{
  border-top: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
}
.link-muted{ color: var(--muted); text-decoration: none; }
.link-muted:hover{ color: var(--text); text-decoration: underline; }

.text-white-50{ color: var(--muted) !important; }
.text-white{ color: var(--text) !important; }

@media (max-width: 991.98px){
  .workspace{
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .preview-side{ min-height: 420px; height: 58vh; }
  .preview-body,
  .preview-body.has-thumbs{
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .preview-body.has-thumbs .thumbs-rail{
    max-height: 120px;
  }
  .thumb-strip{
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .thumb{
    width: 84px;
    height: 84px;
  }
  .side-panel{ max-height: none; }
  .canvas-wrap{ min-height: 300px; }
}
