:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --txt: #e8ebf0;
  --txt-dim: #9aa3b2;
  --accent: #22a0d6;
  --accent-2: #4cb84a;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 360px;
  min-width: 360px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 22px 20px 40px;
  overflow-y: auto;
  height: 100vh;
}

.brand { margin-bottom: 6px; }
.brand img { height: 26px; display: block; }
.subtitle { font-size: 12.5px; color: var(--txt-dim); margin: 14px 0 20px; line-height: 1.4; }

.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--txt); margin-bottom: 7px; letter-spacing: .2px;
}
.hint { font-size: 11px; color: var(--txt-dim); margin-top: 6px; line-height: 1.4; }

input[type=text], input[type=url], textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; color: var(--txt); font-family: var(--font);
  font-size: 14px; padding: 11px 12px; resize: vertical; line-height: 1.4;
  transition: border-color .15s;
}
input[type=text]:focus, input[type=url]:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 70px; }

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--panel-2);
  padding: 22px 14px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: #1b2530; }
.dropzone .dz-icon { font-size: 26px; line-height: 1; margin-bottom: 8px; opacity: .75; }
.dropzone .dz-title { font-size: 13px; font-weight: 600; }
.dropzone .dz-sub { font-size: 11px; color: var(--txt-dim); margin-top: 4px; }
.dropzone.has-file { border-style: solid; border-color: var(--accent-2); }
.dz-thumb {
  width: 100%; height: 120px; object-fit: cover; border-radius: 8px;
  display: none; margin-bottom: 2px;
}
.dropzone.has-file .dz-thumb { display: block; }
.dropzone.has-file .dz-placeholder { display: none; }
input[type=file] { display: none; }

/* Range */
.range-row { display: flex; align-items: center; gap: 10px; }
input[type=range] { flex: 1; accent-color: var(--accent); }
.range-val { font-size: 11px; color: var(--txt-dim); width: 42px; text-align: right; }

/* Segmented (logo source) */
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; background: transparent; border: none; color: var(--txt-dim);
  font-family: var(--font); font-size: 12.5px; font-weight: 600;
  padding: 8px 6px; border-radius: 7px; cursor: pointer; transition: .15s;
}
.seg button.active { background: var(--accent); color: #fff; }

.divider { height: 1px; background: var(--line); margin: 22px 0; }

.dl-btns { display: flex; flex-direction: column; gap: 10px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; border: none; border-radius: 10px; cursor: pointer;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  padding: 14px; transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn-feed { background: linear-gradient(135deg, #22a0d6, #1b7fb0); color: #fff; }
.btn-story { background: linear-gradient(135deg, #4cb84a, #379a37); color: #fff; }
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
.btn svg { width: 17px; height: 17px; flex: none; }

/* ===== Assistente IA ===== */
.ai-box {
  background: linear-gradient(160deg, #141b26, #12161d);
  border: 1px solid #26405a;
  border-radius: var(--radius);
  padding: 16px 15px 17px;
  margin-bottom: 22px;
}
.ai-box .ai-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; margin-bottom: 4px; letter-spacing: .2px;
}
.ai-box .ai-head .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, #22a0d6, #4cb84a); flex: none;
  box-shadow: 0 0 8px rgba(34, 160, 214, .7);
}
.ai-box .ai-sub { font-size: 11px; color: var(--txt-dim); margin: 0 0 13px; line-height: 1.4; }
.ai-box .field { margin-bottom: 13px; }
.ai-box .field:last-of-type { margin-bottom: 0; }

.pw-row { display: flex; gap: 7px; }
.pw-row input { flex: 1; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  color: var(--txt-dim); cursor: pointer; width: 42px; flex: none;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { color: var(--txt); border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }

select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; color: var(--txt); font-family: var(--font);
  font-size: 13px; padding: 10px 11px; cursor: pointer;
}
select:focus { outline: none; border-color: var(--accent); }

.ai-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; border: none; border-radius: 10px; cursor: pointer;
  font-family: var(--font); font-size: 14px; font-weight: 700; color: #fff;
  padding: 13px; margin-top: 2px;
  background: linear-gradient(135deg, #22a0d6, #4cb84a);
  transition: transform .08s, filter .15s;
}
.ai-btn:hover { filter: brightness(1.07); }
.ai-btn:active { transform: translateY(1px); }
.ai-btn:disabled { opacity: .6; cursor: progress; filter: none; }
.ai-btn svg { width: 17px; height: 17px; flex: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2.4px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.ai-status { font-size: 11.5px; margin-top: 9px; line-height: 1.4; min-height: 0; }
.ai-status.err { color: #ff8080; }
.ai-status.ok { color: #7bd88f; }

/* legenda + copiar */
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.legend-head label { margin-bottom: 0; }
.copy-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  color: var(--txt-dim); font-family: var(--font); font-size: 11.5px; font-weight: 600;
  padding: 5px 10px; cursor: pointer; transition: .15s; display: flex; align-items: center; gap: 5px;
}
.copy-btn:hover { color: var(--txt); border-color: var(--accent); }
.copy-btn.copied { color: #7bd88f; border-color: #3a7a45; }
.copy-btn svg { width: 13px; height: 13px; }

/* ===== Preview area ===== */
.stage {
  flex: 1; overflow: auto; padding: 34px;
  display: flex; gap: 34px; align-items: flex-start; justify-content: center;
  flex-wrap: wrap;
}
.card { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.card .cap { font-size: 12.5px; color: var(--txt-dim); font-weight: 600; letter-spacing: .3px; }
.card .cap b { color: var(--txt); font-weight: 700; }
.canvas-wrap {
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  background: #000;
  position: relative;
}
canvas.preview { display: block; height: auto; }
#feedCanvas { width: 340px; }
#storyCanvas { width: 290px; }

/* enquadrador estilo recorte */
.canvas-wrap.has-bg canvas.preview { cursor: grab; touch-action: none; }
.canvas-wrap.cropping canvas.preview { cursor: grabbing; }
.crop-frame {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .65);
  opacity: 0; transition: opacity .15s;
}
.crop-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .15s;
  background-image:
    linear-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .5) 1px, transparent 1px);
  background-size: 100% 33.33%, 100% 33.33%, 33.33% 100%, 33.33% 100%;
  background-position: 0 33.33%, 0 66.66%, 33.33% 0, 66.66% 0;
  background-repeat: no-repeat;
}
.canvas-wrap.has-bg:hover .crop-frame,
.canvas-wrap.cropping .crop-frame { opacity: 1; }
.canvas-wrap.cropping .crop-grid { opacity: 1; }
.crop-handle {
  position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
  opacity: 0; transition: opacity .15s; pointer-events: none; touch-action: none;
  z-index: 3;
}
.canvas-wrap.has-bg .crop-handle { pointer-events: auto; }
.canvas-wrap.has-bg:hover .crop-handle,
.canvas-wrap.cropping .crop-handle { opacity: .95; }
.crop-handle.tl { top: 8px; left: 8px; cursor: nwse-resize; }
.crop-handle.tr { top: 8px; right: 8px; cursor: nesw-resize; }
.crop-handle.bl { bottom: 8px; left: 8px; cursor: nesw-resize; }
.crop-handle.br { bottom: 8px; right: 8px; cursor: nwse-resize; }

.frame-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--txt); font-family: var(--font); font-size: 12.5px; font-weight: 600;
  padding: 9px 12px; cursor: pointer; transition: .15s; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.frame-btn:hover { border-color: var(--accent); }
.frame-btn svg { width: 15px; height: 15px; }

@media (max-width: 1100px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .stage { padding: 24px 16px; }
}