:root {
  --bg: #0f1115;
  --panel: #171a21;
  --muted: #9aa4b2;
  --text: #e6e9ef;
  --primary: #6aa6ff;
  --primary-600: #4e8bf0;
  --success: #37cb8a;
  --danger: #ff6a6a;
  --border: #2a2f3a;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: auto; } /* permite rolagem da página */
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* header/footer removidos do layout atual */

.app-main {
  display: grid;
  grid-template-columns: auto 1fr; /* primeira coluna auto (baseada no conteúdo), segunda cresce */
  gap: 16px;
  padding: 16px;
  height: 100vh; /* altura exata da viewport */
  box-sizing: border-box;
}

.left, .right {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.left {
  width: 400px; /* largura fixa para o painel de controles */
  height: 100%; /* altura baseada no conteúdo */
}

.right {
  min-height: 0; /* permite encolher dentro do grid */
  overflow: auto; /* rolagem interna apenas se necessário */
}

.uploader {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 120px; /* altura mínima menor, baseada no conteúdo */
  flex: 1; /* cresce para preencher o espaço disponível */
}
.uploader.dragover { border-color: var(--primary); background: rgba(106, 166, 255, 0.06); }
.uploader-instructions { display: flex; align-items: center; gap: 8px; justify-content: center; flex-wrap: wrap; }
.uploader-instructions strong { color: var(--text); }
.uploader-hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* Make left column's drop area grow to fill remaining height responsively */
/* .left { flex: 1; } */
/* .left .uploader { flex: 1; } */

.thumbs { 
  display: grid; 
  grid-template-columns: repeat(5, 1fr); 
  gap: 8px; 
  position: relative;
}
.thumb {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  background: #0b0d11;
  cursor: grab;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.thumb.dragging {
  cursor: grabbing;
  transform: scale(1.05);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}
.thumb.drop-target {
  border-color: var(--primary);
  background: rgba(106, 166, 255, 0.1);
}
.thumb:not(.has-image) {
  cursor: default;
}

/* Single insertion bar (mais forte e consistente) */
#insertionBar {
  position: absolute;
  top: 4%;
  height: 92%;
  width: 8px;
  background: linear-gradient(180deg,#ffffff 0%, var(--primary) 15%, #4e8bf0 50%, var(--primary) 85%, #ffffff 100%);
  border-radius: 4px;
  box-shadow:
    0 0 6px #fff,
    0 0 14px var(--primary),
    0 0 28px rgba(106,166,255,0.9),
    0 0 42px rgba(106,166,255,0.6);
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) scaleY(0.9);
  transition: opacity .12s ease, left .08s ease;
  z-index: 1500;
}
body.drag-reordering #insertionBar { opacity: 1; animation: insertionPulse 1.4s infinite; }
@keyframes insertionPulse {
  0%,100% { box-shadow: 0 0 6px #fff,0 0 14px var(--primary),0 0 28px rgba(106,166,255,0.9),0 0 42px rgba(106,166,255,0.6); }
  50% { box-shadow: 0 0 10px #fff,0 0 20px var(--primary),0 0 38px rgba(106,166,255,1),0 0 54px rgba(106,166,255,0.8); }
}
.thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block; /* remove gaps inline e melhora layout */
  image-rendering: auto; /* mantém suavização padrão */
  transform: translateZ(0); /* cria layer e reduz artefatos de subpixel */
}
.thumb .remove {
  position: absolute;
  top: 6px; right: 6px;
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  padding: 4px 6px;
  cursor: pointer;
}

.controls { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
.controls label { display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }

.aspect { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aspect-buttons { 
  display: grid; 
  grid-template-columns: repeat(4, 1fr); 
  gap: 6px; 
  width: 100%;
}
/* aspecto dos botões de proporção (pílula com ícone + texto) */
.btn-aspect {
  height: 34px;
  padding: 0 12px;
  border-radius: 9999px; /* pílula */
  font-size: 13px;
  line-height: 1;
  gap: 8px;
}
.btn-aspect svg { display: block; }
.btn-aspect[aria-pressed="true"] {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
  color: var(--primary);
}
.btn-aspect[aria-pressed="true"] span { color: var(--text); }

.background-option {
  display: flex;
  align-items: center;
  margin-top: 8px;
}

.options-row {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: -4px;
}

.options {
  display: block;
  width: 100%;
}
.option-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-toggle {
  height: 26px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px; /* pílula */
  font-size: 12px;
  font-weight: 500; /* peso fixo para evitar shift */
  line-height: 1;
  /* remover contorno/borda visível */
  border: 0;
  /* fundo cinza quando desativado */
  background: #1c222c;
  color: var(--text);
  white-space: nowrap; /* evita quebra que altere altura */
}
.btn-toggle[aria-pressed="true"] {
  /* destacar com fundo colorido, sem contorno */
  background: var(--primary);
  color: #0b0d11;
  border: 0;
  box-shadow: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkmark {
  width: 18px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #11151b;
  position: relative;
  transition: all 0.2s ease;
}

.checkbox-label:hover .checkmark {
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid #0b0d11;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #11151b;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  text-decoration: none;
}
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary-600); color: #0b0d11; font-weight: 600; }
.btn.primary:hover { background: var(--primary-600); }
.btn.success { background: var(--success); border-color: #2aa872; color: #0b0d11; font-weight: 600; }
.btn.danger { background: var(--danger); border-color: #e75f5f; color: #0b0d11; font-weight: 600; }
.btn.outline { background: transparent; color: var(--text); }

.preview { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.preview-frame {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0b0d11;
 
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 8px;
}
.preview-frame img {
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  width: auto;
  height: auto;
  display: none;
  object-fit: contain;
  image-rendering: auto;
  backface-visibility: hidden; /* ajuda com transform glitches */
}
.preview-frame .placeholder { position: absolute; color: var(--muted); }

.download { display: flex; justify-content: center; }

.status { min-height: 18px; color: var(--muted); font-size: 12px; }

/* Overrides to guarantee option toggles are borderless, fully rounded, smaller, and gray when inactive */
.option-buttons .btn-toggle {
  height: 24px;
  border: 0 !important;
  border-radius: 9999px !important;
  background: #1c222c;
  color: var(--text);
}
.option-buttons .btn-toggle:hover {
  background: #222935;
  box-shadow: none;
  border: 0 !important;
}
.option-buttons .btn-toggle[aria-pressed="true"] {
  background: var(--primary);
  color: #0b0d11;
  border: 0 !important;
  box-shadow: none;
}

@media (max-width: 1000px) {
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr; /* primeira linha auto, segunda responsiva */
    height: 100vh; /* altura fixa da viewport */
    overflow: hidden; /* evita rolagem da página */
  }
  .left {
    width: auto; /* largura automática em mobile */
    height: auto; /* altura automática em mobile */
    overflow: visible; /* sem rolagem interna */
  }
  .right {
    min-height: 0; /* permite encolher */
    overflow: visible; /* remove rolagem interna em mobile */
    display: flex;
    flex-direction: column;
  }
  .preview {
    flex: 1;
    min-height: 125px; /* altura mínima para a prévia */
  }
  .preview-frame {
    min-height: 100%; /* altura mínima menor em mobile */
  }
  
  /* Ajuste do botão download em mobile */
  .download {
    padding: 16px; /* padding maior */
    flex-shrink: 0; /* não encolhe */
    background: var(--panel); /* mesmo fundo do painel */
  }
  
  #btnDownload {
    width: 100%; /* ocupa toda a largura disponível */
    max-width: none; /* remove limitação de largura */
    padding: 12px 16px; /* padding maior para melhor touch */
  }
}
