/* --- ESTILOS GERAIS --- */
:root {
  --orange: #f8991e;
  --dark-gray: #343a40;
  --medium-gray: #6c757d;
  --light-gray: #f1f3f5;
  --border-color: #dee2e6;
  --background-color: #f8f9fa;
  --white: #ffffff;
  --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Poppins', sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background-color: var(--background-color);
  color: var(--dark-gray);
}

/* --- TOPBAR --- */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow);
  z-index: 10;
}

#controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

.controls-title {
  font-weight: 600;
  color: var(--dark-gray);
  margin-right: 10px;
  padding-right: 20px;
  border-right: 1px solid var(--border-color);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-group label {
  font-weight: 500;
  color: var(--dark-gray);
}

.input-stepper {
  display: flex;
}

.stepper-btn {
  background-color: var(--light-gray);
  border: 1px solid var(--border-color);
  color: var(--medium-gray);
  cursor: pointer;
  width: 38px;
  height: 38px;
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.stepper-btn:hover {
  background-color: var(--orange);
  color: var(--white);
  border-color: var(--orange);
}

.stepper-btn:first-child { border-radius: 6px 0 0 6px; }
.stepper-btn:last-child { border-radius: 0 6px 6px 0; }

#controls input[type="number"] {
  border: 1px solid var(--border-color);
  border-left: none;
  border-right: none;
  border-radius: 0;
  padding: 8px 5px;
  width: 60px;
  height: 38px;
  text-align: center;
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
  -moz-appearance: textfield;
  appearance: textfield;
}

#controls input[type="number"]::-webkit-inner-spin-button,
#controls input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#controls input[type="number"]:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(248, 153, 30, 0.25);
  position: relative;
  z-index: 1;
}

#top-bar button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: 'Poppins', sans-serif;
  transition: transform 0.1s, background-color 0.2s;
}

#top-bar button:hover {
  transform: translateY(-1px);
}

#clear-grid-btn {
  background-color: var(--medium-gray);
  color: var(--white);
}

#clear-grid-btn:hover {
  background-color: var(--dark-gray);
}

#generate-btn {
  background-color: var(--orange);
  color: var(--white);
  box-shadow: 0 2px 4px rgba(248, 153, 30, 0.2);
}

#generate-btn:hover {
  background-color: #e08810;
}

/* --- CONTAINER PRINCIPAL / CONTANT ÁREA --- */
#main-container {
  display: flex;
  flex: 1;
  min-height: 0;
}

#content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--light-gray);
}

#bottom-bar {
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  font-size: 12px;
  color: var(--medium-gray);
  flex-shrink: 0; 
}

#bottom-bar a {
  color: var(--dark-gray); /* Destaque sutil */
  font-weight: 500;
  text-decoration: none;
  transition: color 0.2s;
}

#bottom-bar a:hover {
  color: var(--orange); /* Destaque maior no hover */
}

#bottom-bar p span {
  font-size: 1.5em;
  position: relative;
  top: 1px;
}

/* --- SIDEBAR --- */
#sidebar {
  width: 220px;
  padding: 24px;
  background: var(--white);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: var(--shadow);
}

#sidebar h3 {
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--orange); /* Destaque laranja */
  font-weight: 600;
  color: var(--dark-gray);
}

.component {
  width: 120px;
  height: 120px;
  margin-bottom: 20px;
  background-color: #fdfdfd;
  background-size: 85%;
  background-repeat: no-repeat;
  background-position: center;
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  cursor: grab;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.component:hover {
  border-color: var(--orange);
  box-shadow: 0 0 10px rgba(248, 153, 30, 0.2);
}

.component[data-type="maxim-ar"] {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-1 -1 104 104"><path d="M0 0 L51 102 L102 0" stroke="%236c757d" stroke-width="2" fill="none"/></svg>');
}

.component[data-type="veneziana"] {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><g stroke="%236c757d" stroke-width="1"><line y1="5" x2="100" y2="5" x1="0"></line><line y1="15" x2="100" y2="15" x1="0"></line><line y1="25" x2="100" y2="25" x1="0"></line><line y1="35" x2="100" y2="35" x1="0"></line><line y1="45" x2="100" y2="45" x1="0"></line><line y1="55" x2="100" y2="55" x1="0"></line><line y1="65" x2="100" y2="65" x1="0"></line><line y1="75" x2="100" y2="75" x1="0"></line><line y1="85" x2="100" y2="85" x1="0"></line><line y1="95" x2="100" y2="95" x1="0"></line></g></svg>');
}

.component[data-type="giro"] {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 2 L75 50 L25 98" stroke="%236c757d" stroke-width="2" fill="none"/></svg>');
}

.component {
  position: relative;
}

.component::after {
  content: attr(data-tooltip); 
  position: absolute;
  top: 50%;                
  left: 100%;               
  transform: translateY(-50%);
  margin-left: 24px;         
  
  background-color: var(--dark-gray);
  color: var(--white);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap; 

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 20;
}

.component::before {
  content: '';
  position: absolute;
  top: 50%;               
  left: 100%;               
  transform: translateY(-50%); 
  margin-left: 9px;        

  border-width: 6px;
  border-style: solid;
  border-color: transparent var(--dark-gray) transparent transparent;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 20;
}

.component:hover::after,
.component:hover::before {
  opacity: 1;
  visibility: visible;
}

/* --- ÁREA DO CROQUI (CANVAS) --- */
#canvas-container {
  flex: 1;
  overflow: auto;
  position: relative;
  padding: 30px;
}

#croqui-wrapper {
  position: absolute;
  display: inline-grid;
  grid-template-areas: "corner top" "left grid";
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  background: var(--white);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.07);
}

#grid-container {
  grid-area: grid;
  position: relative;
  background: var(--white);
}

#canvas-wrapper {
  position: relative;
  background: white;
}

/* --- LABELS --- */
#corner-box, #labels-top, #labels-left {
  background: #f8f9fa;
}

#corner-box {
  grid-area: corner;
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

#labels-top {
  grid-area: top;
  display: flex;
  flex-direction: row;
  height: 25px;
  border-bottom: 1px solid var(--border-color);
}

#labels-left {
  grid-area: left;
  display: flex;
  flex-direction: column;
  width: 25px;
  border-right: 1px solid var(--border-color);
}

#labels-top div, #labels-left div {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  color: var(--medium-gray);
  transition: background-color 0.2s, color 0.2s;
}

#labels-top div:hover, #labels-left div:hover {
  background-color: var(--orange);
  color: var(--white);
}

#labels-top div {
  min-width: 15px;
  height: 100%;
  border-left: 1px solid var(--border-color);
}

#labels-left div {
  width: 100%;
  min-height: 15px;
  border-top: 1px solid var(--border-color);
}

#labels-top div:first-child { border-left: none; }
#labels-left div:first-child { border-top: none; }

/* --- GRID ---*/
#grid, #overlay {
  position: absolute;
  top: 0;
  left: 0;
}

.line {
  position: absolute;
  background: #000;
}
.h-line { height: 2px; width: 100%; }
.v-line { width: 2px; height: 100%; }

.add-btn {
  position: absolute;
  font-size: 32px;
  font-weight: 500;
  color: var(--border-color);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}

.add-btn:hover {
  opacity: 1;
  color: var(--orange);
}

.add-btn.drag-over {
  background-color: rgba(248, 153, 30, 0.1); /* Destaque de drop laranja */
  opacity: 1;
}

.component-placed {
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: auto;
  z-index: 10;
}

.component-placed.hovering {
  background-color: rgba(0, 0, 0, 0.1);
}

.component-placed svg {
  width: 100%;
  height: 100%;
  stroke: #000;
  stroke-width: 2;
  fill: none;
}

.trash-btn {
  display: none;
  position: absolute;
  background: none;
  border: none;
  cursor: pointer;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.component-placed.hovering .trash-btn {
  display: block;
}

.trash-btn svg {
  width: 24px;
  height: 24px;
  stroke: var(--orange);
  stroke-width: 2;
  transition: stroke 0.2s ease-in-out;
}

.trash-btn:hover svg {
  stroke: #e08810;
}

/* --- MENU POPUP --- */
#menu-popup {
  position: absolute;
  background: var(--white);
  border: 1px solid var(--border-color);
  z-index: 10;
  display: flex;
  flex-direction: row;
  padding: 5px;
  gap: 5px;
  box-shadow: var(--shadow);
  border-radius: 6px;
}

#menu-popup .option {
  width: 60px; 
  height: 60px;
  cursor: pointer;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 85%;
  transition: all 0.2s ease;
}

#menu-popup .option:hover {
  border-color: var(--orange);
  background-color: #fff8f0; 
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

/* --- MODAL DE PRÉ-VISUALIZAÇÃO --- */
#modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#modal-content {
  background: var(--white);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
}

#modal-content h3 {
  margin-bottom: 20px;
  color: var(--dark-gray);
  font-weight: 600;
}

#modal-image-container {
  margin-bottom: 25px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

#modal-image-container img {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

#modal-actions {
  display: flex;
  gap: 15px;
}

#modal-actions button {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  font-family: 'Poppins', sans-serif;
  transition: transform 0.1s;
}

#modal-actions button:hover {
  transform: translateY(-1px);
}

#modal-cancel-btn {
  background-color: var(--light-gray);
  color: var(--medium-gray);
}

#modal-download-btn {
  background-color: var(--orange);
  color: var(--white);
}

#custom-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-in-out;
}

#custom-modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

#custom-modal-content {
  background: var(--white);
  padding: 24px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 400px;
  text-align: center;
}

#custom-modal-title {
  font-weight: 600;
  font-size: 20px;
  color: var(--dark-gray);
  margin-bottom: 8px;
}

#custom-modal-text {
  color: var(--medium-gray);
  margin-bottom: 20px;
  line-height: 1.5;
}

#custom-modal-input-wrapper {
  margin-bottom: 20px;
}

#custom-modal-input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
  text-align: center;
}

#custom-modal-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(248, 153, 30, 0.25);
}

.custom-modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.custom-modal-actions button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  font-family: 'Poppins', sans-serif;
  transition: transform 0.1s;
}

.custom-modal-actions button:hover {
  transform: translateY(-1px);
}

#custom-modal-cancel-btn {
  background-color: var(--light-gray);
  color: var(--medium-gray);
  border: 1px solid var(--border-color);
}

#custom-modal-confirm-btn {
  background-color: var(--orange);
  color: var(--white);
}

.modal-filename-wrapper {
  width: 100%;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-filename-wrapper label {
  text-align: left;
  font-weight: 500;
  color: var(--medium-gray);
  font-size: 14px;
}

#filename-input {
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-family: 'Poppins', sans-serif;
  font-size: 16px;
}

#filename-input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(248, 153, 30, 0.25);
}

/* --- ESTILOS DO MODAL DE OPÇÕES DE GIRO --- */
#giro-options-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1002;
}

#giro-options-modal-content {
  background: var(--white);
  padding: 24px 30px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#giro-options-modal-content h3 {
  text-align: center;
  font-weight: 600;
  color: var(--dark-gray);
  margin-bottom: 10px;
}

.giro-option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.giro-option-group > label {
  font-weight: 500;
  color: var(--medium-gray);
  font-size: 14px;
}

.giro-option-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.giro-option-btn {
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--white);
  cursor: pointer;
  font-weight: 500;
  font-size: 15px;
  transition: all 0.2s ease-in-out;
}

.giro-option-btn:hover {
  border-color: #fbd093;
  background-color: #fffaf2;
}

.giro-option-btn.selected {
  background-color: var(--orange);
  color: var(--white);
  border-color: var(--orange);
  font-weight: 600;
}

.giro-option-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--light-gray);
}

.giro-option-btn.disabled:hover {
  border-color: var(--border-color);
  background-color: var(--light-gray);
}

#giro-options-cancel-btn, #giro-options-confirm-btn {
  flex-grow: 1;
}

#giro-options-cancel-btn {
  background-color: var(--light-gray);
  color: var(--medium-gray);
  border: 1px solid var(--border-color);
}

#giro-options-confirm-btn {
  background-color: var(--orange);
  color: var(--white);
}

#version-link {
    color: var(--dark-gray);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

#version-link:hover {
    color: var(--orange); /* Fica laranja ao passar o mouse */
}
