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

:root {
  --bg: #16181d;
  --bg2: #1e2128;
  --bg3: #262a33;
  --border: #343945;
  --text: #e8eaf0;
  --text-dim: #9aa0ad;
  --accent: #4f8cff;
  --accent-hover: #6da1ff;
  --danger: #ff5470;
}

html, body { height: 100%; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
}

/* ============ Topbar ============ */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo { font-size: 17px; font-weight: 700; margin-right: 10px; user-select: none; }
.logo span { color: var(--accent); }

.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.spacer { flex: 1; }

#img-info { color: var(--text-dim); font-size: 12px; margin-right: 8px; }

/* ============ Buttons ============ */
.btn {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #2f3440; border-color: #454c5c; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.icon { padding: 7px 10px; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.wide { flex: 1; width: 100%; }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-row { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }

/* ============ Layout ============ */
#main { display: flex; flex: 1; min-height: 0; }

#toolbar {
  width: 92px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 8px 6px;
  gap: 4px;
  flex-shrink: 0;
  overflow-y: auto;
}

.tool-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-dim);
  padding: 9px 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  transition: background .15s, color .15s;
}
.tool-btn .ico { font-size: 19px; }
.tool-btn:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.tool-btn.active { background: var(--bg3); color: var(--accent); border-color: var(--border); }
.tool-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ============ Canvas area ============ */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    repeating-conic-gradient(#20232a 0 25%, #191c22 0 50%) 0 0 / 24px 24px;
}

#view, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#overlay { touch-action: none; }

#dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  background: var(--bg);
}
#dropzone.hidden { display: none; }
#dropzone.dragover .dz-inner { border-color: var(--accent); background: rgba(79,140,255,.08); }

.dz-inner {
  border: 2px dashed var(--border);
  border-radius: 18px;
  padding: 50px 70px;
  text-align: center;
  transition: border-color .2s, background .2s;
}
.dz-icon { font-size: 52px; margin-bottom: 12px; }
.dz-inner h2 { font-size: 20px; margin-bottom: 6px; }
.dz-inner p { color: var(--text-dim); margin: 8px 0; }
.dz-formats { font-size: 11px; letter-spacing: .5px; }

#zoom-box {
  position: absolute;
  bottom: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 4;
}
#zoom-box button {
  background: transparent;
  border: none;
  color: var(--text);
  width: 28px; height: 26px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
}
#zoom-box button:hover { background: var(--bg3); }
#zoom-label { font-size: 12px; color: var(--text-dim); min-width: 44px; text-align: center; }

/* ============ Side panel ============ */
#panel {
  width: 270px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  display: none;
}
#panel.open { display: block; }

.tool-panel { display: none; padding: 16px 14px 24px; }
.tool-panel.active { display: block; }
.tool-panel h3 { font-size: 15px; margin-bottom: 12px; }

.tool-panel label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 10px 0 4px;
}

.tool-panel input[type="number"],
.tool-panel input[type="text"],
.tool-panel textarea,
.tool-panel select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  margin-top: 4px;
}
.tool-panel input:focus, .tool-panel textarea:focus, .tool-panel select:focus {
  outline: none;
  border-color: var(--accent);
}

.tool-panel input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
}

.tool-panel input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  margin-top: 4px;
}

.row2 { display: flex; gap: 8px; }
.row2 label { flex: 1; }

.check {
  display: flex !important;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text) !important;
}
.check input { accent-color: var(--accent); }

.hint { font-size: 11.5px; color: var(--text-dim); line-height: 1.45; margin: 8px 0; }

/* ============ Âncora de canvas ============ */
.rs-anchor {
  display: grid;
  grid-template-columns: repeat(3, 22px);
  gap: 3px;
  margin: 6px 0 10px;
}
.rs-anchor button {
  width: 22px; height: 22px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  transition: background .1s, border-color .1s;
}
.rs-anchor button:hover { border-color: var(--accent); }
.rs-anchor button.rs-anc-sel { background: var(--accent); border-color: var(--accent); }

/* ============ Camadas ============ */
#layers-box {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.layers-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 6px;
}
.layers-head h3 { font-size: 14px; }
.layers-actions { display: flex; gap: 3px; }
.layers-actions .btn.small { padding: 3px 7px; font-size: 12px; }

#layers-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.ly-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}
.ly-row:hover { background: var(--bg3); }
.ly-row.active { background: var(--bg3); border-color: var(--accent); }
.ly-thumb {
  width: 44px;
  height: 33px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.ly-name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ly-eye {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
.ly-eye.off { opacity: .35; }
.ly-opacity-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-top: 10px;
}
.ly-opacity-label input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
}

/* ============ Refinamento (remover fundo) ============ */
.refine-box {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.refine-box h4 { font-size: 13px; margin-bottom: 8px; }

/* ============ Progress ============ */
.progress { margin: 12px 0; }
.progress.hidden { display: none; }
.progress-bar {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar > div {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .2s;
}

/* ============ GIF frames ============ */
.frames {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 10px 0;
  max-height: 220px;
  overflow-y: auto;
}
.frame-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: var(--bg);
}
.frame-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame-item .frame-n {
  position: absolute; top: 2px; left: 4px;
  font-size: 10px; color: #fff;
  text-shadow: 0 0 3px #000;
}
.frame-item .frame-x {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,.6);
  border: none; color: #fff;
  width: 17px; height: 17px;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  line-height: 1;
}
.frame-item .frame-x:hover { background: var(--danger); }

#gif-result { margin-top: 12px; }
#gif-result.hidden { display: none; }
#gif-preview {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  background:
    repeating-conic-gradient(#2a2e38 0 25%, #20242c 0 50%) 0 0 / 16px 16px;
}

/* ============ Export ============ */
.size-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 13px;
}
.size-box b { color: var(--accent); font-size: 15px; }

/* ============ Comparação (ampliar IA) ============ */
.compare-row {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.compare-row > div {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.compare-row canvas {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  image-rendering: pixelated;
}
.compare-row span { font-size: 11px; color: var(--text-dim); }

/* ============ Statusbar ============ */
#statusbar {
  display: flex;
  padding: 5px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ============ Toasts ============ */
#toast-area {
  position: fixed;
  bottom: 46px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  animation: toast-in .25s ease;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: #3dd68c; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ============ Scrollbars ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }
::-webkit-scrollbar-track { background: transparent; }
