/* =========================================================
   Bug Mug — estilos v2 com toolbar e editor side-by-side
   ========================================================= */

:root {
  --nav-h: 64px;
  --toolbar-h: 80px;
  --radius: 14px;
  --radius-sm: 8px;
  --accent: #e1131f;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"] {
  --bg: #eef1ef;
  --surface: #ffffff;
  --surface-2: #f4f6f4;
  --text: #1b1f1d;
  --muted: #5b655f;
  --border: rgba(20, 30, 25, 0.12);
  --shadow: rgba(20, 30, 25, 0.14);
  --navbar-bg: rgba(238, 241, 239, 0.6);
}

:root[data-theme="dark"] {
  --bg: #12161a;
  --surface: #1b2126;
  --surface-2: #20272c;
  --text: #eceff0;
  --muted: #9aa6a1;
  --border: rgba(255, 255, 255, 0.09);
  --shadow: rgba(0, 0, 0, 0.5);
  --navbar-bg: rgba(18, 22, 26, 0.55);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
  padding-top: var(--nav-h);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 .6em; }

h2 {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ---------- Navbar ---------- */

.navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  z-index: 50;
  display: flex;
  align-items: center;
  background: var(--navbar-bg);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .navbar { background: var(--surface); }
}

.navbar-inner {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -.01em;
}
.brand-bug { color: var(--text); }
.brand-mug { color: var(--accent); }

.theme-toggle {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}
.theme-toggle .icon { width: 18px; height: 18px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- Main layout ---------- */

main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
}

.editor-wrapper {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 4px 12px var(--shadow);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-group-end {
  margin-left: auto;
}

.tool-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  flex: none;
  transition: all .1s ease;
}
.tool-btn:hover {
  background: var(--border);
}
.tool-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.tool-btn svg {
  width: 20px;
  height: 20px;
}

.color-picker-label {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.color-picker-label input {
  width: 0;
  height: 0;
  opacity: 0;
}
.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: #000000;
  transition: border-color .1s ease;
}
.color-picker-label:hover .color-swatch {
  border-color: var(--accent);
}

.brush-slider {
  accent-color: var(--accent);
  width: 100px;
}

/* ---------- Editor main ---------- */

.editor-main {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1200px) {
  .editor-main {
    grid-template-columns: 1fr;
  }
  .right-panel {
    max-height: 400px;
    overflow-y: auto;
  }
}

/* ---------- Canvas container ---------- */

.canvas-container {
  position: relative;
  background: #ffffff;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px var(--shadow);
  border: 1px solid var(--border);
  aspect-ratio: 20 / 9;
  transition: border-color .15s ease;
}
.canvas-container.is-dragover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.canvas-drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 3px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  color: var(--accent);
  font-size: .95rem;
  font-weight: 600;
  z-index: 20;
}
/* fallback pra browsers sem color-mix */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .canvas-container.is-dragover { border-color: var(--accent); }
  .canvas-drop-overlay { background: rgba(225, 19, 31, 0.10); border-color: var(--accent); }
}

#designCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
#designCanvas.select-cursor { cursor: default; }
#designCanvas.move-cursor { cursor: grab; }
#designCanvas.move-cursor.is-dragging { cursor: grabbing; }

.export-menu {
  position: relative;
}

.export-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.export-btn:hover {
  filter: brightness(1.05);
}

/* ---------- Menus de exportação (dropdown) ---------- */

.dropdown-list {
  position: absolute;
  right: 0;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 30;
}
.dropdown-list[hidden] {
  display: none;
}
.dropdown-list.drop-up { bottom: calc(100% + 10px); }
.dropdown-list.drop-down { top: calc(100% + 10px); }

.dropdown-list button {
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 9px 10px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.dropdown-list button:hover {
  background: var(--surface-2);
}
.dropdown-list button:disabled {
  opacity: .5;
  cursor: default;
}

/* ---------- Cabeçalho da seção 3D + botão exportar ---------- */

.viewer-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}
.viewer-header h2 {
  margin: 0;
}

#exportMenu3D {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
}

.export-3d-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: .8rem;
  font-weight: 600;
  color: #f1efe9;
  cursor: pointer;
}
.export-3d-btn:hover {
  background: var(--surface-2);
}
.export-3d-btn:disabled {
  opacity: .6;
  cursor: default;
}
#exportMenu3D .dropdown-list {
  color: var(--text);
}

/* ---------- Right panel ---------- */

.right-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--nav-h) - 200px);
}

.tabs-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.tab-btn {
  flex: 1;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .1s ease;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.is-active {
  color: var(--accent);
  border-bottom: 3px solid var(--accent);
}

.tab-panel {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
}

/* ---------- Camadas ---------- */

.layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all .1s ease;
}
.layer-row:hover {
  background: var(--surface-2);
}
.layer-row.is-selected {
  border-color: var(--accent);
  background: var(--surface-2);
}

.layer-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}

.layer-name {
  flex: 1;
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-actions {
  display: flex;
  gap: 2px;
}
.layer-actions button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: .75rem;
  color: var(--muted);
  transition: all .1s ease;
}
.layer-actions button svg {
  width: 13px;
  height: 13px;
}
.layer-actions button:hover {
  background: var(--border);
  color: var(--text);
}

.layer-row-bg {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 10px;
  cursor: pointer;
}
.layer-thumb-bg {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex: none;
  display: block;
  background: #ffffff;
  border: 1px solid var(--border);
}
.layer-lock {
  flex: none;
  font-size: .8rem;
  opacity: .55;
}

/* ---------- Ajustes ---------- */

.adjust-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 12px;
}
.adjust-block h3 {
  margin: 0 0 8px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
}

.slider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: .8rem;
  margin-bottom: 8px;
}
.slider-row span {
  flex: 0 0 auto;
  color: var(--muted);
  min-width: 70px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.btn-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn {
  flex: 1;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .1s ease;
}
.btn:hover {
  background: var(--border);
}
.btn-danger {
  color: #b3432b;
}

/* ---------- Amostras ---------- */

.sample-gallery {
  display: grid;
  grid-auto-flow: dense;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

.sample-gallery button {
  display: block;
  width: 100%;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: auto;
  transition: all .1s ease;
}
.sample-gallery button:hover,
.sample-gallery button:focus-visible {
  border-color: var(--accent);
  outline: none;
  transform: scale(1.02);
}
.sample-gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- Upload ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 16px 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  font-size: .8rem;
  transition: all .1s ease;
}
.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}

/* ---------- Viewer 3D ---------- */

.viewer {
  margin-top: 40px;
  padding: 40px 20px 56px;
  border-radius: var(--radius);
  text-align: center;
  background: radial-gradient(120% 140% at 50% -10%, #28333a 0%, #11151a 65%);
  color: #f1efe9;
}

.viewer h2 {
  color: rgba(241, 239, 233, 0.6);
  margin-bottom: 28px;
}

.viewer-3d-box {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
}
.viewer-3d-box canvas {
  display: block;
  touch-action: none;
  cursor: grab;
}
.viewer-3d-box canvas:active {
  cursor: grabbing;
}

/* ---------- Accessibility ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
