:root {
  --fluent-bg: #f3f3f3;
  --fluent-card-bg: rgba(255, 255, 255, 0.85);
  --fluent-card-solid: #ffffff;
  --fluent-accent: #0067c0;
  --fluent-accent-hover: #1875d1;
  --fluent-accent-active: #00539c;
  --fluent-text-primary: #1a1a1a;
  --fluent-text-secondary: #5d5d5d;
  --fluent-border: rgba(0, 0, 0, 0.08);
  --fluent-border-strong: rgba(0, 0, 0, 0.14);
  --fluent-radius-sm: 6px;
  --fluent-radius-md: 10px;
  --fluent-radius-lg: 14px;
  --fluent-shadow: 0 4px 16px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  --fluent-shadow-modal: 0 16px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI Variable', 'Segoe UI', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--fluent-bg);
  color: var(--fluent-text-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* RIBBON / BARRA DE COMANDOS */
#ribbon {
  background: var(--fluent-card-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--fluent-border);
  padding: 6px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  font-size: 11px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  z-index: 100;
  flex-shrink: 0;
}

#ribbon::-webkit-scrollbar {
  height: 4px;
}
#ribbon::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.ribbon-group {
  display: flex;
  gap: 6px;
  border-right: 1px solid var(--fluent-border);
  padding-right: 10px;
  align-items: center;
  height: 100%;
  flex-shrink: 0;
}

.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--fluent-radius-sm);
  cursor: pointer;
  color: var(--fluent-text-primary);
  font-size: 11px;
  font-weight: 500;
  padding: 4px 6px;
  min-width: 44px;
  transition: all 0.15s ease;
  user-select: none;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--fluent-border);
}

.btn:active {
  background: rgba(0, 0, 0, 0.08);
  transform: scale(0.97);
}

.btn-icon {
  font-size: 16px;
  margin-bottom: 2px;
}

.btn-optimize {
  background: var(--fluent-accent) !important;
  color: white !important;
  font-weight: 700 !important;
  border-radius: var(--fluent-radius-sm) !important;
  padding: 6px 12px !important;
  min-width: 60px !important;
}

.btn-optimize:hover {
  background: var(--fluent-accent-hover) !important;
}

.btn-file-action {
  flex-direction: row !important;
  padding: 4px 8px !important;
  background: var(--fluent-card-solid) !important;
  border: 1px solid var(--fluent-border) !important;
  white-space: nowrap !important;
}

select, input[type="number"], input[type="text"] {
  padding: 5px 8px;
  border: 1px solid var(--fluent-border-strong);
  background: var(--fluent-card-solid);
  color: var(--fluent-text-primary);
  font-size: 11px;
  border-radius: var(--fluent-radius-sm);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select:focus, input[type="number"]:focus, input[type="text"]:focus {
  border-color: var(--fluent-accent);
  box-shadow: 0 0 0 2px rgba(0, 103, 192, 0.2);
}

#branding-area {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding-left: 10px;
  flex-shrink: 0;
}

.app-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--fluent-text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.app-title span {
  color: var(--fluent-accent);
}

.app-version {
  font-weight: 600;
  font-size: 10px;
  color: var(--fluent-text-secondary);
  background: rgba(0, 0, 0, 0.05);
  padding: 1px 6px;
  border-radius: 10px;
  margin-top: 2px;
}

/* ÁREA PRINCIPAL Y CANVAS 3D */
#main-area {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
  width: 100%;
}

#canvas-container {
  flex: 1;
  background: radial-gradient(circle at 50% 50%, #fcfcfc 0%, #e8eef5 100%);
  position: relative;
  outline: none;
  width: 100%;
  height: 100%;
  min-height: 220px;
}

/* WIDGET DE VISTAS RÁPIDAS 3D FLOTANTE */
#view-cube-widget {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--fluent-card-bg);
  backdrop-filter: blur(16px);
  padding: 4px 6px;
  border-radius: var(--fluent-radius-md);
  border: 1px solid var(--fluent-border);
  box-shadow: var(--fluent-shadow);
  z-index: 10;
  display: flex;
  gap: 4px;
}

.view-btn {
  background: var(--fluent-card-solid);
  border: 1px solid var(--fluent-border-strong);
  border-radius: var(--fluent-radius-sm);
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fluent-text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  user-select: none;
}

.view-btn:hover {
  background: rgba(0, 103, 192, 0.08);
  border-color: var(--fluent-accent);
  color: var(--fluent-accent);
}

.view-btn:active {
  transform: scale(0.96);
}

#container-selector-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--fluent-card-bg);
  backdrop-filter: blur(16px);
  padding: 10px;
  border-radius: var(--fluent-radius-md);
  font-weight: 600;
  font-size: 11px;
  border: 1px solid var(--fluent-border);
  box-shadow: var(--fluent-shadow);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 250px;
}

#container-selector-panel button {
  background: var(--fluent-accent);
  color: white;
  border: none;
  border-radius: var(--fluent-radius-sm);
  padding: 6px 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

#container-selector-panel button:hover {
  background: var(--fluent-accent-hover);
}

/* PANELES INFERIORES Y TABLA DE ÍTEMS */
#bottom-panels {
  display: flex;
  height: 200px;
  background: var(--fluent-bg);
  border-top: 1px solid var(--fluent-border);
  gap: 8px;
  padding: 8px;
  flex-shrink: 0;
}

#packing-list-panel {
  flex: 3;
  display: flex;
  background: var(--fluent-card-solid);
  border-radius: var(--fluent-radius-md);
  border: 1px solid var(--fluent-border);
  box-shadow: var(--fluent-shadow);
  overflow: hidden;
}

#packing-list-table-container {
  flex: 1;
  overflow-y: auto;
  min-height: 100px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--fluent-border);
  background: rgba(0, 0, 0, 0.02);
  color: var(--fluent-text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--fluent-border);
  cursor: pointer;
}

tr:hover {
  background-color: rgba(0, 103, 192, 0.04);
}

tr.selected {
  background-color: rgba(0, 103, 192, 0.12) !important;
  outline: 1px solid var(--fluent-accent);
}

.color-box {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
  display: inline-block;
  vertical-align: middle;
}

#action-buttons {
  width: 100px;
  background: rgba(0, 0, 0, 0.015);
  border-left: 1px solid var(--fluent-border);
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 5px;
  flex-shrink: 0;
}

.side-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border: 1px solid var(--fluent-border);
  background: var(--fluent-card-solid);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--fluent-radius-sm);
  transition: all 0.15s;
  white-space: nowrap;
}

.side-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--fluent-border-strong);
}

#container-info {
  flex: 1.2;
  padding: 10px;
  background: var(--fluent-card-solid);
  border-radius: var(--fluent-radius-md);
  border: 1px solid var(--fluent-border);
  box-shadow: var(--fluent-shadow);
  font-size: 11px;
  overflow-y: auto;
}

.info-title {
  color: var(--fluent-accent);
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 12px;
}

.progress-row {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.progress-label {
  width: 90px;
  text-align: right;
  margin-right: 8px;
  color: var(--fluent-text-secondary);
  font-weight: 500;
  line-height: 1.2;
}

.progress-bar-bg {
  flex: 1;
  height: 14px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--fluent-accent), #0080ff);
  border-radius: 6px;
  width: 0%;
  transition: width 0.4s ease-out;
}

.progress-text {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 0;
  left: 0;
  line-height: 14px;
  color: var(--fluent-text-primary);
  font-size: 10px;
  font-weight: 700;
}

/* MODALES */
.draggable-modal {
  display: none;
  background: var(--fluent-card-solid);
  border: 1px solid var(--fluent-border-strong);
  box-shadow: var(--fluent-shadow-modal);
  font-size: 12px;
  position: absolute;
  z-index: 1001;
  border-radius: var(--fluent-radius-lg);
  overflow: hidden;
}

.modal-header-drag {
  background: var(--fluent-bg);
  border-bottom: 1px solid var(--fluent-border);
  padding: 8px 12px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
  user-select: none;
  color: var(--fluent-text-primary);
}

.modal-body {
  padding: 14px 18px;
  background: var(--fluent-card-solid);
}

.title-gradient {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--fluent-text-primary);
  position: relative;
  padding-bottom: 4px;
}

.title-gradient::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 70px;
  background: var(--fluent-accent);
  border-radius: 2px;
}

.form-group {
  display: flex;
  margin-bottom: 8px;
  align-items: center;
}

.form-group label {
  width: 85px;
  text-align: left;
  color: var(--fluent-text-primary);
  font-weight: 500;
}

.form-group input[type="number"], .form-group input[type="text"], .form-group select {
  border: 1px solid var(--fluent-border-strong);
  padding: 4px 6px;
  width: 120px;
}

.fit-calc-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 150px;
}

.link-select {
  border: 1px solid var(--fluent-border-strong);
  color: var(--fluent-accent);
  background: var(--fluent-card-solid);
  cursor: pointer;
  font-size: 11px;
  outline: none;
  padding: 2px 6px;
  font-weight: 600;
  border-radius: var(--fluent-radius-sm);
  width: 100%;
  max-width: 180px;
  margin-top: 2px;
}

.modal-footer {
  padding: 10px 14px;
  background: var(--fluent-bg);
  border-top: 1px solid var(--fluent-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-footer button {
  padding: 5px 16px;
  cursor: pointer;
  font-size: 11px;
  border-radius: var(--fluent-radius-sm);
  font-family: inherit;
  font-weight: 600;
}

.btn-cancel {
  background: var(--fluent-card-solid);
  border: 1px solid var(--fluent-border-strong);
  color: var(--fluent-text-primary);
}

.btn-ok {
  background: var(--fluent-accent);
  border: 1px solid var(--fluent-accent);
  color: white;
}

.safe-link {
  cursor: pointer;
  color: var(--fluent-accent);
  font-size: 11px;
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.color-select-wrapper {
  position: relative;
  width: 120px;
  user-select: none;
}

.color-select-btn {
  border: 1px solid var(--fluent-border-strong);
  background: var(--fluent-card-solid);
  padding: 2px 5px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 11px;
  height: 24px;
  border-radius: var(--fluent-radius-sm);
}

.color-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  margin-right: 5px;
  display: inline-block;
  flex-shrink: 0;
}

.color-select-menu {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: var(--fluent-card-solid);
  border: 1px solid var(--fluent-border-strong);
  box-shadow: var(--fluent-shadow);
  z-index: 1002;
  display: none;
  max-height: 150px;
  overflow-y: auto;
  border-radius: var(--fluent-radius-sm);
}

.color-select-menu.show { display: block; }
.color-option { padding: 5px 7px; display: flex; align-items: center; cursor: pointer; font-size: 11px; }
.color-option:hover { background: rgba(0, 103, 192, 0.08); }

#custom-cont-dims { display: none; margin-left: 6px; align-items: center; gap: 4px; }
#custom-cont-dims input { width: 45px; }

#toast-msg {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #107c41;
  color: white;
  padding: 10px 18px;
  border-radius: var(--fluent-radius-md);
  box-shadow: var(--fluent-shadow-modal);
  font-weight: 600;
  z-index: 10000;
  font-size: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ADAPTATIVIDAD TABLET Y MÓVIL */
@media (max-width: 820px) {
  body {
    height: 100vh;
    overflow-y: auto;
  }

  .ribbon-group-optimize {
    order: -1;
    border-right: 1px solid var(--fluent-border);
    padding-right: 8px;
  }

  #view-cube-widget {
    top: auto;
    bottom: 12px;
    right: 12px;
  }

  #main-area {
    flex-direction: column;
    height: 380px;
    flex: none;
  }

  #canvas-container {
    height: 100%;
    width: 100%;
  }

  #bottom-panels {
    flex-direction: column;
    height: auto;
  }

  #packing-list-panel {
    flex-direction: column;
    height: 260px;
  }

  #packing-list-table-container {
    flex: 1;
    min-height: 180px;
    overflow-y: auto;
  }

  #action-buttons {
    width: 100%;
    height: 40px;
    min-height: 40px;
    flex-direction: row;
    justify-content: space-between;
    border-left: none;
    border-top: none;
    border-bottom: 1px solid var(--fluent-border);
    padding: 4px;
    order: -1; /* Esto mueve la botonera arriba visualmente */
  }

  .side-btn {
    flex: 1;
    height: 30px;
    padding: 2px 4px;
    font-size: 10px;
    justify-content: center;
  }

  #container-info {
    height: auto;
  }

  .draggable-modal {
    width: 90% !important;
    max-width: 460px;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    position: fixed !important;
  }
}
